loveincode
دوشنبه 07 فروردین 1391, 19:58 عصر
Below is pseudo-code algorithm that prints a set of output values:
1. Get value for n
2. Set the value of k to 1
While k is less than or equal to n, do steps 4 through 8
4. Set the value of j to one half n
5. While j is greater than or equal to 1, do steps 6 through 7
6. Print the value of j
7. Set the value of j to one half its former value
8. Increase k by 1
9. Stop
Questions سوالها:
a. Let n have the value of 4. Write the values printed out by this algorithm
b. Let n have the value of 8. Write the
c. C. which of the following best describes the efficiency of this algorithm, where the work unit is printing a value?
Θ(n2) Θ(nlgn) Θ(n) Θ(lgn)
1. Get value for n
2. Set the value of k to 1
While k is less than or equal to n, do steps 4 through 8
4. Set the value of j to one half n
5. While j is greater than or equal to 1, do steps 6 through 7
6. Print the value of j
7. Set the value of j to one half its former value
8. Increase k by 1
9. Stop
Questions سوالها:
a. Let n have the value of 4. Write the values printed out by this algorithm
b. Let n have the value of 8. Write the
c. C. which of the following best describes the efficiency of this algorithm, where the work unit is printing a value?
Θ(n2) Θ(nlgn) Θ(n) Θ(lgn)