Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Suppose you have two algorithms, blarg and wibble, with time complexity Suppose

ID: 3831493 • Letter: S

Question

Suppose you have two algorithms, blarg and wibble, with time complexity

Suppose you have two algorithms, blarg and wibble, with time complexity Ohm(n log n) and Ohm(n) respectively. blarg modifies the input, while wibble just checks something about the input and returns True or False. You write a new algorithm: For i = 1 to n If wibble blarg End-if End-for Assume all calls to blarg and wibble occur on an input of size n. (a) Suppose wibble always returns True. (It still takes Theta(n) time.) What is the time complexity of the algorithm? (b) Suppose instead that wibble always returns False. What is the time complexity of the algorithm? (c) Suppose instead that for the worst case input, wibble returns True for about log_5(n) values of i in the For loop. What is the time complexity of the algorithm?

Explanation / Answer

answer for a) is O(n2log2n) as outer executes n times for each execution for loop wibble takes O(n) and blarg takes O(nlogn) where n is the size of the input

answer for b) is O(n2) as it executes for loop n times and wibble takes O(n)

answer for c) is O(nlog5nlog2n)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote