0% found this document useful (0 votes)
4 views1 page

Sorting Algorithms: Insertion, Bubble, Selection

The document outlines three sorting algorithms: Insertion Sort, Bubble Sort, and Selection Sort. Each algorithm is described with a step-by-step procedure for sorting a list of numbers. The steps include initializing variables, iterating through the list, and performing comparisons and swaps as needed.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

Sorting Algorithms: Insertion, Bubble, Selection

The document outlines three sorting algorithms: Insertion Sort, Bubble Sort, and Selection Sort. Each algorithm is described with a step-by-step procedure for sorting a list of numbers. The steps include initializing variables, iterating through the list, and performing comparisons and swaps as needed.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Insertion sort

Insertion Sort INSERTIONSORT(numList, n)


Step 1: SET i=1
Step 2: WHILE i< n REPEAT STEPS 3 to 9
Step 3: temp = numList[i]
Step 4: SET j = i-1
Step 5: WHILE j> = 0 and numList[j]>temp,REPEAT STEPS 6 to 7
Step 6: numList[j+1] = numList[j]
Step 7: SET j=j-1
Step 8: numList[j+1] = temp #insert temp at position j
Step 9: set i=i+1

Bubble sort
BUBBLESORT( numList, n)
Step 1: SET i = 0
Step 2: WHILE i< n REPEAT STEPS 3 to 8
Step 3: SET j = 0
Step 4: WHILE j< n-i-1,REPEAT STEPS 5 to 7
Step 5: IF numList[j] > numList[j+1] THEN
Step 6: swap(numList[j],numList[j+1])
Step 7: SET j=j+1
Step 8: SET i=i+1

Selection sort
SELECTIONSORT( numList, n)
Step 1: SET i=0
Step 2: WHILE i< n REPEAT STEPS 3 to 11
Step 3: SET min = i, flag = 0
Step 4: SET j= i+1
Step 5: WHILE j< , REPEAT STEPS 6 to 10
Step 6: numList[min] THEN
Step 7: min = j
Step 8: flag = 1
Step 9: IF flag = 1 THEN
Step 10: swap(numList[i],numList[min])
Step 11: SET i=i+1

You might also like