2. Consider the following algorithm which receives as input two numbers m and n and sets result to m x n; div is the integer division operator. result repeat 0 if m is odd then L result mm div 2 nnn until m < 1: result + n • State (as a function of m and n) how many times the loop is executed and justify your answer. • Give the running time of the algorithm in ☺ notation as a function of m and n. Explain how you reached the answer.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter5: Repetition Statements
Section5.5: A Closer Look: Loop Programming Techniques
Problem 12E: (Program) Write a program that tests the effectiveness of the rand() library function. Start by...
icon
Related questions
Question

I need a help on this. Thank you 

2. Consider the following algorithm which receives as input two numbers m and n and sets
result to m x n; div is the integer division operator.
result
repeat
0
if m is odd then
L result
mm div 2
nnn
until m < 1:
result + n
• State (as a function of m and n) how many times the loop is executed and justify your
answer.
• Give the running time of the algorithm in ☺ notation as a function of m and n. Explain
how you reached the answer.
Transcribed Image Text:2. Consider the following algorithm which receives as input two numbers m and n and sets result to m x n; div is the integer division operator. result repeat 0 if m is odd then L result mm div 2 nnn until m < 1: result + n • State (as a function of m and n) how many times the loop is executed and justify your answer. • Give the running time of the algorithm in ☺ notation as a function of m and n. Explain how you reached the answer.
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr