NEW
Font size
WorksheetsCompuScholar Chapter 5
Total questions: 28
Worksheet time: 14mins
What shape would be drawn with this algorithm?
A triangle with side length 100
A five-sided star
A pentagon with side length 100
A rectangle with side length 500
How could you change this algorithm with parameters to draw any regular polygon with any side length?
I. Replace the 100 with a parameter for side length
II. Replace the 5 with a parameter for number of sides
III. Replace the 72 with 360 divided by parameter for number of sides
I and II
I, II, and III
This procedure should draw a square with side legth L, but it has a bug. How can you fix it?
Change the 90 to "get L"
Change the 50 to "get L"
Change the 4 to "get L"
Change the 90 and the 50 to "get L"
What code should be added to the procedure so that increment(x) adds x to the variable z?
Define a procedure named procTwoParams that multiplies its two parameters and assigns the result to the global variable Z.
Which code would successfully navigate the robot to the shaded square?
moveAndTurn(1, 2)
moveAndTurn(3, 5)
moveAndTurn(0, 3)
moveAndTurn(3, 1)
moveAndTurn(6, 3)
moveAndTurn(3, 1)
moveAndTurn(2, 1)
moveAndTurn(5, 1)
moveAndTurn(2, 1)
moveAndTurn(2, 1)
moveAndTurn(5, 3)
moveAndTurn(2,0)
Which is a procedure that would NOT take a parameter?
A procedure that greets your user by name
A procedure that draws a line segment of a certain length
A procedure that doubles a number
A procedure that resets all of your global variables to 0
You want to search this list for an 18, which search algorithm makes the most sense to use and why?
{3, 11, -3, 5, 0, 7, 18}
Binary Search, because it's the most efficient
Sequential Search, because the list is not in order
Bubble Sort, because the highest number rises to the top
Merge Sort, because it's more efficient than bubble sort
You have a suit of cards and you are looking for the Ace. In which scenario can you use binary search?
The cards are shuffled
The suit is hearts
The ace is on top
The suit is in numerical order
How many passes does Bubble Sort take to sort 16 items?
16 passes
4 passes
5 passes
13 passes
After one pass of the merge sort, what does this data look like?
{1, 5, 25, 4, 11, 3, 15, 16}
{1, 5}, {4, 25} {3, 11} {15, 16}
{1, 3} {4, 5} {11, 15} {16, 25}
{1, 5, 4, 11, 3, 15, 16, 25}
{1, 4, 5, 25} (3, 11, 15, 16}
After one pass of the bubble sort, what does this data look like?
{2, 6, 9, 4, 5, 1, 11}
{2, 6, 9, 4, 5, 1, 11}
{2, 6, 4, 5, 1, 9, 11}
{1, 2, 4, 5, 6, 9, 11}
{2, 6} {4, 9} {1, 5} {11}
What does it mean for a cipher to be a substitution cipher?
Encoding and decoding use the same key
The cipher is easy to for spies to decode
Each letter is replaced by a new letter in the cipher alphabet
It is impossible to decode unless you intercept the key
Encode "Hello" using a Caesar cipher shift of 3
lohel
khoor
ebiil
lipps
Define a function named hello(x) that concatenates the word 'hello' and the parameter x, with a space in between. For example hello("world") would result in "hello world".
Write a function, double(x), that doubles the value of its single argument.
What value does this function return?
The square root of its parameter, x
The parameter, x to the power of 2
Double the parameter, x
Nothing because you never intialized the global variable, x
What is the difference between a function and a procedure?
A function returns a value, but a procedure doesn't
A procedure can use parameters, but a function can't
Procedures can have user-defined names, but functions can't be named
You can put comments in a procedure, but you can't add comments to a function
Why can't a compiler tell you that you made a semantic error in your code?
A compiler only understands machine language
Compilers only look at executable files, not code
A semantic error is a mistake in logic and the compiler doesn't know what the programmer wanted to create
Compilers are specific to machines, like iPhones or PCs and so they can't find errors in all types of code
What would be the value of the global variable, result if this loop successfully runs?
Impossible to tell because you never initialized the global variable, number
5
120
1
For a list of 1000 numbers, at most how many guesses would it take using binary search to guess the secret number if after each guess you were told whether your guess was too high or too low or just right?
9
10
1000
500
For a list of 1000 numbers, at most how many guesses would it take using sequential search to guess the secret number?
9
10
500
1000
Which search algorithm takes log2(x) lookups to find a number in a list (worst case)?
binary
sequential
merge
bubble
To say that bucket sort is more efficient than bubble sort means that _________________.
No matter the list size, bucket sort always takes less time than bubble sort
Bucket sort is faster for long lists than bubble sort
Bucket sort requires fewer comparisons than bucket sort
There is no reason to ever use bubble sort
Which algorithm uses about N2 comparisons to sort a list of N elements?
Bucket
Merge
Bubble
Binary
Which algorithm uses about N log(N) comparisons to sort a list of N items?
Bucket
Bubble
Merge
Binary
What is an intractable problem?
One for which an algorithm doesn't exist to solve it
One which could be solved algorithmically but it would take too long to be practical
One which you could solve with a repetition algorithm
One which has no real-world application
Why would you use a heuristic algorithm?
You are too lazy to program a good algorithm
An approximate solution is good enough and the problem is intractable
You want the exact answer to an intractable problem
You want an approximate answer to an undecidable problem
