Insertion sort & Linear Search presentation

SaranshGupta923104 27 views 6 slides Aug 01, 2024
Slide 1
Slide 1 of 6
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6

About This Presentation

it is presentation on linear and insertion sort and search


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.

Linear Search
Tags