Design and Analysis of
Algorithms Final Exam |
Questions & Answers
Study Guide 2026
Guidehttps://www.stuvia.com/dashboard!@_)#*)(@$)($@*($@)($@*_1 of 17
Page 1 of 17 Design and Analysis of Algorithms Final Exam _ Questions & Answers Study Guide 2026.pdf
,Design and Analysis of Algorithms Final Page 2 2026-03-20
Binary Search Input: An array of sorted numbers A, values x, min, and max
Output: The position of x in A
Input: An array of sorted numbers A, values x, min, and
max 1: (min = 0, max = n - 1)
2: if max < min then
3: return "x not in A"
4: else
5: if x < A[floor(max + min) / 2] then
6: return BinSrch(A,x,min,floor((max + min)/2)-1)
7: elif X > A[floor(max + min) / 2] then
8: return BinSrch(A,x,floor((max+min)/2)+1,max)
9: else
10: return floor((max+min) / 2)
O(log2(n))
Page 2 of 17 2 of 17 Design and Analysis of Algorithms Final.pdf
, Design and Analysis of Algorithms Final Page 3 2026-03-20
Merge Sort MergeSort
Input: A list of unsorted numbers A[0, ..., n - 1]
Input: A list of unsorted numbers A[0, ..., n - 1] Output: The same list, sorted in increasing order
1: if n <= 1 then
2: return A
3: else
4: return Merge(MergeSort(A[0 -> n/2],
MergeSort(A[(n/2) + 1 -> n-1])
Merge
1: if X = 0 return Y
2: if y = 0 return X
3: if X[0] <= Y[0] then
4: return X[0] º Merge(x[1 -> n - 1], y[0 -> n - 1])
5: else
6: return Y[0] º Merge(x[0 -> n - 1], y[1 -> n - 1])
O(nlog2(n))
Page 3 of 17 3 of 17 Design and Analysis of Algorithms Final.pdf