Data 02
Data 02
4
Classification of Data Structures
5
Classification of Data Structures Cont…
6
Classification of Data Structures Cont…
7
Classification of Data Structures Cont…
Linear Data Structures:
A data structure that preserves a linear connection among its data elements is known
as a Linear Data Structure.
The arrangement of the data is done linearly, where each element consists of the
. successors and predecessors except the first and the last data element.
Based on memory allocation, the Linear Data Structures are further classified into two
types:
Static Data Structures: The data structures having a fixed size are known as Static
Data Structures. The memory for these data structures is allocated at the compiler time,
and their size cannot be changed by the user after being compiled
Example: Array
Dynamic Data Structures: The data structures having a dynamic size are known as
Dynamic Data Structures. The memory of these data structures is allocated at the run
time, and their size varies during the run time of the code.
Example: Linked Lists, Stacks, and Queues.
8
Classification of Data Structures Cont…
9
10
Algorithms
An algorithm is a well-defined list of step for solving problem.
An Algorithm is a finite step – by – step list of well defined
instructions for solving a particular problem.
It is used to manipulate the data contained in the data structures as
in searching and sorting.
11
Algorithms Cont…
Characteristics of an algorithm:
Unambiguous: Algorithm should be clear and Unambiguous.
Input: 0 or more well defined input.
Output: 1 or more well defined output.
Finiteness: Algorithm must be terminated after a finite number of
steps.
Feasibility: Feasible with the available resource.
Independent: Independent of any programming language.
12
Algorithms Cont…
The following are the steps required to add two numbers
entered by the user:
Step 1: Start
Step 2: Declare three variables a, b, and sum.
Step 3: Enter the values of a and b.
Step 4: Add the values of a and b and store the result in the sum
variable, i.e., sum=a+b.
Step 5: Print sum
Step 6: Stop
13
Complexity
The complexity of an algorithm is the function which gives the running
time and/or space in terms of the input size.
The complexity of an algorithm is the function f(n) which measures the
running time and/or space in terms of the input size n
15
Asymptotic Notation
The commonly used asymptotic notations used for calculating
the running time complexity of an algorithm is given below:
Big oh Notation (?)
Omega Notation (Ω)
Theta Notation (θ)
16
Asymptotic Notation Cont…
Big oh Notation (?)
Big-O notation represents the upper bound of the running time of an
algorithm.
It returns the highest possible output value (big-O)for a given input.
Therefore, it gives the worst-case complexity of an algorithm.
17
Asymptotic Notation Cont…
Omega Notation (Ω)
Omega notation represents the lower bound of the running
time of an algorithm.
Thus, it provides the best case complexity of an algorithm.
18
Asymptotic Notation Cont…
Theta Notation (θ)
Theta notation encloses the function from above and below.
Since it represents the upper and the lower bound of the running time of
an algorithm.
it is used for analyzing the average-case complexity of an algorithm.
19
Array
Linear array (One dimensional array) : A list of finite number n of
similar data elements referenced respectively by a set of n consecutive
numbers, usually 1, 2, 3,…..n. That is a specific element is accessed by an
index.
• Let, Array name is A then the elements of A is : a1,a2….. an
• Or by the bracket notation A[1], A[2], A[3],…………., A[n]
20
Example
A linear array STUDENT consisting of the name of six students
STUDENT
1 Dalia Rahaman
2 Sumona
3 Mubtasim Fuad
4 Anamul Haque
5 Ibtisam Rahaman
6
Jarin
21
Array (con…)
Linear arrays are called one dimensional arrays because each element in such
an array is referenced by one subscript.
(Two dimensional array) : Two dimensional array is a collection of similar
data elements where each element is referenced by two subscripts.
Such arrays are called matrices in mathematics and tables in business
applications.
Multidimensional arrays are defined analogously
MATRICES
1 2 3 4
1 1 2 3 4
Here, MATRICES[3,3]=11
2 5 6 7 8
3 9 10 11 12
4 13 14 15 16
22
Array Data Structure
It can hold multiple values of a single type.
Elements are referenced by the array name and an ordinal index.
Each element is a value
Indexing begins at zero.
The array forms a contiguous list in memory.
The name of the array holds the address of the first array element.
We specify the array size at compile time, often with a named
constant.
23
Linked lists
•A linked list, or one way list, is a linear collection of data elements,
called nodes, where the linear order is given by means of pointers.
Node
Data Next
In linked list
Each node of the list contains the data item
a pointer to the next node
24
Linked lists Cont...
Start
node
node
Data Next Data
Linked list with 2 nodes
25
Linked lists
INFO LINK
3 2 A 5 LINK[3]=2, INFO[2]=A
M 2 LINK[2]=5, INFO[5]=N
3
LINK[5]=4, INFO[4]=G
4 G 7
LINK[4]=7, INFO[7]=O
5 N 4
LINK[7]=0, NULL value, So the list has ended
6
7 O 0
26
Data structure operations
The following four operations play a major role:
Traversing
Accessing each record exactly once so that certain items in the record may
be processed. (This accessing or processing is sometimes called 'visiting"
the records.)
Searching
Finding the location of the record with a given key value, or finding the
locations of all records, which satisfy one or more conditions.
Inserting
Adding new records to the structure.
Deleting
Removing a record from the structure.
27
Data structure operations Cont…
The following two operations, which are used in special situations, will also be
considered:
Sorting: Arranging the records in some logical order
Merging: Combining the records in two different sorted files into a single
sorted files
28
Stacks
• Stacks are a special form of collection with LIFO semantics
• Two methods
- add item to the top of the stack
- remove an item from the top of the stack
• Like a plate stacker
29
Queues
• Like a stack, a queue is also a list. However, with a queue, insertion
is done at one end, while deletion is performed at the other end
• The insertion end is called rear
– The deletion end is called front
Remove Insert
front rear
30
edges
31
32
33
Your Task