Professional Documents
Culture Documents
Data Structures and Abstractions with Java 4th Edition Carrano Test Bank instant download all chapter
Data Structures and Abstractions with Java 4th Edition Carrano Test Bank instant download all chapter
Data Structures and Abstractions with Java 4th Edition Carrano Test Bank instant download all chapter
https://testbankdeal.com/product/data-structures-and-
abstractions-with-java-4th-edition-carrano-solutions-manual/
https://testbankdeal.com/product/data-structures-and-
abstractions-with-java-5th-edition-carrano-solutions-manual/
https://testbankdeal.com/product/starting-out-with-java-from-
control-structures-through-data-structures-3rd-edition-gaddis-
test-bank/
https://testbankdeal.com/product/starting-out-with-java-from-
control-structures-through-data-structures-2nd-edition-gaddis-
test-bank/
Starting Out with Java From Control Structures through
Data Structures 3rd Edition Gaddis Solutions Manual
https://testbankdeal.com/product/starting-out-with-java-from-
control-structures-through-data-structures-3rd-edition-gaddis-
solutions-manual/
https://testbankdeal.com/product/starting-out-with-java-from-
control-structures-through-data-structures-2nd-edition-gaddis-
solutions-manual/
https://testbankdeal.com/product/java-foundations-introduction-
to-program-design-and-data-structures-4th-edition-lewis-test-
bank/
https://testbankdeal.com/product/data-structures-and-algorithms-
in-java-1st-edition-peter-drake-solutions-manual/
https://testbankdeal.com/product/data-structures-and-algorithm-
analysis-in-java-3rd-edition-weiss-solutions-manual/
Chapter 7 - Recursion
True/False (10)
Answer: true
Answer: false
Answer: false
4. You can use a recurrence relation to determine the performance of a recursive method.
Answer: true
Answer: false
6. Activation records for recursive methods are the same as activation records for non-recursive
methods.
Answer: true
Answer: false
8. An iterative solution to the Towers of Hanoi problem moves fewer disks than the recursive
solution.
Answer: false
Answer: true
10. You can replace recursion with iteration by simulating the program stack.
Answer: true
Short Answer (7)
Answer: Each Fibonacci number is calculated multiple times. The larger the Fibonacci sequence, the
more redundant calculations are performed.
2. What is the value returned from the following method when it is called with the value 9?
Answer: 5
4. What is the value returned from the following method when it is called with the value 5?
Answer: 32
5. What does the following method compute?
Answer: It returns true if the value of c is in the array x, otherwise it returns false. The variable b is
the size of the array x.
Answer: It searches an array for the value of c. It returns the array index if the value is found, -1 if it
is not found. The variable b is the size of the array x.
Multiple Choice (25) WARNING: CORRECT ANSWERS ARE IN THE SAME POSITION AND TAGGED
WITH **. YOU SHOULD RANDOMIZE THE LOCATION OF THE CORRECT ANSWERS IN YOUR EXAM.
2. The condition when a recursive method does not satisfy a base case it is called
a. infinite recursion **
b. finite recursion
c. iterative recursion
d. baseless recursion
3. When too many recursive calls are made creating more activation records than the allocated
program memory can handle, what kind of error occurs?
a. stack overflow **
b. activation record overflow
c. recursive overflow
d. infinite recursion
4. What happens when a recursive method does not reach the base case?
a. the program crashes
b. a stack overflow occurs
c. both a & b **
d. none of the above
6. Recursive methods
a. are useful when each recursive all is a solution to a smaller, identical problem **
b. do not use an if-statement
c. are not useful in programming
d. all of the above
8. What question should you keep in mind when debugging a recursive method?
a. Is there at least one recursive call?
b. Did you consider all possible cases?
c. Does the method contain a statement to test an input value and leads to different
cases?
d. All of the above. **
9. What question should you keep in mind when debugging a recursive method?
a. Does each base case produce a result that is correct for that case?
b. are there enough base cases?
c. Is at least one of the cases a base case that has no recursive call?
d. All of the above. **
10. What question should you keep in mind when debugging a recursive method?
a. If the method returns a value, does each of the cases return a value? **
b. Should a for-loop be included in the method?
c. Are the activation records correct?
d. All of the above.
13. To determine the efficiency of a recursive method you need to solve a(n)
a. recurrence relation **
b. recursive relation
c. quadratic equation
d. base case
16. The efficiency for solving the Towers of Hanoi problem recursively is
a. O(2n) **
b. O(n2)
c. O(n)
d. O(log n)
17. The rate of growth for the Towers of Hanoi problem as the number of disks increases is
a. exponential **
b. quadratic
c. linear
d. constant
18. When the last action in a recursive method is a recursive call, it is called
a. tail recursion **
b. final recursion
c. delayed recursion
d. latent recursion
19. When method X calls method Y, method Y calls method Z, and method Z calls method X, this is
called
a. indirect recursion **
b. mutual recursion
c. tail recursion
d. an error
20. When method X calls method Y, and method Y calls method X, this is called
a. mutual recursion **
b. tail recursion
c. associative recursion
d. an error
21. What is the output of the following program when the method is called with 4?
void unknown(int n)
{
System.out.print("?");
if (n > 0)
unknown(n-1);
}
a. ????? **
b. ????
c. ???
d. none of the above
22. What is the output of the following program when the method is called with 4?
void unknown(int n)
{
if (n > 0)
{
System.out.print("?");
unknown(n-1);
}
}
a. ???? **
b. ?????
c. ???
d. none of the above
23. What is the output of the following program when the method is called with 4?
void unknown(int n)
{
if (n > 0)
unknown(n-1);
System.out.print("?");
}
a. ????? **
b. ????
c. ???
d. none of the above
24. How many recursive calls will be made if the following method is called with 6?
void greeting(int n)
{
System.out.println("Hello!");
greeting(n-1);
}
a. infinitely **
b. 7
c. 6
d. 5
25. How many recursive calls will be made if the following method is called with 6?
void greeting(int n)
{
if (n > 0)
{
System.out.println("Hello!");
greeting(n+1);
}
}
a. infinitely **
b. 7
c. 6
d. 5
Another random document with
no related content on Scribd:
PELASTUS
Tiesi, tiesi äiti sen. Mutta hänen ajatuksensa olivat askarrelleet niin
kiihoittuneina suuren, raastavan surun ympärillä, että yksin suojeleva
äidintunnekin oli turtunut.
Ajatus oli juuri sillä hetkellä herännyt hänen mielessään, eikä hän
silloin ollut voinut aavistaakaan, kuinka äärettömän vaikeaksi sen
toteuttaminen kävisi. Mutta lupaus tai paremminkin vain pieni toivon
kipinä, jonka hän oli äidille antanut, se velvoitti. Se lepäsi kuin taakka
hartioilla hänen istuessaan päivillä pulpettinsa ääressä suuressa,
kumajavassa pankkihuoneessa. Samoin iltaisin kotona hänen
tehdessään puhtaaksikirjoitustyötä.
Niin, lainan hän kyllä uskaltaisi ottaa, jos vain saisi sellaisen. Se ei
tuntunut niinkään pelottavalta. Mutta ettei ollut ketään muuta kuin
tuomari Keihäs, jonka puoleen olisi saattanut kääntyä siinä asiassa,
se se pani epäröimään ja peräytymään viikko viikolta.
Oli tietysti paikkakunnalla montakin yhtä varakasta kuin tuomari,
ehkäpä varakkaampiakin. Mutta niiltä tiesi saavansa varman epuun,
aivan varman epuun jokaiselta. Kun oli nainen. Eikä ollut takaajia.
Ei, ei hän tungetellut. Itse hän oli heidän välinsä katkaissut. Pulaan
joutuneena, avun tarpeessa, kääntyi hän vain tuttavan puoleen,
jonka otaksui auttavan. Siinä se oli. Niin selvänä ja mutkatonna.
Auttakoon toinen sitten tai kieltäytyköön, se oli hänen asiansa.
— Siksi että… siksi että minulta vaadittiin jotakin muuta, jota olisi
aivan mahdoton toteuttaa…
— Hm… eihän se vain liene sama vaatimus, jonka aikoinaan
kerroit tehdyn Lainalle?
— Kuten ainakin.
Tuomari naurahti.
— Sinä siis tahdot ja uskallat antaa niin suuren lainan niin pienillä
takuilla — köyhälle tytölle?
Hän oli todellakin niin uskalias. Ja sitten — sitten oli vielä eräs
seikka, joka tuki hänen uskallustaan…
*****
*****
— Minä näin heti paikalla, ettei tässä talossa asiat olleet oikein…
Sellainen armeija keveitä suunpieksäjöitä miehesi ympärillä… Mutta
sinua itseäsi ei huomata edes oman kattosi alla! Miten voit kestää
sellaista, Toini?
— Minun.
Kului pitkä, hiljainen hetki, jonka kuluessa toinen luki, yhä vain luki,
ja toinen istui odotellen, pää käsien varassa.
— Usko tai et, ovat nämä koko joukon edellä Liisa Orvokin
runoista, joita miehesi arvostelijana on niin suuresti ylistänyt.
— Nauroivat —! Yhdessä —!
Hän astui Toinin luokse, kiersi kätensä hellivästi hänen
ympärillensä ja sanoi:
— Suostutko?
— Mihin sitten?
*****