For problem 2b in exercise 2, should we use the floor or ceiling of the optimal jump size since optimal jump size=sqrt(n) and n=32? 5<sqrt(32)<6, so should we use 5 or 6?
The exercise states " Apply the algorithms exactly as presented in the lecture."
Now look at the slides where the optimal jump width is defined as m = ⌊√n⌋.
Now look at the slides where the optimal jump width is defined as m = ⌊√n⌋.
For problem 3, we should use INORDER-TREE-WALK(x) for the tree on slide 18 on lecture 3 notes but not use recursion. I however never get it to end without breaking before the next iteration in the big while loop when having two while loops here. Here is my code:
INORDER-TREE-WALK(x)
WHILE TRUE
S.push()
x=x.left
WHILE (x=NIL and S.top())
x=S.top()
print x.key
S.pop()
x=x.right
This means that the inner while loop runs as long as S.top() isn't empty but we still go out to the outer while-loop even after the inner ends and a break or end statement would end the program before we are done with the outer iterations, so how can we make it stop after it's done when we are only allowed to use pop, top and push?
INORDER-TREE-WALK(x)
WHILE TRUE
S.push()
x=x.left
WHILE (x=NIL and S.top())
x=S.top()
print x.key
S.pop()
x=x.right
This means that the inner while loop runs as long as S.top() isn't empty but we still go out to the outer while-loop even after the inner ends and a break or end statement would end the program before we are done with the outer iterations, so how can we make it stop after it's done when we are only allowed to use pop, top and push?
I think starting your loop with While True: might be the issue?
in essence, I do not grasp your algorithm, since it is not clear if you have two separated or nested WHILE loops. But as Kyle observed, you write "WHILE TRUE" which of course runs for ever, since you never updated the "TRUE" value. Where is this pseudo-code from?
Try to check if the stack is not empty in the outer while loop instead and you soon got it
For problem 10, how shall we think regarding the code? It says the name and location will help so something like 16 or 128 then? Two codes are given but how shall we know from them the meaning? The explaination is quite complicated for this problem.
Hi Robert,
I understand your confusion. Having deciphered the codes myself, I can tell you that most of the text serves as fluff. (By the way, to whoever wrote the exercise, I really enjoyed the prose; please keep cooking.) As far as your understanding of the question goes, you are already halfway there with the location of the kingdom. You need only combine that with the other half of the hint (reread the kingdom name carefully) and that should hopefully be enough for you and anyone else to solve it if you give it a couple of tries. Hope this helps.
I understand your confusion. Having deciphered the codes myself, I can tell you that most of the text serves as fluff. (By the way, to whoever wrote the exercise, I really enjoyed the prose; please keep cooking.) As far as your understanding of the question goes, you are already halfway there with the location of the kingdom. You need only combine that with the other half of the hint (reread the kingdom name carefully) and that should hopefully be enough for you and anyone else to solve it if you give it a couple of tries. Hope this helps.
thanks Doru!
@Robert: Well it is a riddle for some reason but I give you an extra hint: maybe some of the slides of the lecture may help.
@Robert: Well it is a riddle for some reason but I give you an extra hint: maybe some of the slides of the lecture may help.