0% found this document useful (0 votes)
87 views2 pages

Pseudocode For Sorting Algorithms

The document describes three sorting algorithms: Insertion sort works by iterating through an array and inserting each element into its sorted position; Bubble sort iterates through adjacent elements and swaps them if out of order; Selection sort finds the smallest element in the unsorted portion of the array and swaps it with the first element of that portion on each pass.

Uploaded by

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

Pseudocode For Sorting Algorithms

The document describes three sorting algorithms: Insertion sort works by iterating through an array and inserting each element into its sorted position; Bubble sort iterates through adjacent elements and swaps them if out of order; Selection sort finds the smallest element in the unsorted portion of the array and swaps it with the first element of that portion on each pass.

Uploaded by

Timothy Detre
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Insertion Sort

int TEMP
int J
int I = 0
loop while I <= size -1
input A[I]
J = I
loop while J > 0 and A[J] < A[J - 1]
TEMP = A[J]
A[J] = A[J - 1]
A[J - 1] = TEMP
J = J - 1
end loop
I=I+1
end loop

Bubble Sort
int TEMP
int J
int I = 0
loop while I < size -1
J = 0
loop while J < size -1
if A[J] > A[J + 1] then
TEMP = A[J]
A[J] = A[J + 1]
A[J + 1] = TEMP
end If
J=J+1
end loop
I=I+1
end loop
Selection sort
The idea of Selection Sort is that we repeatedly find the smallest
element in the unsorted part of the array and swap it with the first
element in the unsorted part of the array.
int I=0
int J
int SMALLSUB
int TEMP
loop while I <= size -1

SMALLSUB = I
J=I+1
loop while J <= size -1
if A[J] < A[SMALLSUB] then
SMALLSUB = J
end-If
J=J+1
end loop
TEMP = A[I]
A[I] = A[SMALLSUB]
A[SMALLSUB] = TEMP
I=I+1
end loop

You might also like