UNIT 1- Data structure
UNIT 1- Data structure
UNIT 1- Data structure
Array Linked
List
a[1] a[2] a[3] a[4] a[5] a[6] a[7] a[8] a[9] a[10]
• 57 • 47 • 28 • 12 • 17 •8 • 99 • 67 • 55 •6
b[1] b[2] b[3] b[4] b[5] b[6] b[7] b[8] b[9] b[10]
• S •T •R •U •C •T •U •R •E •S
Algorithm
Types of Complexity
Compiled by Ms. Archana Patil, Asst. Professor, ALSJ
1 45
Enter Element to be searched
Worst
case 67
2 34
Time required for search – 8 m sec
3 76
Enter Element to be searched
4 85 Best case 45
Time required for search – 1m sec
5 23
6 49
Enter Element to be searched
Average
case 85
7 12
Time required for search – 4 m sec
8 67
Considering that time required to traverse one single index of array is 1 millisecond
11 43 43 47 Algorithm : (loop)
i=1
S[0] S[1] S[2] S[3] S[4] S[5] set S[1+1]=S [1]
set i = 1-1
New
Set S[k] =new
11 53 43 47
S[1] = 53
S[0] S[1] S[2] S[3] S[4] S[5] Set n = n+1
n=2+1
Compiled by Ms. Archana Patil, Asst. Professor, ALSJ
Deletion from Array
Deletion operation refers to removing an existing element from
an array.
The element from any position can be removed from an array.
Removal of element from the end of the array is very simple
operation as no data element is involved.
But removing an element at any position from an array, all
element which is next to the element to be deleted has to be
shifted one position to its left.
11 47 53
47 53 Algorithm : (loop)
i=2
S[0] S[1] S[2] S[3] S[4] S[5] set S[2]=S [2+1]
set i = [2+1]
11 47 53 Set n = n-1
n=3-1
S[0] S[1] S[2] S[3] S[4] S[5]
Here n = 6
Suppose we want to find 23
so Data =23
S[1] 34
S[2] 45
S[3] 23
S[4] 56
S[5] 12
S[6] 7
Now considering the first part of list again start the algorithm
4 10 13
1 2 3
Array 1 Array 2
4 20 13 23 7 30 14
1 2 3 4 5 6 7
4 7 30 52 10 35 50
1 2 3 4 1 2 3
4 7 10 30 35 50 52
1 2 3 4 5 6 7