Explore BrainMass

Explore BrainMass

    Analyzing an Algorithm for Assignment Statements

    This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

    For the following algorithm find the number of times the assignment statement (:=) is executed during the running of the program. Answer the question by giving a formula in terms of n:

    i := 1;
    while i < n + 1 do
    i := i + 2;
    for j := 1 to i do S od
    od

    © BrainMass Inc. brainmass.com March 4, 2021, 6:09 pm ad1c9bdddf
    https://brainmass.com/math/discrete-math/analyzing-algorithm-assignment-statements-32324

    Solution Preview

    Solution:
    Assume the number of times is m.

    From i:=1 we can get the number of time for this part is 1;

    From i:=i+2 we ...

    Solution Summary

    The solution finds the number of times the assignment statement is executed during the running of the program.

    $2.49

    ADVERTISEMENT