it is presentation on linear and insertion sort and search
Size: 139.88 KB
Language: en
Added: Aug 01, 2024
Slides: 6 pages
Slide Content
Insertion sort Insertion sort is a simple sorting algorithm that works the way we sort playing cards in our hands.
Insertion sort Algorithm The simple steps of achieving the insertion sort are listed as follows - Step 1 - If the element is the first element, assume that it is already sorted. Step2 - Pick the next element, and store it separately in a key. Step3 - Now, compare the key with all elements in the sorted array. Step 4 - If the element in the sorted array is smaller than the current element, then move to the next element. Else, shift greater elements in the array towards the right. Step 5 - Insert the value. Step 6 - Repeat until the array is sorted.
Example 5,2,1,4,3 SORT BY INSERTION SORT
Searching in Arrays Searching: It is used to find out the location of the data item if it exists in the given collection of data items . E.g . We have linear array A as below: 1 2 3 4 5 15 50 35 20 25 Suppose item to be searched is 20. We will start from beginning and will compare 20 with each element. This process will continue until element is found or array is finished. Here : 1 ) Compare 20 with 15 20 # 15, go to next element . 2 ) Compare 20 with 50 20 # 50, go to next element . 3 ) Compare 20 with 35 20 #35, go to next element . 4 ) Compare 20 with 20 20 = 20, so 20 is found and its location is 4.