Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Apr 26th, 2005, 1:19 AM   #1
Nano
Newbie
 
Nano's Avatar
 
Join Date: Aug 2004
Location: Hacienda Heights, CA
Posts: 8
Rep Power: 0 Nano is on a distinguished road
Send a message via AIM to Nano Send a message via MSN to Nano Send a message via Yahoo to Nano
Strategy to Solve these 2 questions

Hi everyone! AP tests are coming (Start next week) and I am taking Computer Science AB's test. While I was reviewing (doing last year's ap test), I found myself have most trouble on these 2 types of question:
The first type is
public static int indonesia(int p, int q)
{
     if (p/q == 0)
          return q;
     else
          return indonesia (q, p/q);
}

public static int thailand (int p, int q)
{
     int temp = -1;
     int value = 0;
     while (temp != 0)
     {
          temp = p/q;
          if (temp == 0)
          {
                 value = q;
          }
          else
          {
                 p = q;
                 q = temp;
          }
      }
       return value;
}

For which values of p and q do indonesia (p,q) and thailand (p, q) return the same result?
(A) For all values of p and q
(B) For all values, such that p > q
(C) For all values, such that p <= q
(D) For all values, such that p > 0 and q >0
(E) For no values of p and q
I was wondering how to solve the above problem during the test. I think there's 2 approaches, first is plug values respect to the answer in, or recognize the program pattern. Plug the value and test takes a long time, and sometimes I can't recognize the program pattern. Can anybody share their strategy to solve this kind of problem?

Second is Boolean Algebra:
a && (a || b)
a || (a && b)
For which values of a and b are the two expressions equivalent?
(A) For all values of a and b
(B) For no values of a and b
(C) Only whenever a is true
(D) Only whenever b is true
(E) Only whenever both a is true and b is true
Do I plug True or False to test the expressions? I have no idea how to do this kind.

I hope I can get some help because I couldn't get any help from school.......
Thanks in Advance!
__________________
why....why u.s. citizen.............
Nano is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:51 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC