A sorting algorithm is an algorithm that sorts the data into ascending or descending order.
Examples of such sorting algorithms are:
Showing posts with label sorting. Show all posts
Showing posts with label sorting. Show all posts
Wednesday, March 4, 2009
Tuesday, February 17, 2009
Exercise-Radix Sorting
Monday, February 16, 2009
Sorting Algorithm - HeapSort & Heapify
HeapSort(A)
---------------------------------
01 BuildMaxHeap(A)
02 For i <- A.Length to 2 do
03 Exchange A[1] <-> A[i]
04 A.HeapSize <- A.HeapSize-1
05 PercolateDown(A,1)
06 end for
---------------------------------
BuildMaxHeap(A) (i.e. Max-Heapify)
---------------------------------
01 A.HeapSize <- A.Length
02 For i <- (A.Length/2) to 1 do
03 PercolateDown(A,i)
04 end for
---------------------------------
---------------------------------
01 BuildMaxHeap(A)
02 For i <- A.Length to 2 do
03 Exchange A[1] <-> A[i]
04 A.HeapSize <- A.HeapSize-1
05 PercolateDown(A,1)
06 end for
---------------------------------
BuildMaxHeap(A) (i.e. Max-Heapify)
---------------------------------
01 A.HeapSize <- A.Length
02 For i <- (A.Length/2) to 1 do
03 PercolateDown(A,i)
04 end for
---------------------------------
Labels:
algorithm,
Data Structure,
Heapify,
HeapSort,
sorting
Monday, February 9, 2009
Selection Sorting An Array
Selection sorting an array A[0, 1, 2, ..., n-1]
01 SelectionSort(A[0, 1, 2, ..., n-1])
02 for (j <- 0) to (n-2) do
03 m <- j
04 for (i <- j+1) to (n-1) do
05 if A[m] > A[i] then
06 m <- i
07 end if
08 end for
09 exchange A[m] <-> A[j]
10 end for
01 SelectionSort(A[0, 1, 2, ..., n-1])
02 for (j <- 0) to (n-2) do
03 m <- j
04 for (i <- j+1) to (n-1) do
05 if A[m] > A[i] then
06 m <- i
07 end if
08 end for
09 exchange A[m] <-> A[j]
10 end for
Labels:
algorithm,
datastructures,
pseudocode,
SelectionSort,
sorting
Bubble Sorting An Array
Bubble sorting an array A[0, 1, 2, ..., n-1]
01 BubbleSort(A[0, 1, 2, ..., n-1])
02 i <- 0 03 repeat 04 exch <- False 05 for (j <- 0) to (n-2-i) do 06 if A[j] > A[j+1] then
07 exchange A[j] <-> A[j+1]
08 exch <- True
09 end if
10 end for
11 i <- i+1
12 Until exch = False
Click here for explanation on what is bubble sort?
01 BubbleSort(A[0, 1, 2, ..., n-1])
02 i <- 0 03 repeat 04 exch <- False 05 for (j <- 0) to (n-2-i) do 06 if A[j] > A[j+1] then
07 exchange A[j] <-> A[j+1]
08 exch <- True
09 end if
10 end for
11 i <- i+1
12 Until exch = False
Click here for explanation on what is bubble sort?
Labels:
algorithm,
BubbleSort,
datastructures,
pseudocode,
sorting
Subscribe to:
Posts (Atom)