Linear Lists (Python) Part-1
Linear Lists (Python) Part-1
(Arrays)
Part-1
Prepared By-
Naveen Kumar Varshney
PGT (Comp. Sc.)
JNV Devrala, Bhiwani
0 1 2 3 4 5 6 7 8 9
LB UB
• Length(Size) of Linear List(Array)= UB-LB+1
=9-0+1=10
Subscribe my Youtube Channel – Naveen Varshney Official
OPERATIONS ON LINEAR LISTS
1) Linear Search
2) Binary Search
23 23≠39 39 27 44 23 12 5 67
23 39 27 44 23 12 5 67
23 39 27 44 23 12 5 67
23 39 27 44 23 12 5 67
23 23≠39 39 27 44 23 12 5 67
23 23≠27 39 27 44 23 12 5 67
23 39 27 44 23 12 5 67
23 39 27 44 23 12 5 67
23 23≠39 39 27 44 23 12 5 67
23 23≠27 39 27 44 23 12 5 67
23 23≠44 39 27 44 23 12 5 67
23 39 27 44 23 12 5 67
23 23≠39 39 27 44 23 12 5 67
23 23≠27 39 27 44 23 12 5 67
23 23=44 39 27 44 23 12 5 67
23 23=23 39 27 44 23 12 5 67
19 3 7 11 14 19 22 43 67
item
• Item to be searched : 19
19 3 7 11 14 19 22 43 67
item 0 1 2 3 4 5 6 7
19 3 7 11 14 19 22 43 67
item 0 1 2 3 4 5 6 7
19 3 7 11 14 19 22 43 67
item 0 1 2 3 4 5 6 7
• Now, AR[mid] is less than 19 then set the beg at (mid+1) position
i.e. 4
19 3 7 11 14 19 22 43 67
item 0 1 2 3 4 5 6 7
19 3 7 11 14 19 22 43 67
item 0 1 2 3 4 5 6 7
19 3 7 11 14 19 22 43 67
item 0 1 2 3 4 5 6 7
• AR[mid] is greater than 19 then set the last at (mid-1) position i.e. 4
19 3 7 11 14 19 22 43 67
item 0 1 2 3 4 5 6 7
beg mid
last
• Again mid is calculated
mid = int(beg+last)/2 = 4
19 3 7 11 14 19 22 43 67
item 0 1 2 3 4 5 6 7
beg
last
• Again AR[mid] is compared with 19
mid
19 3 7 11 14 19 22 43 67
item 0 1 2 3 4 5 6 7
beg
last
• Now, AR[mid] is equal to 19.
mid
19 3 7 11 14 19 22 43 67
item 0 1 2 3 4 5 6 7
beg
last
• Search is successful. Item is found
mid
at index 4 and position 5.
BINARY
SEARCH
PROGRAM
Subscribe my Youtube Channel – Naveen Varshney Official