0% found this document useful (0 votes)
2 views31 pages

Week 1

This is DSA slides

Uploaded by

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

Week 1

This is DSA slides

Uploaded by

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

W EEK

D ATA S T R U C T U R E S & A L G O R I T H M S
BSIT, BSAI, ADPIT

• Instructor Name: Fraz Sarwar


• E-mail :
[email protected]
DATA STRUCTURE &
ALGORITHM?
• Data Structure : A data structure is a way of storing data on your
computer efficiently.

• Algorithm : Algorithm is a step-by-step procedure for performing some


task in a finite amount of time.

The choice of data structure and algorithm can make the difference between
a program running in a few seconds or many hours.
EXAMPLE
4 3 2
1

Queue
NAME OF DATA
data
STRUCTURE?

structure
1 2 3
4
EXAMPLE

GRAPHS
NAME OF DATA
DATA STRUCTURE
STRUCTURE?
DIFFERENT DATA
STRUCTURES
LIST DATA STRUCTURE
LINKED LIST
STACK
QUEUE
TREES
GRAPHS
HASHES
APPLICATIONS OF DATA
STRUCTURE
• Search − Algorithm to search an item in a data
structure.
• Sort − Algorithm to sort items in a certain order.
• Insert − Algorithm to insert item in a data
structure.
• Update − Algorithm to update an existing item in
a data structure.
• Delete − Algorithm to delete an existing item from
a data structure.
APPLICATIONS OF DATA
STRUCTURE

36 10 20 25 30
DATA STRUCTURE
PROPERTIES
• Each data structure has costs and benefits
• Rarely is one data structure better than another in all situations.
• A data structure requires:
– space for each data item it stores,
– time to perform each basic operation,
– programming effort.
EFFICIENCY

• A solution is said to be efficient if it solves the problem within its resource


constraints.
– Space
– Time
SELECTING A DATA
STRUCTURE
• Designing and using data structures is an important programming skill
• Select a data structure as follows:
– Analyze the problem to determine the resource constraints a solution must
meet.
– Determine the basic operations that must be supported.

Select the data structure that best meets these requirements.


DATA STRUCTURE TYPES
• Predefined Data types or Primitive data types
Int
Char
String
Float
Boolean
pointer
ABSTRACT DATA TYPE
( ADT )
• An abstract data type (or ADT) is a class that has a defined set of operations
and values.
• User can create this data type according to his needs.
• For example. Stack, linked list, trees, graphs, hashes, queues.

• The definition of ADT only mentions what operations are to be performed but
not how these operations will be implemented.
• It does not specify how data will be organized in memory and what algorithms
will be used for implementing the operations.

Example: Think about a car. You just have to execute the start function. You
don’t have to worry about the inner working of the car.

Write some functions of cars?


DATA STRUCTURE TYPES

• We may classify as linear and non-linear data structures

• In linear data structure the data items are arranged in a linear sequence
– like in an array, linked list.

• In a non-linear, the data items are not in sequence. One node is attached
with several others.
– Example of non-linear DS are tree, graphs.
DATA STRUCTURE
CLASSIFICATION
ALGORITHM
• Algorithm is a step-by-step procedure, which defines a set of instructions to
be executed in a certain order to get the desired output.
• Algorithms are generally created independent of underlying languages, i.e.
an algorithm can be implemented in more than one programming language.
PSEUDO CODE
• Programmers are often asked to describe algorithms in a way that is intended
for human eyes only, prior to writing actual code. Such descriptions are called
pseudocode.
• Pseudo-code is not a computer program.
• Pseudo-code is a mixture of natural language and high-level programming
• There really is no precise definition of the pseudo-code language, however,
because of its reliance on natural language.
RULES TO WRITE PSEUDO
CODE
• Expressions: We use the left arrow sign (←) as the assignment
• we use the equal sign (=) as the equality relation in Boolean expressions
• (equivalent to the “==” relation in C++).

• Function declarations: Algorithm name(arg1,arg2, . . . ) declares a new


function “name” and its arguments.

• Decision structures: if condition then true-actions [else false-actions]. We


use indentation to indicate what actions should be included in the true-
actions and false-actions.
RULES TO WRITE PSEUDO
CODE
• While-loops: while condition do actions. We use indentation to indicate
what actions should be included in the loop actions.

• For-loops: for variable-increment-definition do actions. We use indentation


to indicate what actions should be included among the loop actions.
RULES TO WRITE PSEUDO CODE

• Array indexing: A[i] represents the ith cell in the array A. The cells of an n-
celled array A are indexed from A[0] to A[n − 1]

• Member function calls: object.method(args) (object is optional if it is


understood).

• Function returns: return value. This operation returns the value specified
to the method that called this one.
• Comments: { Comment goes here. }. We enclose comments in braces.
SOLUTION OF QUADRATIC
EQUATION
EXAMPLE 1
SUM ELEMENTS OF ARRAY
EXAMPLE 2
FIND MAXIMUM IN AN ARRAY

You might also like