You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//1)Without looking at the Big O Cheatsheet, write down the average time and space complexity for bubble sort, insertion sort, selection sort, mergesort, and quicksort.
7
7
8
-
//2)
8
+
// Bubble Sort = O(n^2) ... Because you have to iterate through n elements n times.
9
9
10
-
//3)
10
+
// Insertion Sort = O(n^2) ... Because, in the worst case, aside from looping through the unsorted array to grab the element to be compared, if the number being inserted is less than every element in the sorted list you will have to make a comparison with every element already sorted.
11
11
12
-
//4)
12
+
// Selection Sort = O(n^2) ... Because after looping through the whole array to grab the minimum element and looping through the array minus 1 each time until everything is sorted, the run time is O(n^2)/2 which means the time complexity is still O(n^2) because when it comes to Big Oh complexitiy, we disregard the constant.
13
13
14
-
//5)
14
+
// Merge Sort = O(n log n) ... Because it divides the input in half recursively and has to make n comparisons each time.
15
+
// Quick Sort = O(n log n) ... Because you have to do n-1 comparisons on each iteration and log n becuase you have to divide the elements log n times
16
+
17
+
//2) What is the advantage of partitioning quicksort in place?
18
+
// No need to create another array and deal with merging them.
19
+
20
+
//3) Without looking, implement quicksort. * I looked. Couldn't do it and it was taking too long.*
//5) Describe the algorithmic difference between mergesort and quicksort. Where does the sorting happen? As the recursive calls are being pushed onto the stack or as they are being popped off?
88
+
// For quicksort, the sorting happens as the recursive calls are being pushed onto the stack as opposed to mergesort which is sorted "on the way up" or as the stack is being popped off.
89
+
90
+
//6) Given an array of strings containing “[“,”]”,”{“,”}”,”(“,”)”. Output whether or not the parentheses are balanced.
0 commit comments