Comp Sci Chapter 5 Review

Ace your homework & exams now with Quizwiz!

For searching a sorted list, which search algorithm is the better choice?

Binary search

A ____________ error occurs when a programmer inadvertently puts code that is syntactically correct, but does not do what the programmer intended it to do

semantic

For searching an unordered list, which search algorithm is the better choice?

sequential search

In computer programming, syntax is the __________ that determines whether statements are correctly formulated.

set of rules

A Caesar cipher is an example of a ______________________.

substitution cipher

A ____________ error occurs when a programming language's rules are broken. This type of error can be detected by the compiler which will provide an error message

syntax

1 point True or False: Semantic errors can be detected by the compiler.

false

True or false: All intractable problems (that cannot be solved in a reasonable time) are bad.

false

For which of the problems would the bubble sort algorithm provide an appropriate solution. Choose all that apply.

Arranging a deck of cards from the lowest to the highest value cards. Sorting a stack of paper money into denominations -- i.e., $1, $5, $10 etc. Arranging books on a bookshelf by author's last name.

Suppose you are sorting the following list of numbers in ascending order using bubble sort: [16, 5, -1, 4, 12, 17, 3, 10, 5, 9]. After the first pass through the numbers, what value would appear on the right of the list?

17

To guess a number between 1 and 100, what's the maximum number of guesses your algorithm would take?

7 guesses

To guess a number between 1 and 500, what's the maximum number of guesses your algorithm would take?

8 guesses

Which of the following characteristics is true of bubble sort?

A comparison-based algorithm An N2 algorithm.

Explain the difference between a function and a procedure. Give an example of a function.

A function is a variable that returns a value or result. An example of a function would be the encrypt and decrypt procedures in the app. A procedure entails the steps of telling the program/app what to do.

Give an example of a search problem you encounter in everyday life. Do it use sequential, binary, or some other search?

A search problem I encounter in my everyday life is trying to find someones phone number in my contacts. It uses binary search because the names are sorted alphabetically.

That article was written in 2012. Password cracking technology has probably gotten a lot better. Suppose the number of passwords that can be checked per second doubles every year, use the Password Strength Calculator to determine an optimal password scheme for the year 2020?

An optimal password scheme for the year 2020 would be 12 characters long. This would take more than 10 years to crack.

Bubble and Merge Sort are referred to as comparison sorts because the values of the two pieces of data are compared during each step. Why are the radix and bucket sort not comparison sorts?

Bucket source and radix are not comparison sorts because they do not actually compare the data, they just use calculations.

There are 32 students standing in a classroom. Two different algorithms are given for finding the average height of the students. Algorithm A Step 1: All students stand. Step 2: A randomly selected student writes his or her height on a card and is seated. Step 3: A randomly selected standing student adds his or her height to the value on the card, records the new value on the card, and is seated. The previous value on the card is erased. Step 4: Repeat step 3 until no students remain standing. Step 5: The sum on the card is divided by 32. The result is given to the teacher. Algorithm B Step 1: All students stand. Step 2: Each student is given a card. Each student writes his or her height on the card. Step 3: Standing students form random pairs at the same time. Each pair adds the numbers written on their cards and writes the result on one student's card; the other student is seated. The previous value on the card is erased. Step 4: Repeat step 3 until one student remains standing. Step 5: The sum on the last student's card is divided by 32. The result is given to the teacher.

C) Both Algorithm A and Algorithm B always calculate the correct average.

Under which of the following conditions is it most beneficial to use a heuristic approach to solve a problem?

C) When the problem cannot be solved in a reasonable time and an approximate solution is acceptable.

Encrypt the word alphabet using a Caesar cipher with a shift of 3.

DOSKDEHW

True or False: An algorithm can be found for any computational problem whatsoever.

False

For which of the problems would the binary search algorithm be useful?

Looking up a phone number in the phone book given the person's full (unique) name. Looking up a word in a dictionary. Arranging a deck of cards from the lowest to the highest value cards.

Which of the following characteristics is true of bucket sort?

