Ask Question
11 April, 00:31

What is the f (n) runtime of the following pseudocode: sum = 0 for A = N/2 downto 1 for B = 1 to 4N increment sum by B

+4
Answers (1)
  1. 11 April, 00:51
    0
    f (N) = 2 + N/2 + 6N² units of time.

    Step-by-step explanation:

    Assigning 0 to the variable sum takes one unit of time.

    Each time you increment sum by B, you need to call the value of sum, sum it to B and assign it to sum, which takes three units of time in total. You are repeating this process for each value of B which ranges from 1 to 4n and for each value of A which ranges from 1 to n/2. Opening the FOR takes also another unit of time, so, as a result, we have

    f (N) 1 + 1 (open the FOR in A) + N/2 * (1 (open the FOR in B) + 4N*3) = 2 + N/2 + 6N² units of time. It has order complexity O (N²).
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “What is the f (n) runtime of the following pseudocode: sum = 0 for A = N/2 downto 1 for B = 1 to 4N increment sum by B ...” in 📗 Mathematics if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers