2024 2-2 Algorithm Term Project Team I
Let's make it easier to understand by visualizing the sorting algorithms in the textbook.
You will be able to directly experience the time complexity of each algorithm.
Every algorithms have different time complexity. The size and numbers of data can affect to the time complexity of an algorithm.
Visualization technique can compare their running time with just few clicks. Finally, we can easily derive which algorithm is the efficient one at certain environment, i.e. specific numbers of data.
Sequence.1.mp4
The "Split Length" slider lets you decide how much you want to split the picture into small pieces. "Run 1 frame Per" slider to adjust how many seconds you want to run one frame.
And choose algorithm u want!
// Sorts (a portion of) an array, divides it into partitions, then sorts those
algorithm quicksort(A, lo, hi) is
if lo >= 0 && hi >= 0 && lo < hi then
p := partition(A, lo, hi)
quicksort(A, lo, p) // Note: the pivot is now included
quicksort(A, p + 1, hi)
// Divides array into two partitions
algorithm partition(A, lo, hi) is
// Pivot value
pivot := A[lo] // Choose the first element as the pivot
// Left index
i := lo - 1
// Right index
j := hi + 1
loop forever
// Move the left index to the right at least once and while the element at
// the left index is less than the pivot
do i := i + 1 while A[i] < pivot
// Move the right index to the left at least once and while the element at
// the right index is greater than the pivot
do j := j - 1 while A[j] > pivot
// If the indices crossed, return
if i >= j then return j
// Swap the elements at the left and right indices
swap A[i] with A[j]
Cormen, Thomas H.; Leiserson, Charles E.; Rivest, Ronald L.; Stein, Clifford (2009) [1990]. "Quicksort". Introduction to Algorithms (3rd ed.). MIT Press and McGraw-Hill. pp. 170–190. ISBN 0-262-03384-4.
procedure bubbleSort(A : list of sortable items)
n := length(A)
repeat
swapped := false
for i := 1 to n - 1 inclusive do
if A[i - 1] > A[i] then
swap(A[i - 1], A[i])
swapped := true
end if
end for
n := n - 1
until not swapped
end procedure
https://en.wikipedia.org/wiki/Bubble_sort