Results 1 to 11 of 11
Thread: Simple question...
- 08-10-2011, 06:45 PM #1
Member
- Join Date
- Aug 2011
- Posts
- 3
- Rep Power
- 0
Simple question...
Hi Guys, can anyone help me with a past paper question i'm looking at for MSc Computing.. it's only worth 4 marks so i'm guessing it's a brief answer but I need to be sure of it incase it comes up again.
Given the following recursive function definition
<CODE>
public static int rec (int n) {
if (n <= 2) return 1;
else return rec(n-1) + rec(n-2);
}
</CODE>
What is the value of rec(5)? Explain your answer.
Is this related to fibonacci numbers?
Any help appreciated (and just incase anyone says they can't help with homework... the year is completed, there aren't any more assignments it's just revision and no masters homework would be this simple :P )
- 08-10-2011, 07:05 PM #2
Have you executed the code and gotten an answer from it?What is the value of rec(5)?
What was the result?
If you want to know what the code is doing, add some printlns to it to show how the variables are changing.
- 08-10-2011, 07:40 PM #3
In addition to what Norm said, have you traced through this with a piece of paper and a pencil? Keep track of what methods are called, what the parameters are, etc. Cross things out, draw lines, etc. That's how you'd answer this on a test, so it's a good skill to pick up.
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 08-10-2011, 09:03 PM #4
- Join Date
- Dec 2010
- Location
- Stockholm, Sweden
- Posts
- 222
- Blog Entries
- 9
- Rep Power
- 3
ÖööhhUhhmm!
I'm not sure want »past paper question i'm looking at for MSc Computing.. it's only worth 4 marks» (the underlined parts) means, but you are clearly asking us to do your homework.
And that part with »the year is completed, there aren't any more assignments» does ensure us that this is not so you can get a better grade than you already got (sv: plussning; do not know the english word), that it is not completion nor a summer class, neither that school has not started for you (just 2½ weeks left for me, and the school is full (really, the trains are more overloaded than usually)).Last edited by Hibernate; 08-10-2011 at 09:28 PM.
Ex animo! Hibernate
Java, Arch Linux, C, GPL v3, Bash, Eclipse, Linux VT, GNOME 2 and many buttons on windows.
- 08-10-2011, 09:05 PM #5
- Join Date
- Dec 2010
- Location
- Stockholm, Sweden
- Posts
- 222
- Blog Entries
- 9
- Rep Power
- 3
And:
If you do not understand recursion read this line!
Not to be confused with:
If you do not understand recursion read this line again!
However:
If you do not understand iteration read this line again!Ex animo! Hibernate
Java, Arch Linux, C, GPL v3, Bash, Eclipse, Linux VT, GNOME 2 and many buttons on windows.
- 08-10-2011, 09:45 PM #6
- Join Date
- Dec 2010
- Location
- Stockholm, Sweden
- Posts
- 222
- Blog Entries
- 9
- Rep Power
- 3
I have had simpler, examples (explain and translated):
What is your ID on the computer network maintained by the university's school/department (do not remember which) for computer science?
How large is the biggest file in your home folder (including subfolders) in that network? (command line supplied)
How many multiplications is needed for square matrix multiplication? (The naïve method is allowed)
Play a specific game and tell how many moves that can be done in the initial state.
Use any operation in C except for - (minus) and use only [0, 255] numbers, to return -1.
In C, reverse the order of the bytes in an integer.
In C, reverse the order of the bits in an integer.
The list goes on…
Edit:
Another, although in pure mathematic (real analysis), but this was on (both an final exam and) home exam:
Construct a set with exactly three cluster points.Last edited by Hibernate; 08-10-2011 at 09:56 PM.
Ex animo! Hibernate
Java, Arch Linux, C, GPL v3, Bash, Eclipse, Linux VT, GNOME 2 and many buttons on windows.
- 08-10-2011, 10:08 PM #7
Member
- Join Date
- Aug 2011
- Posts
- 3
- Rep Power
- 0
You are clearly a crazy person.... and as for 'you are clearly asking us to do your homework'... this is 1 small question from 1 past paper of which I have 6 of dating back to 2005. I don't know how university works in your country you offensive little man but in my country we don't give in 'homework' assignments in the middle of August! The teaching year finished months ago!
To the others that actually said useful things... I get the answer 5 when I use an applet but it doesn't give me an explanation as to why. It isn't too important that I know this as the chances of the question coming up again are very slim but if an intelligent person on here manages to recognise the fact that this isn't even worthy of being a bloody 'homework' question and can give me a simple explanation that would be great.
- 08-10-2011, 10:20 PM #8
- Join Date
- Dec 2010
- Location
- Stockholm, Sweden
- Posts
- 222
- Blog Entries
- 9
- Rep Power
- 3
No reason to be rude[ish], but yes, I'm crazy how else do you become a geek, and take advanced classes years before you are supposed to take them, &c.
Are you telling me that you cannot take classes over the summer [and maybe even get paid for it], in your country‽‽
Neither that you can complete them after the class has finished, or try to get a higher grade‽‽
But that you think the question is rudimentary, but that you cannot answer it?
I'm [truly] sorry, but I do not believe you.
Didn't you see my last post, it explain how you should solve it!
(I got the impression that you do not understand recursion; if you do, say so)
Well, give you the explanation [The classic explanation of recursion: »If you do not understand recursion read this line!»]…Ex animo! Hibernate
Java, Arch Linux, C, GPL v3, Bash, Eclipse, Linux VT, GNOME 2 and many buttons on windows.
- 08-10-2011, 10:24 PM #9
- Join Date
- Dec 2010
- Location
- Stockholm, Sweden
- Posts
- 222
- Blog Entries
- 9
- Rep Power
- 3
And yes, that was the Fibonacci numbers.
Fⁿ = Fⁿ⁻¹ + Fⁿ⁻²; F¹ = F² = 1Ex animo! Hibernate
Java, Arch Linux, C, GPL v3, Bash, Eclipse, Linux VT, GNOME 2 and many buttons on windows.
- 08-10-2011, 10:31 PM #10
- Join Date
- Dec 2010
- Location
- Stockholm, Sweden
- Posts
- 222
- Blog Entries
- 9
- Rep Power
- 3
But if you need another explanation:
Java Code:[1] = 1 [2] = 1 \ / \ \ / \ [3] = [1]+[2] = 2 \ | \ \ | \ | | [4] = [2]+[3] = 3 | | | / | / [5] = [3]+[4] = 5Ex animo! Hibernate
Java, Arch Linux, C, GPL v3, Bash, Eclipse, Linux VT, GNOME 2 and many buttons on windows.
- 08-10-2011, 10:44 PM #11
Member
- Join Date
- Aug 2011
- Posts
- 3
- Rep Power
- 0
I don't enjoy being called a liar when i'm not lying so that's why I took offence but thank you for explaining it all the same.
Yes I knew it was a recursive function but I couldn't get my head around the wording of the question. I was ill during the original programming exam in June so I am having my first attempt at a new paper on Wednesday and this question was one of the smaller starter questions in the June exam. I'm sorry that you don't believe me but if it matters that much that you think you've helped someone cheat a homework assignment I will take a photograph of the paper and send it to you!
Similar Threads
-
Simple Question
By stackptr89 in forum New To JavaReplies: 13Last Post: 01-29-2011, 05:35 PM -
very simple Question
By arsenal4ever_11 in forum NetBeansReplies: 2Last Post: 05-27-2010, 08:51 PM -
some simple question?
By jperson in forum New To JavaReplies: 4Last Post: 05-03-2010, 05:32 PM -
Simple Question
By barusk in forum NetworkingReplies: 13Last Post: 03-04-2009, 07:33 PM -
Probably a really simple question...
By ibanez270dx in forum New To JavaReplies: 0Last Post: 11-16-2007, 01:27 AM


4Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks