0% found this document useful (0 votes)
9 views26 pages

DS Mod-1

Uploaded by

Akshay S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views26 pages

DS Mod-1

Uploaded by

Akshay S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

Data Structures

Manju K

Department of Computer Engineering

Module 1-Basic Concepts

Manju K (CSE) CST201 October 5, 2022 1 / 26


Outline

1 Introduction

2 How to create programs

3 Algorithm

Manju K (CSE) CST201 October 5, 2022 2 / 26


Introduction

Introduction

Manju K (CSE) CST201 October 5, 2022 3 / 26


Introduction

System Life Cycle

System life cycle is a series of stages that are worked through during the
development of a new information system.
A lot of money and time is wasted if a system is developed that doesn’t work
properly or perform exactly how it is required.
System cycle- 5 phases
Requirements
Analysis
Design
Refinement and Coding
Verification

Manju K (CSE) CST201 October 5, 2022 4 / 26


Introduction

Requirements

A set of specifications that define the purpose of the project.


Understanding the given information (the input) and what results are
produced (the output)
A rigorous description of input and output that cover all cases.

Manju K (CSE) CST201 October 5, 2022 5 / 26


Introduction

Analysis

Break the problem down into manageable pieces.


Two approaches to analysis
Top-down
Bottom-up

Manju K (CSE) CST201 October 5, 2022 6 / 26


Introduction

Design

The designer approaches the system from the perspective of both the data
objects that the program needs and the operations performed on them.
Program need leads to creation of abstract data type(ADT)
Operations lead to the specification of algorithms and a consideration of
algorithm design strategies.
Both are language independent

Manju K (CSE) CST201 October 5, 2022 7 / 26


Introduction

Refinement and Coding

Choose representations for data-objects.


Write algorithms for each operation on these objects.
Refine the algorithm
The order in which we do this is important.We first write algorithms that are
typically independent of the data objects first.

Manju K (CSE) CST201 October 5, 2022 8 / 26


Introduction

Verification

Develop correctness proofs for the program.


Testing the program with all types of inputs
Remove errors if any

Manju K (CSE) CST201 October 5, 2022 9 / 26


How to create programs

How to create programs

Manju K (CSE) CST201 October 5, 2022 10 / 26


How to create programs

How to create programs

Requirements
Analysis: Bottom-up vs top-down
Design: data objects and operations
Refinement and coding
Verification
Proving program correctness
Testing
Debugging

Manju K (CSE) CST201 October 5, 2022 11 / 26


Algorithm

Algorithm

Manju K (CSE) CST201 October 5, 2022 12 / 26


Algorithm

Algorithm

Definition: An algorithm is a finite set of instructions that accomplishes a


particular task.
Criteria:
input
output
definiteness: clear and unambiguous
finite:terminate after a finite number of steps
effectiveness: Every instruction should be basic enough to be carried out

Manju K (CSE) CST201 October 5, 2022 13 / 26


Algorithm

Example

Write an algorithm to find the largest from a given list of numbers:

Algorithm 1 Largest in a given List


Require: List of numbers, L
Ensure: Largest number,max
0: Define a variable ’max’.
0: Initialize max with the first element in the list
0: Compare the first number(say ’x’) in the list ’L’ with ’max’, if ’x’ is larger than
max, then set ’max’ to ’x’
0: Repeat step3 for all numbers in the list ’L’
0: Display the value of ’max’. =0

Manju K (CSE) CST201 October 5, 2022 14 / 26


Algorithm

Performance analysis

Space Complexity -storage requirement


Time Complexity -computing time

Manju K (CSE) CST201 October 5, 2022 15 / 26


Algorithm

Space Complexity

Space needed by the program


S(P ) = c + Sp (I)
c is a constant referring the fixed space requirements
Sp (I) is the variable space requirements
Fixed Space requirements
Space requirement are fixed. Do not depend on the number and size of the
program’s input and output.
Variable space requirements
Depends on the input at that particular instance.
For eg:if our input is an array containing n numbers, then n is an instance
characteristic.

Manju K (CSE) CST201 October 5, 2022 16 / 26


Algorithm

Time Complexity

Time taken by a program P is the sum of compile time and run time.
T (P ) = c + Tp (I)
The time Tp taken by a program P is the sum of its compile time and run time.
Compile time is similar to the fixed space component, since it does not depend on
instance characteristics.
Alternatively execution time is the number of operations the program performs.

A program step is a syntactically or semantically meaningful program segment


whose execution time is independent of the instance characteristics.

Manju K (CSE) CST201 October 5, 2022 17 / 26


Algorithm

Figure: Iterative function to sum a list of numbers

Manju K (CSE) CST201 October 5, 2022 18 / 26


Algorithm

Figure: Recursive function to sum a list of numbers

Manju K (CSE) CST201 October 5, 2022 19 / 26


Algorithm

The best case step count is the minimum number of steps that can be
executed for the given parameters.
The worst-case step count is the maximum number of steps that can be
executed for the given parameters.
The average step count is the average number of steps executed on instances
with the given parameters.

Manju K (CSE) CST201 October 5, 2022 20 / 26


Algorithm

Asymptotic notations

Asymptotic notations give us an idea about how good a given algorithm is


compared to some other algorithm that performs the same function.
Let us see the mathematical definition: Primarily there are three types of
asymptotic notations.
Big Oh notation(O)
Big Omega notation(Ω)
Big Theta(Θ)

Manju K (CSE) CST201 October 5, 2022 21 / 26


Algorithm

Big-Oh

Big Oh notation is used to describe asymptotic upper bound


Mathematically if f(n) describes the running time of an algorithm. f(n) is O(g(n))
iff there exists positive constants c and n0 such that
0 ≤ f (n) ≤ c ∗ g(n) ∀ n, n ≥ n0

Manju K (CSE) CST201 October 5, 2022 22 / 26


Algorithm

Big-Omega

Big Omega notation is used to describe asymptotic lower bound


Mathematically if f(n) describes the running time of an algorithm. f(n) is Ω(g(n))
iff there exists positive constants c and n0 such that
f(n) ≥ c ∗ g(n) ∀ n, n ≥ n0

Manju K (CSE) CST201 October 5, 2022 23 / 26


Algorithm

Big-Theta

Big Theta notation is used to describe asymptotic behaviour within a bound.


Mathematically if f(n) describes the running time of an algorithm. f(n) is Θ(g(n))
iff there exists positive constants c1 , c2 and n0 such that
c1 ∗ g(n) ≤ f (n) ≥ c2 ∗ g(n) ∀ n, n ≥ n0

Manju K (CSE) CST201 October 5, 2022 24 / 26


Algorithm

Figure: Graphical representation for Θ,O,Ω

Manju K (CSE) CST201 October 5, 2022 25 / 26


Acknowledgement

Thank you!
E-mail: [email protected]

Manju K (CSE) CST201 October 5, 2022 26 / 26

You might also like