View Poll Results: What was your scaled score?

Voters
5. You may not vote on this poll
  • 850 <= score < infinity

    1 20.00%
  • 800 <= score < 850

    1 20.00%
  • 750 <= score < 800

    1 20.00%
  • 700 <= score < 750

    1 20.00%
  • 650 <= score < 700

    1 20.00%
  • 600 <= score < 650

    0 0%
  • 550 <= score < 600

    0 0%
  • 500 <= score < 550

    0 0%

Thread: Computer Science GRE subject exam

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #16
    Registered User
    Join Date
    Jan 2008
    Posts
    290
    How on earth does the loop terminate in question 15?
    k = floor(k / 2), when repeated, will cause k to become 0, thus terminating the loop. (Unless of course k is negative, but you can rule this out due to the explicitly stated invariant k >= 0)

    Question 15 is very simple if you just ignore all the unnecessary information. All you need to know is:
    Code:
    Invariant:  z*x^k = b^n  and  k >= 0
    ...
    while (k != 0)
    ...
    Clearly the only way this loop terminates is when k is zero. Substitute 0 for k in the invariant, and you get the answer.
    Code:
    z*x^0 = b^n
    z*1 = b^n
    z = b^n
    Also:
    Think of a the loop invariant as any condition that must remain true on entry and during all iterations of the loops.
    Using the terminology from question 14 of this practice GRE: "A loop invariant for a while statement is an assertion that is true each time the guard is evaluated during the execution of the while statement." The invariant does NOT have to be true at any arbitrary point in the body of the while loop, only before the body begins and after the body ends. I'm pretty sure you already know this, but I felt that statement needed some more exactificationness.

    [edit]
    Also, a loop can certainly have more than one invariant. In fact, I believe all loops have an infinite number of invariants.
    [/edit]
    Last edited by arpsmack; 04-08-2010 at 07:46 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Computer Science Exam Tomorrow!!!
    By cozman in forum C++ Programming
    Replies: 14
    Last Post: 05-23-2002, 08:23 AM
  2. The best university for computer science
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 19
    Last Post: 04-18-2002, 12:42 AM
  3. computer science or computer engineering??
    By pkananen in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 02-26-2002, 12:10 PM
  4. computer science rant
    By cozman in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 08-10-2001, 11:02 PM