0% found this document useful (0 votes)
3 views7 pages

Sorting Algorithms: Insertion, Selection, Bubble

The document outlines three sorting algorithms: Insertion Sort, Selection Sort, and Bubble Sort, providing step-by-step procedures for each. Insertion Sort involves placing elements in their proper position by comparing and shifting, Selection Sort finds the minimum element and swaps it with the current position, and Bubble Sort repeatedly compares adjacent elements to sort the data. An example array is provided to illustrate the sorting processes.

Uploaded by

Ishita Kaur
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views7 pages

Sorting Algorithms: Insertion, Selection, Bubble

The document outlines three sorting algorithms: Insertion Sort, Selection Sort, and Bubble Sort, providing step-by-step procedures for each. Insertion Sort involves placing elements in their proper position by comparing and shifting, Selection Sort finds the minimum element and swaps it with the current position, and Bubble Sort repeatedly compares adjacent elements to sort the data. An example array is provided to illustrate the sorting processes.

Uploaded by

Ishita Kaur
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

DATA

STRUCTURE
SORTING
INSERTION SORT
• INSERTION( A,N)
1. SET A[0]=-∞
2. REPEAT STEPS 3 to 5 for K=2,3….N
3. SET TEMP:= A[K] and PTR:=K-1
4. REPEAT while TEMP<A[PTR]:
a) SET A[PTR+1]:= A[PTR]
b) SET PTR:= PTR-1
5. SET A[PTR+1]:=TEMP [Insert element in proper place].
6. Return.
SELECTION SORT
• MIN (A,K,N,LOC)
1. SET MIN:=A[K] AND LOC:=K [Initializes Pointers]
2. Repeat for J=K+1, K+2……N
IF MIN>A[J], then Set MIN:=A[J] AND LOC:=J
3. RETURN.
• SELECTION (A,N)
1. REPEAT STEPS 2 and 3 for K=1,2,3….n-1
2. CALL MIN(A,K,N,LOC)
3. [INTERCHANGE A[K] and A[LOC]
1. SET TEMP:=A[K]
2. A[K]:=A[LOC]
3. A[LOC]:=TEMP
4. EXIT.
EXAMPLE:
• 77 33 44 11 88 22 66 55
BUBBLE SORT
BUBBLE(DATA,N)
1. REPEAT STEPS 2 and 3 for K=1 to N-1.
2. SET PTR:=1
3. REPEAT WHILE PTR<=N-K:
a) IF DATA[PTR]>DATA[PTR+1] then:
INTERCHANGE DATA[PTR] and DATA[PTR+1]
[END OF IF STRUCTURE].
b) SET PTR:=PTR+1
4. EXIT.

You might also like