Algorithm Analysis Project at Universitas Pelita Harapan
| No | Profile Picture | Member Name | Github Userid | Student Id Number |
|---|---|---|---|---|
| 1. | Bryan Christofel Yehezkiel | @bryanchr | 00000016528 | |
| 2. | Feronia Meilinda | @feroniameimei | 00000012566 | |
| 3. | Rickhen Hermawan | @rickhenhermawan | 00000012311 | |
| 4. | Sudono Tanjung | @sudtanj | 00000012273 |
Cpu = Intel(R) Xeon(R) CPU @ 2.30GHz
Core = 4
Ram = 512 MB
Storage = 2 GB
PancakeFlipper(A[1 · · n])
if n > 1
Let k be the index if the largest pancake
Flip(A[1 · · k])
Flip(A[1 · · n])
PancakeFlipper(1 · · n − 1)
- Run Time (based on flips): O(n2)
- Memory Required: O(n)
- Run Time (based on flips): O(n)
- Memory Required: O(n)
# Sort an array a[0...n-1].
gaps = [701, 301, 132, 57, 23, 10, 4, 1]
# Start with the largest gap and work down to a gap of 1
foreach (gap in gaps)
{
# Do a gapped insertion sort for this gap size.
# The first gap elements a[0..gap-1] are already in gapped order
# keep adding one more element until the entire array is gap sorted
for (i = gap; i < n; i += 1)
{
# add a[i] to the elements that have been gap sorted
# save a[i] in temp and make a hole at position i
temp = a[i]
# shift earlier gap-sorted elements up until the correct location for a[i] is found
for (j = i; j >= gap and a[j - gap] > temp; j -= gap)
{
a[j] = a[j - gap]
}
# put temp (the original a[i]) in its correct location
a[j] = temp
}
}
- O(n2) (worst known gap sequence)
- O(n log2n) (best known gap sequence)
- O(n log n)
- depends on gap sequence
Begin
1. i = 1
2. j = size
3. while (i < j) do
begin
4. if array[i] > array[j] swap (array, i, j)
5. i = i + 1
6. j = j – 1
end
[Call Bidirectional Bubble Sort to sort the adjacent elements]
7. Bidirectional Bubble Sort (A, size:int)
End
- The worst-case occurs in a sorting algorithm when the elements to be sorted are in reverse order.
- The best-case occurs when the elements are already sorted.
- The average–case may occur when part of the elements are already sorted or data randomly distributed in the list. The average case may not be easy to determine in that it may not be apparent what constitutes an ‘average’ input.
Avi_Sort (A, N)
//Let A is a linear array with N elements i.e. A [1: N]
Step 1 Repeat steps 2, 3 and 4 for i = 1 to N-1
Step2 Repeat step 3 for j = 1 to N-1-i
Step 3 //Exchange Elements
if A[j]> A[j+2]
A[j] ↔ A [j+2]
//End of if statement
//End of step 2 for statement
Step 4 //Exchange Elements
if A[j]> A[j+1]
A[j] ↔ A [j+1]
//End of if statement
//End of step 1 for statement
Step 5 Exit
Fig.
- O(N2)
- execution time lies in between selection and insertion sort
- O(N)
- Avi sort execution time is equal to insertion sort









