CSE 310 Exam 1 questions with answers
|\ |\ |\ |\ |\ |\
Big O notation - CORRECT ANSWERS ✔✔O(g(n) = f(n) if f(n) <=
|\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\
a*g(n) while n >= b |\ |\ |\ |\
Big Ω notation - CORRECT ANSWERS ✔✔Ω(g(n)) = f(n) if f(n) >=
|\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\
a*g(n) while n >= b |\ |\ |\ |\
Big Θ notation - CORRECT ANSWERS ✔✔Θ(g(n)) = f(n) if f(n) <=
|\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\
a*g(n) and f(n) >= b*g(n) for all n >= c
|\ |\ |\ |\ |\ |\ |\ |\ |\
To prove correctness of algorithm, show ______, _____ and _____
|\ |\ |\ |\ |\ |\ |\ |\ |\ |\
hold - CORRECT ANSWERS ✔✔initialization, maintenance, and
|\ |\ |\ |\ |\ |\ |\
termination
Index of left child of node - CORRECT ANSWERS ✔✔i = index of
|\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\
node
2*i = index of node's left child
|\ |\ |\ |\ |\ |\
parent index in heap - CORRECT ANSWERS ✔✔i = index of node
|\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\
floor(i/2) = index of node's parent|\ |\ |\ |\ |\
What does heap-extract max do? - CORRECT ANSWERS ✔✔1)
|\ |\ |\ |\ |\ |\ |\ |\ |\
takes out the head of heap and replaces it with last node
|\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\
2) performs max-heapify on head
|\ |\ |\ |\
, Find the expression associated with the runtime of this
|\ |\ |\ |\ |\ |\ |\ |\ |\
pseudocode (i.e. C1 x n + C2 x n ... etc) and find the big O |\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\
approximation
k=1 // C1 |\ |\
do // C2 |\ |\
{
|\ j = 1 // C3
|\ |\ |\ |\
|\ do // C4 |\ |\
|\ {
|\ j = j*2 // C5
|\ |\ |\ |\
|\ }while(j < n) // C6 |\ |\ |\ |\
|\ k++ // C7 |\ |\
}while (k < n) // C8 - CORRECT ANSWERS ✔✔C1 x 1 + C2 x n +
|\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\
C3 x n + C4 x n(log_2(n)) + C5 x n(log_2(n)) + C6 x n(log_2(n))
|\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\
+ C7 x n + C8 x n = O(nlogn)
|\ |\ |\ |\ |\ |\ |\ |\ |\
Time of max-heapify - CORRECT ANSWERS ✔✔O(logn)
|\ |\ |\ |\ |\ |\
O approximation of T(n) = T(n/2)+cn+b - CORRECT ANSWERS
|\ |\ |\ |\ |\ |\ |\ |\ |\
✔✔O(nlogn)
What is the height of a heap? - CORRECT ANSWERS ✔✔The
|\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\
number of edges from head to lowest node |\ |\ |\ |\ |\ |\ |\
|\ |\ |\ |\ |\ |\
Big O notation - CORRECT ANSWERS ✔✔O(g(n) = f(n) if f(n) <=
|\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\
a*g(n) while n >= b |\ |\ |\ |\
Big Ω notation - CORRECT ANSWERS ✔✔Ω(g(n)) = f(n) if f(n) >=
|\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\
a*g(n) while n >= b |\ |\ |\ |\
Big Θ notation - CORRECT ANSWERS ✔✔Θ(g(n)) = f(n) if f(n) <=
|\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\
a*g(n) and f(n) >= b*g(n) for all n >= c
|\ |\ |\ |\ |\ |\ |\ |\ |\
To prove correctness of algorithm, show ______, _____ and _____
|\ |\ |\ |\ |\ |\ |\ |\ |\ |\
hold - CORRECT ANSWERS ✔✔initialization, maintenance, and
|\ |\ |\ |\ |\ |\ |\
termination
Index of left child of node - CORRECT ANSWERS ✔✔i = index of
|\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\
node
2*i = index of node's left child
|\ |\ |\ |\ |\ |\
parent index in heap - CORRECT ANSWERS ✔✔i = index of node
|\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\
floor(i/2) = index of node's parent|\ |\ |\ |\ |\
What does heap-extract max do? - CORRECT ANSWERS ✔✔1)
|\ |\ |\ |\ |\ |\ |\ |\ |\
takes out the head of heap and replaces it with last node
|\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\
2) performs max-heapify on head
|\ |\ |\ |\
, Find the expression associated with the runtime of this
|\ |\ |\ |\ |\ |\ |\ |\ |\
pseudocode (i.e. C1 x n + C2 x n ... etc) and find the big O |\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\
approximation
k=1 // C1 |\ |\
do // C2 |\ |\
{
|\ j = 1 // C3
|\ |\ |\ |\
|\ do // C4 |\ |\
|\ {
|\ j = j*2 // C5
|\ |\ |\ |\
|\ }while(j < n) // C6 |\ |\ |\ |\
|\ k++ // C7 |\ |\
}while (k < n) // C8 - CORRECT ANSWERS ✔✔C1 x 1 + C2 x n +
|\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\
C3 x n + C4 x n(log_2(n)) + C5 x n(log_2(n)) + C6 x n(log_2(n))
|\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\
+ C7 x n + C8 x n = O(nlogn)
|\ |\ |\ |\ |\ |\ |\ |\ |\
Time of max-heapify - CORRECT ANSWERS ✔✔O(logn)
|\ |\ |\ |\ |\ |\
O approximation of T(n) = T(n/2)+cn+b - CORRECT ANSWERS
|\ |\ |\ |\ |\ |\ |\ |\ |\
✔✔O(nlogn)
What is the height of a heap? - CORRECT ANSWERS ✔✔The
|\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\
number of edges from head to lowest node |\ |\ |\ |\ |\ |\ |\