Data Structures and Abstractions with Java 4th Edition Carrano Test Bank download pdf
Data Structures and Abstractions with Java 4th Edition Carrano Test Bank download pdf
com
https://testbankfan.com/product/data-structures-and-
abstractions-with-java-4th-edition-carrano-test-bank/
OR CLICK HERE
DOWLOAD NOW
https://testbankfan.com/product/data-structures-and-abstractions-with-
java-4th-edition-carrano-solutions-manual/
testbankfan.com
https://testbankfan.com/product/data-structures-and-abstractions-with-
java-5th-edition-carrano-solutions-manual/
testbankfan.com
https://testbankfan.com/product/starting-out-with-java-from-control-
structures-through-data-structures-3rd-edition-gaddis-test-bank/
testbankfan.com
https://testbankfan.com/product/starting-out-with-c-from-control-
structures-to-objects-8th-edition-gaddis-solutions-manual/
testbankfan.com
Medical Surgical Nursing Concepts and Practice 2nd Edition
DeWit Test Bank
https://testbankfan.com/product/medical-surgical-nursing-concepts-and-
practice-2nd-edition-dewit-test-bank/
testbankfan.com
https://testbankfan.com/product/nutritional-foundations-and-clinical-
applications-5th-edition-grodner-test-bank/
testbankfan.com
https://testbankfan.com/product/principles-of-accounting-11th-edition-
needles-solutions-manual/
testbankfan.com
https://testbankfan.com/product/textbook-of-diagnostic-
microbiology-4th-edition-mahon-test-bank/
testbankfan.com
https://testbankfan.com/product/business-ethics-ethical-decision-
making-and-cases-11th-edition-ferrell-solutions-manual/
testbankfan.com
Business Communication Essentials A Skills Based Approach
8th Edition Bovee Solutions Manual
https://testbankfan.com/product/business-communication-essentials-a-
skills-based-approach-8th-edition-bovee-solutions-manual/
testbankfan.com
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
Other documents randomly have
different content
the sap, so as to secure it from the attacks of rodents, who too
frequently appropriate to themselves the food intended by plants for
other purposes. If you examine the tuber before the arum has
blossomed, you will find it large and solid; but if you dig it up in the
autumn after the seeds have ripened, you will see that it is flaccid
and drained; all its starches and other contents have gone to make
up the flower, the fruit, and the stalk which bore them. But the tuber
has a further protection against enemies besides its deep
underground position. It contains an acrid juice like that of the
leaves, which sufficiently guards it against four-footed depredators.
Man, however, that most persistent of persecutors, has found out a
way to separate the juice from the starch; and in St. Helena the big
white arum is cultivated as a food-plant, and yields the meal in
common use among the inhabitants.
When the arum has laid by enough starch to make a flower it begins
to send up a tall stalk, on the top of which grows the curious hooded
blossom known to be one of the earliest forms still surviving upon
earth. But now its object is to attract, not to repel, the animal world;
for it is an insect-fertilised flower, and it requires the aid of small flies
to carry the pollen from blossom to blossom. For this purpose it has
a purple sheath around its head of flowers and a tall spike on which
they are arranged in two clusters, the male blossoms above and the
female below. This spike is bright yellow in the cultivated species.
The fertilisation is one of the most interesting episodes in all nature,
but it would take too long to describe here in full. The flies go from
one arum to another, attracted by the colour, in search of pollen; and
the pistils, or female flowers, ripen first. Then the pollen falls from
the stamens or male flowers on the bodies of the flies, and dusts
them all over with yellow powder. The insects, when once they have
entered, are imprisoned until the pollen is ready to drop, by means
of several little hairs, pointing downwards, and preventing their exit
on the principle of an eel-trap or lobster-pot. But as soon as the
pollen is discharged the hairs wither away, and then the flies are free
to visit a second arum. Here they carry the fertilising dust with which
they are covered to the ripe pistils, and so enable them to set their
seed; but, instead of getting away again as soon as they have eaten
their fill, they are once more imprisoned by the lobster-pot hairs,
and dusted with a second dose of pollen, which they carry away in
turn to a third blossom.
As soon as the pistils have been impregnated, the fruits begin to set.
Here they are, on their tall spike, whose enclosing sheath has now
withered away, while the top is at this moment slowly dwindling, so
that only the cluster of berries at its base will finally remain. The
berries will swell and grow soft, till in autumn they become a
beautiful scarlet cluster of living coral. Then once more their object
will be to attract the animal world, this time in the shape of field-
mice, squirrels, and small birds; but with a more treacherous intent.
For though the berries are beautiful and palatable enough they are
deadly poison. The robins or small rodents which eat them, attracted
by their bright colours and pleasant taste, not only aid in dispersing
them, but also die after swallowing them, and become huge manure
heaps for the growth of the young plant. So the whole cycle of arum
existence begins afresh, and there is hardly a plant in the field
around me which has not a history as strange as this one.
IX.
This little chine, opening toward the sea through the blue lias cliffs,
has been worn to its present pretty gorge-like depth by the slow
action of its tiny stream—a mere thread of water in fine weather,
that trickles down its centre in a series of mossy cascades to the
shingly beach below. Its sides are overgrown by brambles and other
prickly brushwood, which form in places a matted and impenetrable
mass: for it is the habit of all plants protected by the defensive
armour of spines or thorns to cluster together in serried ranks,
through which cattle or other intrusive animals cannot break.
Amongst them, near the down above, I have just lighted upon a rare
plant for Southern Britain—a wild raspberry-bush in full fruit.
Raspberries are common enough in Scotland among heaps of stones
on the windiest hillsides; but the south of England is too warm and
sickly for their robust tastes, and they can only be found here in a
few bleak spots like the stony edges of this weather-beaten down
above the chine. The fruit itself is quite as good as the garden
variety, for cultivation has added little to the native virtues of the
raspberry. Good old Izaak Walton is not ashamed to quote a certain
quaint saying of one Dr. Boteler concerning strawberries, and so I
suppose I need not be afraid to quote it after him. 'Doubtless,' said
the Doctor, 'God could have made a better berry, but doubtless also
God never did.' Nevertheless, if you try the raspberry, picked fresh,
with plenty of good country cream, you must allow that it runs its
sister fruit a neck-and-neck race.
Yet the main object attained by all is in the end precisely similar.
Strawberries, raspberries, and blackberries all belong to the class of
attractive fruits. They survive in virtue of the attention paid to them
by birds and small animals. Just as the wild strawberry which I
picked in the hedgerow the other day procures the dispersion of its
hard and indigestible fruitlets by getting them eaten together with
the pulpy receptacle, so does the raspberry procure the dispersion of
its soft and sugary fruitlets by getting them eaten all by themselves.
While the strawberry fruitlets retain throughout their dry outer
coating, in those of the raspberry the external covering becomes
fleshy and red, but the inner seed has, notwithstanding, a still
harder shell than the tiny nuts of the strawberry. Now, this is the
secret of nine fruits out of ten. They are really nuts, which clothe
themselves in an outer tunic of sweet and beautifully coloured pulp.
The pulp, as it were, the plant gives in, as an inducement to the
friendly bird to swallow its seed; but the seed itself it protects by a
hard stone or shell, and often by poisonous or bitter juices within.
We see this arrangement very conspicuously in a plum, or still better
in a mango; though it is really just as evident in the raspberry,
where the smaller size renders it less conspicuous to human sight.
It is a curious fact about the rose family that they have a very
marked tendency to produce such fleshy fruits, instead of the mere
dry seed-vessels of ordinary plants, which are named fruits only by
botanical courtesy. For example, we owe to this single family the
peach, plum, apricot, cherry, damson, pear, apple, medlar, and
quince, all of them cultivated in gardens or orchards for their fruits.
The minor group known by the poetical name of Dryads, alone
supplies us with the strawberry, raspberry, blackberry, and dewberry.
Even the wilder kinds, refused as food by man, produce berries well
known to our winter birds—the haw, rose-hip, sloe, bird-cherry, and
rowan. On the other hand, the whole tribe numbers but a single
thoroughgoing nut—the almond; and even this nut, always
somewhat soft-shelled and inclined to pulpiness, has produced by a
'sport' the wholly fruit-like nectarine. The odd thing about the rose
tribe, however, is this: that the pulpy tendency shows itself in very
different parts among the various species. In the plum it is the outer
covering of the true fruit which grows soft and coloured: in the apple
it is a swollen mass of the fruit-stalk surrounding the ovules: in the
rose-hip it is the hollowed receptacle: and in the strawberry it is the
same receptacle, bulging out in the opposite direction. Such a
general tendency to display colour and collect sugary juices in so
many diverse parts may be compared to the general bulbous
tendency of the tiger-lily or the onion, and to the general succulent
tendency of the cactus or the house-leek. In each case, the plant
benefits by it in one form or another; and whichever form happens
to get the start in any particular instance is increased and developed
by natural selection, just as favourable varieties of fruits or flowers
are increased and developed in cultivated species by our own
gardeners.
DISTANT RELATIONS.
Behind the old mill, whose overshot wheel, backed by a wall thickly
covered with the young creeping fronds of hart's-tongue ferns, forms
such a picturesque foreground for the view of our little valley, the
mill-stream expands into a small shallow pond, overhung at its
edges by thick-set hazel-bushes and clambering honeysuckle. Of
course it is only dammed back by a mud wall, with sluices for the
miller's water-power; but it has a certain rustic simplicity of its own,
which makes it beautiful to our eyes for all that, in spite of its
utilitarian origin. At the bottom of this shallow pond you may now
see a miracle daily taking place, which but for its commonness we
should regard as an almost incredible marvel. You may there behold
evolution actually illustrating the transformation of life under your
very eyes: you may watch a low type of gill-breathing gristly-boned
fish developing into the highest form of lung-breathing terrestrial
amphibian. Nay, more—you may almost discover the earliest known
ancestor of the whole vertebrate kind, the first cousin of that once
famous ascidian larva, passing through all the upward stages of
existence which finally lead it to assume the shape of a relatively
perfect four-legged animal. For the pond is swarming with fat black
tadpoles, which are just at this moment losing their tails and
developing their legs, on the way to becoming fully formed frogs.
The tadpole and the ascidian larva divide between them the honour
of preserving for us in all its native simplicity the primitive aspect of
the vertebrate type. Beasts, birds, reptiles, and fishes have all
descended from an animal whose shape closely resembled that of
these wriggling little black creatures which dart up and down like
imps through the clear water, and raise a cloud of mud above their
heads each time that they bury themselves comfortably in the soft
mud of the bottom. But while the birds and beasts, on the one hand,
have gone on bettering themselves out of all knowledge, and while
the ascidian, on the other hand, in his adult form has dropped back
into an obscure and sedentary life—sans eyes, sans teeth, sans
taste, sans everything—the tadpole alone, at least during its early
days, remains true to the ancestral traditions of the vertebrate
family. When first it emerges from its egg it represents the very most
rudimentary animal with a backbone known to our scientific
teachers. It has a big hammer-looking head, and a set of branching
outside gills, and a short distinct body, and a long semi-transparent
tail. Its backbone is a mere gristly channel, in which lies its spinal
cord. As it grows, it resembles in every particular the ascidian larva,
with which, indeed, Kowalewsky and Professor Ray Lankester have
demonstrated its essential identity. But since a great many people
seem wrongly to imagine that Professor Lankester's opinion on this
matter is in some way at variance with Mr. Darwin's and Dr.
Haeckel's, it may be well to consider what the degeneracy of the
ascidian really means. The fact is, both larval forms—that of the frog
and that of the ascidian—completely agree in the position of their
brains, their gill-slits, their very rudimentary backbones, and their
spinal cords. Moreover, we ourselves and the tadpole agree with the
ascidian in a further most important point, which no invertebrate
animal shares with us; and that is that our eyes grow out of our
brains, instead of being part of our skin, as in insects and cuttle-fish.
This would seem à priori a most inconvenient place for an eye—
inside the brain; but then, as Professor Lankester cleverly suggests,
our common original ancestor, the very earliest vertebrate of all,
must have been a transparent creature, and therefore comparatively
indifferent as to the part of his body in which his eye happened to
be placed. In after ages, however, as vertebrates generally got to
have thicker skulls and tougher skins, the eye-bearing part of the
brain had to grow outward, and so reach the light on the surface of
the body: a thing which actually happens to all birds, beasts, and
reptiles in the course of their embryonic development. So that in this
respect the ascidian larva is nearer to the original type than the
tadpole or any other existing animal.
The ascidian, however, in mature life, has grown degraded and fallen
from his high estate, owing to his bad habit of rooting himself to a
rock and there settling down into a mere sedentary swallower of
passing morsels—a blind, handless, footless, and degenerate thing.
In his later shape he is but a sack fixed to a stone, and with all his
limbs and higher sense-organs so completely atrophied that only his
earlier history allows us to recognise him as a vertebrate by descent
at all. He is in fact a representative of retrogressive development.
The tadpole, on the contrary, goes on swimming about freely, and
keeping the use of its eyes, till at last a pair of hind legs and then a
pair of fore legs begin to bud out from its side, and its tail fades
away, and its gills disappear, and air-breathing lungs take their place,
and it boldly hops on shore a fully evolved tailless amphibian.
There is, however, one interesting question about these two larvæ
which I should much like to solve. The ascidian has only one eye
inside its useless brain, while the tadpole and all other vertebrates
have two from the very first. Now which of us most nearly
represents the old mud-loving vertebrate ancestor in this respect?
Have two original organs coalesced in the young ascidian, or has one
organ split up into a couple with the rest of the class? I think the
latter is the true supposition, and for this reason: In our heads, and
those of all vertebrates, there is a curious cross-connection between
the eyes and the brain, so that the right optic nerve goes to the left
side of the brain and the left optic nerve goes to the right side. In
higher animals, this 'decussation,' as anatomists call it, affects all the
sense-organs except those of smell; but in fishes it only affects the
eyes. Now, as the young ascidian has retained the ancestral position
of his almost useless eye so steadily, it is reasonable to suppose that
he has retained its other peculiarities as well. May we not conclude,
therefore, that the primitive vertebrate had only one brain-eye; but
that afterwards, as this brain-eye grew outward to the surface, it
split up into two, because of the elongated and flattened form of the
head in swimming animals, while its two halves still kept up a
memory of their former union in the cross-connection with the
opposite halves of the brain? If this be so, then we might suppose
that the other organs followed suit, so as to prevent confusion in the
brain between the two sides of the body; while the nose, which
stands in the centre of the face, was under no liability to such error,
and therefore still keeps up its primitive direct arrangement.
It is worth noting, too, that these tadpoles, like all other very low
vertebrates, are mud-haunters; and the most primitive among adult
vertebrates are still cartilaginous mud-fish. Not much is known
geologically about the predecessors of frogs; the tailless amphibians
are late arrivals upon earth, and it may seem curious, therefore, that
they should recall in so many ways the earliest ancestral type. The
reason doubtless is because they are so much given to larval
development. Some ancestors of theirs—primæval newts or
salamanders—must have gone on for countless centuries improving
themselves in their adult shape from age to age, yet bringing all
their young into the world from the egg, as mere mud-fish still, in
much the same state as their unimproved forefathers had done
millions of æons before. Similarly, caterpillars are still all but exact
patterns of the primæval insect, while butterflies are totally different
and far higher creatures. Thus, in spite of adult degeneracy in the
ascidian and adult progress in the frog, both tadpoles preserve for
us very nearly the original form of their earliest backboned ancestor.
Each individual recapitulates in its own person the whole history of
evolution in its race. This is a very lucky thing for biology; since
without these recapitulatory phases we could never have traced the
true lines of descent in many cases. It would be a real misfortune for
science if every frog had been born a typical amphibian, as some
tree-toads actually are, and if every insect had emerged a fully
formed adult, as some aphides very nearly do. Larvæ and embryos
show us the original types of each race; adults show us the total
amount of change produced by progressive or retrogressive
development.
XI.
SPECKLED TROUT.
The hedge and bank in Haye Lane are now a perfect tangled mass
of creeping plants, among which I have just picked out a queer little
three-cornered flower, hardly known even to village children, but
christened by our old herbalists 'dog's mercury.' It is an ancient trick
of language to call coarser or larger plants by the specific title of
some smaller or cultivated kind, with the addition of an animal's
name. Thus we have radish and horse-radish, chestnut and horse-
chestnut, rose and dog-rose, parsnip and cow-parsnip, thistle and
sow-thistle. On the same principle, a somewhat similar plant being
known as mercury, this perennial weed becomes dog's mercury.
Both, of course, go back to some imaginary medicinal virtue in the
herb which made it resemble the metal in the eyes of old-fashioned
practitioners.
The male and female flowers of dog's mercury have taken to living
upon separate plants. Why is this? Well, there was no doubt a time
when every blossom had both stamens and pistil, as dog-roses and
buttercups always have. But when the plant took to wind fertilisation
it underwent a change of structure. The stamens on some blossoms
became aborted, while the pistil became aborted on others. This was
necessary in order to prevent self-fertilisation; for otherwise the
pollen of each blossom, hanging out as it does to the wind, would
have been very liable to fall upon its own pistil. But the present
arrangement obviates any such contingency, by making one plant
bear all the male flowers and another plant all the female ones.
Why, again, are the petals green? I think because dog's mercury
would be positively injured by the visits of insects. It has no honey
to offer them, and if they came to it at all, they would only eat up
the pollen itself. Hence I suspect that those flowers among the
mercuries which showed any tendency to retain the original coloured
petals would soon get weeded out, because insects would eat up all
their pollen, thus preventing them from fertilising others; while those
which had green petals would never be noticed and so would be
permitted to fertilise one another after their new fashion. In fact,
when a blossom which has once depended upon insects for its
fertilisation is driven by circumstances to depend upon the wind, it
seems to derive a positive advantage from losing all those attractive
features by which its ancestors formerly allured the eyes of bees or
beetles.