What is the Bubble Sort Algorithm
Describe the psudocode for a Bubble Sort Algorithm
Function BubbleSort (int[] data)
numItems = data.length - 1
For i = 0 to numItems - 2
For j = 0 to numItems - i - 2
If data[j] > data[j + 1]
temp = data[j]
data[j] = data[j + 1]
data[j + 1] = temp
end if
next j
next i
end fucntion
Describe the pseudocode for a Improved Bubble Sort Algorithm
Function BubbleSort (int[] data)
numItems = data.length - 1
Swapped = true
WHILE numItems > 0 AND swapped
Swapped = False
numItem = numItems – 1
FOR count = 0 to numItems – 1
IF data[count] > data[count + 1] THEN
temp = data[count + 1]
data[count + 1] = data[count]
data[count] = temp
Swapped = True
END IF
NEXT Count
END WHILE
return data
END FUNCTION
Why do we use an Improved Bubble Sort Algorithm
What is the Time Complexity and Space Complexity of the Bubble Sort
Best Case Time Complexity- O (n)
Wosrt Case Time Complexity - O (n2)
Space Complexity - 0 (n)
What is the Insertion Sort Algorithm
Describe the pseudocode for a Insertion Sort
Function insertionSort(int[] data)
For count = 1 to data.length
currentdata = data[count]
While (count > 0 AND data[count –1] > currentdata
temp = data[count]
data[count] = data[count - 1]
data[count - 1] = temp
count = count - 1
End while
data[count] = currentdata
NEXT COUNT
END FUNCTION
return A
What is the Time Complexity of an Insertion Sort
Worst Time Complexity - O (n2)
Best Time Complexity - O (n)
Space Complexity - O (k)
What is a Merge Sort Algorithm
What is the Time Complexity and Space Complexity of a Merge Sort
Best and Worst Time Complexity - O(n logn)
Space Complexity - O (n) because the merge sort needs extra space for the left and right sublists that are created whenever items is split, if the original list has n items, then the sublists will also need to hold n items in total
What is a Quick Sort Algorithm
What is the Time Complexity of a Quick Sort Algorithm
O (n log n)