Go Back   TestMagic Forums > Test preparation > GRE Subject Tests > GRE Computer Science
Register FAQForum Rules Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 10-23-2003, 08:40 PM   #1 (permalink)
AlbaLed
TestMagic Guru-in-Training
 
Join Date: Oct 2003
Location: Albania
Posts: 534
AlbaLed has disabled reputation
Can you find out what do this functions do? Can you prove it? Don't worry about parameter passing methods, just what happens inside the function
Code:
1.
f(x,y)
{
    x:=x+y
    y:=x-y
    x:=x-y
}

2. what's returned?
f(y,z)
{
    x:=1
    while z>0 do
        x:=x*y
        z:=z-1
   return (x)
}

3. what's returned?
f(y,z)
{
    x:=1
    while z>0 do
       if x is odd then x:=x*y
        z:= floor(z/2)
        y:=y^2
   return (x)
}

4. what's returned?
f(y,z)
{
    x:=0
    while z>0 do
        x:=x+y*(z mod 2)
        y:=2y
        z:=floor(z/2)
   return (x)
}

Enjoyy!!!!!!!!!

AlbaLed
AlbaLed is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Google Bookmark this Post!Reddit!
Reply With Quote
Old 10-23-2003, 10:55 PM   #2 (permalink)
jaideep
Within my grasp!
 
Join Date: Oct 2003
Posts: 137
jaideep has disabled reputation
1) Swapping
2) y power z
3) This is my guess y (even) then x = y^(2^(|_ lg n _| + 1) - 1)
y = odd then x = y.
4) Convert the z value to its binary equivalent. Start from right side as y then move left as 2.y further left as y.2^2 ans so on. Each time you encounter a one in the binary multiply by its equivalent y factor and add it to the sum.

e.g 1 1 1 1
2.2.2.y 2.2.y 2.y y

This gives me another idea to state the same thing.
Write down the expression for converting a binary number represented by z to its equivalent decimal number.
Then instead of multiplying by 2^i at the places multiply it by y.2^i.

Nice one.
Jaideep
jaideep is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Google Bookmark this Post!Reddit!
Reply With Quote
Old 10-24-2003, 01:02 AM   #3 (permalink)
AlbaLed
TestMagic Guru-in-Training
 
Join Date: Oct 2003
Location: Albania
Posts: 534
AlbaLed has disabled reputation
Anyone else want to give 'em a try before I post the answers, Jaideep got some right, not necessarily all, I will not point which though. I'll post the answers in about 2-3 hours

AlbaLed
AlbaLed is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Google Bookmark this Post!Reddit!
Reply With Quote
Old 10-24-2003, 11:19 AM   #4 (permalink)
crackit
Eager!
 
Join Date: Jul 2003
Location: India
Posts: 90
crackit has disabled reputation
answer to 4

is 2*(number of 1 in Z)
crackit is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Google Bookmark this Post!Reddit!
Reply With Quote
Old 10-24-2003, 11:21 AM   #5 (permalink)
crackit
Eager!
 
Join Date: Jul 2003
Location: India
Posts: 90
crackit has disabled reputation
Quote:
Originally posted by crackit

answer to 4

y*z
crackit is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Google Bookmark this Post!Reddit!
Reply With Quote
Old 10-24-2003, 08:32 PM   #6 (permalink)
AlbaLed
TestMagic Guru-in-Training
 
Join Date: Oct 2003
Location: Albania
Posts: 534
AlbaLed has disabled reputation
Answers are

1. swaping
2. x power y

typo on 3, sorry
Code:
f(y,z)
{
    x:=1
    while z>0 do
       if z is odd then x:=x*y
        z:= floor(z/2)
        y:=y^2
   return (x)
}
3. y power z
4. y*z

Good job jaideep and crackit

AlbaLed
AlbaLed is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Google Bookmark this Post!Reddit!
Reply With Quote
Old 10-25-2003, 01:10 AM   #7 (permalink)
bb
Trying to make mom and pop proud
 
Join Date: Oct 2003
Posts: 14
bb has disabled reputation
For swapping 1. has to have

x:= x + y
y:= x - y
x:= x - x

bb is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Google Bookmark this Post!Reddit!
Reply With Quote
Old 10-25-2003, 01:32 AM   #8 (permalink)
bb
Trying to make mom and pop proud
 
Join Date: Oct 2003
Posts: 14
bb has disabled reputation
#2.

Let's say z:=5

z:= 5 ( >0) x := 1*y z:=5-1 = 4
z:=4 ( >0) x ..> 1*y*y z:=4-1 = 3
z:=3 ( >0) x ..> 1*y*y*y z:=3-1 = 2
z:=2 ( >0) x ..> 1*y*y*y*y z:=2-1 = 1
z:=1 ( >0) x ..> 1*y*y*y*y*y z:=1-1 = 0
z:=0 not >0 OUT

x = y^z (not x^y)
bb is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Google Bookmark this Post!Reddit!
Reply With Quote
Old 10-25-2003, 01:32 AM   #9 (permalink)
AlbaLed
TestMagic Guru-in-Training
 
Join Date: Oct 2003
Location: Albania
Posts: 534
AlbaLed has disabled reputation
wouldn't

x=x-x be 0 ???

it is not x-x because now the previous value of x is in y.
AlbaLed
AlbaLed is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Google Bookmark this Post!Reddit!
Reply With Quote
Old 10-25-2003, 02:07 AM   #10 (permalink)
bb
Trying to make mom and pop proud
 
Join Date: Oct 2003
Posts: 14
bb has disabled reputation
Sorry for #1. :o)
bb is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Google Bookmark this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

What you can do
You cannot post new threads
You cannot post replies
You cannot post attachments
You cannot edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 06:11 PM.

Contact TestMagic   TestMagic Forums      Archive   

Link to TestMagic   TestMagic Locations   Legal   Privacy

Partner Sites: GMAT Sentence Correction   SAT 2400

Content Relevant URLs by vBSEO 3.0.0
Copyright © 1998-2008 TestMagic
Ad Management by RedTyger

Scroll Up