Algorithms Part 2

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Which of the following reasons would justify the use of a heuristic?

She has to leave in an hour.

What should be put into box 1 and box 2 to complete this algorithm for sorting a list from smallest to largest?

(Box 1): find smallest element in list between index and end of list (Box 2): swap smallest element with element at index

However, the programmer tested the procedure using other data sets and discovered that it did not always return the correct answer. Which of the following data sets would produce invalid results, proving that the procedure is not working correctly for all inputs?

1) nums <-- [ 6, 2, 3, 5, 8, 9 ] 2) nums <-- [ 4, 3, 3, 4, 8 ]

Which of the following statements is TRUE?

Algorithm 1 requires the list be already sorted. Algorithm 2 will always work.

For which of the following lists will Kaylie's algorithm work?

Both A and C.

Which of the following statements would prove to the programmer that the code is not always working because it displays the WRONG result?

DISPLAY ( factors (7) )

Finding the shortest distance between two nodes is which type of problem?

Decidable.

Which of the following correctly explains how to handle this problem and other problems with an unreasonable solve time?

I and III only.

The following code segment below was written to display the number of elements, total, and the average of all the elements in a list called numList. 1 total ← 0 2 sum ← 0 3 FOR EACH element IN numList 4 { 5 total ← total + 1 6 sum ← sum + element 7 avg ← sum/total 8 } 9 DISPLAY (avg) Which of the following changes will maintain the accuracy of the program while reducing the number of operations that are performed when the program is run?

Move line 7 outside of the FOR EACH loop.

Efficiency is normally a concern when developing a program. Three of the following modifications would make the procedure more efficient, so that it would run faster relative to this original code. Which of the following modifications would NOT improve its efficiency?

Replace lines 32, 36, and 40 with the following code: result <-- result + 0

After the code is run, what is calculated?

The code is counting the number of odd numbers between 0 and y.

In order to test the program, arrNum is initialized to [−2,0,5,8]. The program displays 11. Which of the following statements is true?

The program does not work as intended. Using [−2,0,5,8] as the test is not sufficient to assume the program is correct.

A programmer is working on a problem that requires an algorithm to solve. She writes an algorithm that works for one example, but doesn't work for another example. What type of problem is this?

Undecidable (4)

Brandon is writing a program that allows users to keep a database of recipes. Each recipe includes a name, a list of ingredients, and instructions. He is currently writing the search procedure that will allow users to find recipes in the database by looking up ingredients. Brandon realizes that if there are too many recipes in the database, searching for one will be very difficult. Which of the following describes a heuristic approach to solving this issue?

1) The procedure could start by checking the recipes that have been searched for recently. 2) The procedure could start by checking the recipes that the user normally searches for at that time of day.

Algorithms can have runtimes that are either reasonable or unreasonable. Let's assume that n represents the number of input items that have to be considered and f(n) represents the number of things that the computer must do to solve the problem for n number of inputs. Which of the following represents an unreasonable run time?

1) f(n)=3n 2) f(n)=n!

What is this algorithm an example of?

A heuristic.

Consider the following algorithms. Assume that you have a deck of cards with numbers on them and you are looking for a card with a particular number: Which of the following statements is TRUE? Elimina

Algorithm 1 is an example of binary search. For it to work, the list must already be sorted. Algorithm 2 is an example of linear search. It will work for any list.

Which of the following statements is true?

Algorithm 2 always calculates the correct average, but Algorithm 1 only does some of the time.

What method would be the best way to search for item in the list below?

Linear search because a linear search can be used to search any list.

Using this definition of efficiency, which of the following code segments is the MOST efficient?

FOR EACH prevName IN prevYearStudents { i <-- 1 REPEAT UNTIL ( i > LENGTH (currYearStudents) ) { IF ( prevName = currYearStudents[i] ) { DISPLAY ( prevName ) i = LENGTH (currYearStudents) } i <-- i + 1 } }

Consider the following lists. For which of the following lists would a binary search be more efficient than a linear search?

II only.

What one change can Kaylie make that will allow this program to work for all lists?

In Step 1, initialize max to the first element's value.

Which of the following is NOT an example of a heuristic?

Martha is instructed to inventory all of the items in three aisles of a grocery store. She counts everything item by item and writes down the totals.

Eric reads an article about a problem in computer science. He reads that there is an algorithm to solve the problem, but the algorithm only works for some of the possible inputs. It's been proven that there is no algorithm that works for the other inputs. What kind of problem is Eric reading about?

Undecidable. (1)

The Entscheidungsproblem was a problem posed by David Hibert. The Entscheidungsproblem looks for an algorithm that will determine if any mathematical statement is provable from known axioms. The problem looks for a simple "yes" or "no" answer, however, just eight years after the problem was posed it was proved that there is no one algorithm that can be constructed that always lead to a correct "yes" or "no" answer. What do we call these types of problems?

Undecidable. (2)

Stan is working on a procedure that takes an integer as an input and returns true or false depending on certain criteria. He tests his procedure with a variety of inputs and notices that his algorithm only gives the correct answer when the input is negative or zero. He cannot come up with an algorithm that works for all integers. What kind of problem does Stan have?

Undecidable. (3)

In order to determine whether code can run in a reasonable amount of time, it is important to get a feel for the runtimes of different code segments. Let's assume that runtime is measured as the number of passes through a loop. In the following choices, this is represented by the variable count. Assume that every element in the list named licenses is a unique license number, and that searchNum is a valid license number that exists in licenses. Which of the following segments of code would generally have the shortest runtime according to this definition of runtime?

count <-- 0 i <-- 0 REPEAT UNTIL ( licenses[i] = searchNum ) { count <-- count + 1 i <-- i + 1 }

Let's define runtime as the number of times the code reaches Line 6. Assume that c represents the number of elements in currLicenses and p represents the number of elements in prevLicenses. Of the following, which is the best approximation of runtime for the algorithm represented by this code?

c∗p


संबंधित स्टडी सेट्स

Study Guide Chapter 1.10 (Content and Analysis)

View Set

Chapter 20 section 4 - The Columbian Exchange and Global Trade

View Set

ECON 2105: CHAPTER 10 [MEASURING A NATION'S INCOME]

View Set

Therapeutic Modalities & Non-Systems review for NPTE

View Set

extra help of Accounting study guide of ch 1, 2, & 3

View Set

Chapter 8: Big Data, Data Warehouses, and Business Intelligence Systems

View Set