PDA

View Full Version : سوال: جواب سوال این psuedo-code چیست؟ پس فردا باید تحویل بدم. لطفا زود کمک کنید. البته با توضیح



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)

Mahdi1001
چهارشنبه 09 فروردین 1391, 20:05 عصر
سلام
این که خیلی ساده است
اولی
2 1 1
دومی
4 2 1 2 1 1
سومی
nlogn

کد سی شو می نویسم تا متوجه شی

for(k=1;k<=n;k++)
for(j=n/2;j>=1;j/=2)
cout<<j;