Ask Question
2 October, 09:45

A. Consider the following algorithm segment: for i : = 1 to 4, for j : = 1 to i, [Statements in body of inner loop. None contain branching statements that lead outside the loop.] next j, next i. How many times will the inner loop be iterated when the algorithm is implemented and run?

b. Let n be a positive integer, and consider the following algorithm segment: for i : = 1 to n, for j : = 1 to i, [Statements in body of inner loop. None contain branching statements that lead outside the loop.], next j, next i. How many times will the inner loop be iterated when the algorithm is implemented and run?

+1
Answers (1)
  1. 2 October, 13:28
    0
    (a) 4i times

    (b) "i * n" times

    Step-by-step explanation:

    (a) Given the algorithm segment;

    for i : = 1 to 4, (Outer loop)

    for j : = 1 to i (Inner loop)

    next j,

    next i

    The inner loop runs for i times, while the outer loop runs for 4 times.

    The total times the inner loop would run when the entire algorithm is run is:

    = i * 4

    = 4i times

    (b) Given the algorithm segment;

    for i : = 1 to n, (Outer loop)

    for j : = 1 to i (Inner loop)

    next j,

    next i

    Where n is a set of positive integers.

    The inner loop runs for "i" times, while the outer loop runs for "n" times.

    The total times the inner loop would run when the entire algorithm is run is:

    = i * n

    = "i * n" times
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “A. Consider the following algorithm segment: for i : = 1 to 4, for j : = 1 to i, [Statements in body of inner loop. None contain branching ...” in 📙 Mathematics if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers