Question

Suppose I spend my weekends implementing this algorithm: method gradeLabs:     while there are ungraded labs...

  1. 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

  2. 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

  3. 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)

  4. 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)

  5. 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"

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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

Add a comment
Know the answer?
Add Answer to:
Suppose I spend my weekends implementing this algorithm: method gradeLabs:     while there are ungraded labs...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT