Suppose I spend my weekends implementing this algorithm:
method gradeLabs:
while there are ungraded labs
grade one lab
end loop
This algorithm is
O(n)
O(log n)
O(n ^ 2)
recursive
nondeterministic
Suppose I deal with my dirty dishes by implementing this pseudocode:
do:
Clean a plate
Throw two plates away
while there are dirty dishes remaining
announce that I am finished with the dishes
This algorithm is:
O(1)
O(log n)
O(n)
O(n log n)
recursive
Which of the following statements is true?
O(log n) is better than O(n)
O(n) is better than O(log n)
O(n ^ 2) is better than O(n log n)
O(n) is better than O(1)
recursive algorithms are always O(log n)
Suppose an instructor calls roll in a class, but only calls the student whose name appears first on the roll. This algorithm is
O(log n)
O(1)
O (n ^ 2)
O(n)
Suppose I use this algorithm:
while there are Brussels sprouts remaining:
eat one Brussels sprout
throw away half the remaining Brussels sprouts
This algorithm is
O(1)
O(n)
O(log n)
O(n ^ 2) note that CSNS can't show a superscript in an answer; read
^2 as "squared"
1. O(n)
Because, worst case scenario is that all the labs are ungraded. So lets ssay there are n labs then O(n) is the complexity as each assignment will be graded once
2. O(n)
for each plate cleaned we are throwing 2 plates.
So we are incrementing the counter by 2 at each iteration.
So we are running the loop for n/2 times
thus O(n) with c= 1/2
3.
a) O(log n) is better than O(n)
Only in this option first one is less than second one .. So O(logn) is better than O(n) is correct
4. O(1)
Only 1 person is called so it took constant time
5. Its O(logn)
because at each iteration, we are halving the sample set, so at each iteration N becomes n/2
which is O(logn)
eg. binary search
Suppose I spend my weekends implementing this algorithm: method gradeLabs: while there are ungraded labs...