CS108L Spring 2014 Week 11: Quiz

advertisement
CS108L Spring 2014
Week 11: Quiz
1. What is algorithm analysis?
a)
b)
c)
d)
Asking the algorithm lots of questions to understand what it is doing.
Looking at the algorithm closely to understand what it is doing.
Looking at the input values that the algorithm needs.
****Develop an understanding of the characteristics of an algorithm for
different input parameters
2. What two factors are most important when analyzing an algorithm?
a)
b)
c)
d)
How much money it cost to write the software and where we can find it.
****How long the algorithm takes to run and the amount of memory it uses.
How difficult it is to use and the cost of the software.
How much input data is needed and the computer it can run on.
3. When you use a search algorithm you are looking for something in a group of
items. There are different algorithms that you can use to do this. What is a
Linear Search algorithm?
a) ****A Linear Search algorithm checks every element one at a time in
sequence, until the item you are looking for is found.
b) A Linear Search algorithm checks only the items in that line and ignores the
rest of the items in the group, that’s why it is linear!
c) A Linear Search algorithm draws a line and checks every item above that line.
d) A Linear Search algorithm checks some of the items in the group, the items
that are most likely the one you are looking for.
Document1
4. What does the following code do?
a)
b)
c)
d)
It prints “wow wow 1000”
It prints “wow 1000”
It prints “a green line with pen size 7”
****It prints “wow wow wow wow wow 1000”
5. In the code below, what does the word “other” do?
a) Nothing, it is redundant
b) ****The word ”other” removes the current turtle from the agentset of turtleshere.
c) The word “other” means opposite.
d) The word “other” is a typo for “mother”
Document1
6. Some agentset commands return an agentset, some modify an agentset and
some return Booleans. (Remember, a Boolean is a only has two possible “values”
like yes/no or true/false). In the code below(which is the same as question 5)
which agentset command returns a Boolean?
a.
b.
c.
d.
****any?, any? is called with “other turtles-here” as an argument
Other is a Boolean and turtles-here is an agentset
Turtles-here is true if there are any turtles on that patch
All the commands above are Booleans
7. A reporter returns a value, which can be a number. It essentially “turns into”
some value. For example, the reporter, multiply-two is defined as shown in
section A below. Then asking the turtles to Set size multiply-two 2 3,
would set the size of the turtle to 6. Given that information, what does line B do?
a.
b.
c.
d.
sets turtles to size 12
****shows a 12 in the command window
produces an error
redefines the reporter
Document1
8. Sometimes recursive processes are evident in the structure and patterns of
nature. Which of the following does not suggest recursive processes?
a. The structure of a fern
b. The patterns of small river leading to larger rivers in a river basin
c. ***The equilibrium between gravity and air resistance reached by a
freefalling body.
d. The organization of cells into tissues, tissues into organs and organs into
organisms.
9. The following code is an example of what type of procedure?
a)
b)
c)
d)
A very difficult procedure
A search procedure
****A recursive procedure
A sort procedure
Document1
10. Recursion stops or “bottoms out” when a certain test condition is met. In the
recursive program below which line contains the test condition?
a.
b.
c.
d.
e.
line 5
****line 2
line 1
line 8
line 10
Document1
Download