More efficient than bubble sort. A linear algorithm

In talking about sorting algorithms in general, a sort algorithm's efficiency refers to ______________________.

how long it takes to arrange the values in order.

Your classmate discovers that their LightsOff app has a bug in it. What should he/she do to debug their app?

Form a hypothesis about what might be wrong, design an experiment to test their hypothesis, perform the experiment, debug, and then retest the app.

Explain the difference between global and local variables. Why are local variables easier to debug than global variables?

Global variables can be used in any procedure or event handler in the app. Local variables can only be used in the procedure in which it was defined in. Local variables are easier to debug than global variables because they are isolated in one part of code, and are defined in one procedure.

According to this 2012 article, a password-cracking computer can try 350 billion passwords per second. How would you have to modify your scheme to withstand a 10-year attack by this specially designed computer?

I would modify my password length to 11 characters. This would be able to stand a 10 year attack.

Is the following problem tractable (solvable in a reasonable amount of time) or intractable (cannot be solved in a reasonable amount of time)? For any length string of letters using any combination of the letters 'a' through 'z', write down all possible strings.

Intractable

For which of the problems could the sequential search algorithm be used?

Looking up a phone number in the phone book given the person's full (unique) name. Looking up a word in a dictionary. Looking up a person's name in the phone book given the person's phone number. Guessing a secret number between 1 and 100.

Define a pseudocode algorithm that will efficiently play the guessing game

Select a random number between 1 and 100. Get a guess from the user If the guess is too low say "Too Low" If the guess is too high say "Too High" If the user is correct say "Your guess is correct."

Which of the following are examples of semantic errors in App Inventor?

The PaintPot ButtonMinus.Click event adding 1 to dotsize. The PaintPot ButtonRed.Click setting the Canvas1.PaintColor to blue. Check Answer

Suppose you have a deck of cards and you want to find the Ace of Spades. If the deck is shuffled, which is the best search algorithm to use and why?

The best search algorithm to use would be sequential search because these cards are not sorted in any type of way; they are arranged randomly.

Which sort do you think would be the fastest if you had to sort more than one deck of cards? Why?

The fastest sort would be the bucket sort because you could compare two cards at a time, instead of just one.

For the routes starting and ending at Trinity College, identify the nearest neighbor route and the optimal route. What does this show you about the nearest neighbor heuristic?

The nearest neighbor route would be ACB. The nearest optimal route would also be ACB. This shows you that the nearest neighbor heuristic works only occasionally; not always.

A password scheme consists of a minimum password length and the different types of symbols (i.e., letters, numbers, specials) that can be used in the password. Using the Password Strength Calculator, determine the optimal scheme for withstanding a brute force attack of at least 10 years by an ordinary PC performing 100 million tests per second.

The optimal scheme for withstanding a brute force attack would be 9, and this would take 10 years by an ordinary PC.

A cipher is _________________________.

an algorithm that is used to scramble text so that it can be passed in secret

The Halting Problemis an example of

an undecidable problem

Suppose you are sorting the following list of words in alphabetical order using bubble sort: [apple, banana, lemon, tomato, orange, squash, papaya, pumpkin]. Which of the following gives the correct order of the list after two passes through the list?

apple, banana, lemon, orange, papaya, pumpkin, squash, tomato]

To say that bucket sort is more efficient than bubble sort means that _________________.

as the size of the list grows, bucket sort will be faster than bubble sort.

The function shown in this graph is known as the base-2 logarithm function, y = log2(x). Which search algorithm behaves like this function?

binary search

The following word was encrypted using a Caesar cipher with a shift of 2: ecguct. What word is it?

caesar

Suppose you are sorting the following list of words into alphabetical order using bubble sort: [apple, orange, banana, papaya, lemon, pumpkin, squash, tomato]. After the first pass through the list, what word would appear on the right of the list?

tomato

or False: In computer programming, a bug is an error or defect that prevents the app from working the way it is supposed to

true


Related study sets

Criminal Law - Strict Liability Offenses

View Set

Food AS - Conditions and factors for the growth of bacteria

View Set