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!