Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,143,232 members, 7,780,446 topics. Date: Thursday, 28 March 2024 at 02:28 PM |
Nairaland Forum / Science/Technology / Programming / Computer Science Algorithm Problem (2830 Views)
Why Waste 4 Years On Computer Science In University? / Best Uni For Bsc. Computer Science In Nigeria / Ludo Game Algorithm Wanted For AI Project (2) (3) (4)
Computer Science Algorithm Problem by talk2hb1(m): 4:39pm On Jun 28, 2012 |
Hello Everybody in house, I got this problem from somebody in my office who is preparing for his MIS in UNILAG and she brought this past question with the hope that I could be of help as a programmer. But the question are more of computer science than programming. Please help her out. ok these are the questions procedure mystery a : integer b : integer procedure enigma (x, y) begin y = y + b; x = b + x; b = x + b; a = y; end enigma begin a = 2; b = 7 enigma (a, b); write (a); write (b); end mystery; 1. suppose that all parameters are passed by value, what will be the values of the output when procedure mystery is called? 2. suppose that all parameters are passed by reference, what will be the values of the output when procedure mystery is called? 3. Consider the following pseudocode? x : = 1; i ; = 1; while (x ≤ 1000 ) begin x ; = 2n i = i + 1; end; what is value of i at the end of the dseudocode? 4. consider the following recursive algorithm G (n) ; integer result : integer begin if n ≤ 1 then result = n else result = 5G(n - 1) - 6G(n-2) end Thank you |
Re: Computer Science Algorithm Problem by Beaf: 10:55pm On Jun 28, 2012 |
The answer is quite simple, bro. If a = 2 and b = 7, when you pass the a and b in by reference, then the internals of enigma(a, b) will work like so: b = b + b; /*value of external variable b you passed in changes, the new value will be used in subsequent calculations*/ a = b + a; /*value of external variable a you passed in changes, the new value will be used in subsequent calculations*/ b = a + b; /*value of external variable b you passed in changes, the new value will be used in subsequent calculations*/ a = b;/*value of external variable a you passed in changes*/ when you pass the a and b in by value, then within enigma(a, b), y and x would have no effects on the values of the external variables a and b; their values would only change when you hit the lines that do b = x + b and a = y. 3. Consider the following pseudocode? So long as the way the value of n varies is not given, the question is meaningless. The value of n must vary for the above code to function. Your last problem (4) is not well stated. |
Re: Computer Science Algorithm Problem by Fnights: 2:50am On Jun 29, 2012 |
1. a = 14, b = 16; Solution: a=2; b=7 enigma(x=2,y=7)//passing by value begin y = 7 + b = 14 x = b + 2 = 9 b = 9 + b = 16 a = 14 end enigma 2. a= 23; b = 23 solution a=2;b=7 enigma(a,b)//passing by reference begin b = b + b = 14 a = b + a = 9 b = a + b = 23 a = 23 end enigma 3. I have to agree with beaf, the value of n is unknown 4. The question needs more clarification. |
Re: Computer Science Algorithm Problem by talk2hb1(m): 1:28pm On Jun 29, 2012 |
Thanks really appreciate that |
(1) (Reply)
Javascript: The Best Best Materials To Learn It With. / I Need An Android App Developer. / How Did You Land You First Job As A Self-taught Developer?
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 10 |