Ch2-3 Simple Sorting and Searching Algs
Ch2-3 Simple Sorting and Searching Algs
By:
Umar H. (Bsc. Software Enginnering)
CHAPTER OVERVIEW
Simple Sorting algorithms
o Selection sort
o Bubble sort
o Insertion sort
2 4 5 8 7
2 4 5 7 8
7 2 8 5 4 2 7 5 4 8 2 5 4 7 8 2 4 5 7 8
2 7 8 5 4 2 7 5 4 8 2 5 4 7 8 2 4 5 7 8
2 7 8 5 4 2 5 7 4 8 2 4 5 7 8
2 7 5 8 4 2 5 4 7 8
2 7 5 4 8
11
13
Sort: 34 8 64 51 32 21
34 8 64 51 32 21
The algorithm sees that 8 is smaller than 34 so it swaps.
8 34 64 51 32 21
51 is smaller than 64, so they swap.
8 34 51 64 32 21
The algorithm sees 32 as another smaller number and moves it to its
appropriate location between 8 and 34.
8 32 34 51 64 21
The algorithm sees 21 as another smaller number and moves into
between 8 and 32.
Final sorted numbers:
8 21 32 34 51 64 14
16
17
18
Analysis:
Time is proportional to the size of input n
time complexity O(n)
19
20
if(found==0)
index=-1;
return index;
}
21
22
return index;
24
}
IS(2008) ROYAL U.COLLEGE Saturday, July 31, 2021
ANALYSIS OF GROWTH FUNCTIONS
25
ANY Q?
26
27