Professional Documents
Culture Documents
Adobe Scan 14-Nov-2021
Adobe Scan 14-Nov-2021
SHIFFAN f A THIMA S
19UW30243 ; 19urr108
lli - B.SC (IT)
Contents:-
.~ -__ - -
·-- - ~
I II
~·2· /"·9
11 i :
I' • .· .'
Insertion sort :-
• Insertion sort is a simple sorting algorithm that worbs similar to the way
you sort playing cards in your hands.
• Insertion sort is the sorting mechanism where the
sorted array is built having one item at a time.
~s'.- / ,9
11:
11
Example of Insertion sort
I I I I I I I
5 1 6 2 4 3 Lets t.a.ke th.is Array.
Aa we can • • • here. i n
in.eertion eort . we pick u p •
'"'s© 6 2 4 3
key. and compar·• • ii with
elemnt• ■ head of ,t.
and
puts the key In th• n ghl
1 5 @ 2 4 3 place
1
~ 4 3
S has nothing before iL
1 3
2 ~ 1 is compared to 5 and ia
@ ineerted b•fore 5 .
~
1 2 5 6
6 '• gr♦.-ter than 5 and 1
{
temp=a(i);
j=l-1;
•IJ+tJ,...UI
J- ;
}
■U+ll-ttmp
l
Ask questions
VVlJen
in doubt
ask
questions•
t/,~ a.ttelftlolf
9 / 9·