Question: 1. Suppose you have an algorithm that always takes 312 steps to complete, regardless of the input size. Thus, we can write T(n) = 312.

1. Suppose you have an algorithm that always takes 312 steps to complete, regardless of the input size. Thus, we can write T(n) = 312. Using the formal definition of Big-O, show that the function T(n) = 312 is O(1). Remember that this means you must demonstrate that there exist two constants n0 and c that meet the requirements in the formal definition.

2. In the following code snippet, assume X represents some segment of code that takes a fixed number C of steps to execute. Express the total number of steps taken by the code as a function of the variable n, and indicate the Big-O of that function. You do not have to use the formal definition here X while (n > 1) { X n = n/2; } Hint: Think about how many times the loop runs try substituting different values of n.

X while (n > 1) { X n = n/2; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!