Alg

Ace your homework & exams now with Quizwiz!

A salesperson is given a list of cities and the distances between them. The salesperson has to visit each city exactly once and then return to the first city. What is the shortest possible route the salesperson could take? To find the exact answer, a computer program would have to create every possible route, calculate the lengths of all of them, and then to find the shortest route. This clearly isn't efficient when there are many cities the salesperson must visit. Alternatively, a computer could use this algorithm: 1. Select a city to start. 2. Select the closest unvisited city. 3. Repeat step 2 until all cities have been visited. 4. Return to first city. This algorithm won't always return the shortest route, but the route it returns can be considered "short enough". What is this algorithm an example of? a) An abstraction b) A heuristic c) An unsolvable problem d) An unreasonable problem

Choice 'B' is correct.

The Manhattan distance is often used when talking about how many city blocks two locations are from one another. If you are in a city with only north/south streets and east/west streets and trying to get to a location that is less than 10 miles east and 2 miles north, then which of the following paths will NOT get you to the destination? a) Going north 2 miles, then east 10 miles. b) Going north 3 miles, then east 10 miles, then south 1 mile. c) Going 1 mile north, then 1 mile east twice, then 9 miles east. d) Going 1 mile east 3 times, then 1 mile north 3 times, then 7 miles east, then 1 mile south.

Choice 'C' is correct.

Emergency rooms use a triage procedure to emit patients based on need. The process involves a nurse asking several direct questions to determine which people need to be helped quickly. What term in computer science best describes this process? a) Diagnosis b) Documentation c) Machine learning d) Heuristic

Choice 'D' is correct. The triage process allows the hospital to quickly collect information about a situation and make a judgement about what is most likely needed. Formal medical diagnosis is much slower and can often be an unsolvable problem. The triage process is not 100% accurate, but provides a 'shortcut that allows them to react quickly. This is the same mechanism as a heuristic.

When determining the efficiency of an algorithm you must consider which of the following things? Select TWO answers. a) How long the program takes to run b) The amount of storage the program requires c) How many lines of code the program has d) The platforms on which the program can run

Choices 'A' and 'B' are the correct answers. Efficiency of an algorithm includes both execution time and memory usage.

Which of the following statements are TRUE? Select TWO answers. a) Every programming problem can be solved. b) Approximate solutions can be used when a problem takes too long to solve. c) A heuristic should only be used to solve a problem if an approximate solution is acceptable d) Heuristics are always helpful.

B and C are correct

Aaban and Manha are trying to simplify the following mathematical expression: 11 - 6/2 * 3 + 1 They are debating if they should start with the subtraction, division, multiplication, or addition operation. The discussion they are having is about which of the following issues? a) Sequencing b) Selection c) Iteration d) Distributive property

Choice 'A' is the correct answer, Aaban and Manha are discussing the order in which the operations should be carried out, which is sequencing,

Which of the following statements is the most true concerning general programming languages? a) Most general programming languages are comparable when it comes to being able to express an algorithm. b) General programming languages are typically developed to solve specific problems in certain domains or areas. C) By definition, all general programming languages use the same syntax. d) The same algorithm implemented in two different general programming languages will have nearly identical run times.

Choice 'A' is the correct answer. Nearly all general programming languages are similar in the fact that they can be used to express an algorithm. Each language may be able to express the algorithm in different ways, but at least the algorithm can be expressed.

Which of the following BEST help people understand the concept of an algorithm? Select TWO answers. a) Visual programming languages b) Pseudocode c) Natural language d) Textual programming languages

Choice 'B' and Choice 'C' are the correct answers. Pseudocode and natural language are designed to help people understand algorithms. However, a computer cannot understand either one

Consider the code below: numbers < [12, 17, 15, 72, 3] big < 0 FOR EACH number IN numbers { IF(number>15) big < big +10 ELSE big < big - 10 } display (big) Line 3 is best described as: a) Sequencing b) Selection c) Iteration d) Algorithm

C is correct

You observe that function, when given an input of 2 returns an output of 4. An input of 4 returns and output of 16. Which of the following are possible mathematical representations of this function? Select TWO answers, a) a(x) = 2x b) b(x) = 2^x c) c(x) = x^2 d) d(x)= 4/x

Choices 'B' and 'C' are the correct answers. Check the PDF for more explanation.

Most of Monica's stuffed animals are worth a few dollars, but some are worth more. She decides to only sell the stuffed animals that are worth more than $7.00. She goes through the list she created of all the stuffed animals and their prices. If one is worth more than $7.00, she highlights it. Which of the following are part of Monica's algorithm? a) Iteration only b) Selection only c) Iteration and selection d) None of these

Once again, Monica needs to look through every item in a list. This is iteration. This time, however, she is picking items based on a certain criteria. This is selection. Thus, Choice 'C' is correct

Consider the following pseudocode. counter < 5 Total < 1 REPEAT counter TIMES total< total + 2 DISPLAY total Which of these best describes the results of running the code below? a)The number 10 is displayed. b) The number 11 is displayed. c) The number 13 is displayed. d) The number 32 is displayed.

B is the correct answer

What method would be the best way to search for an item in the list below? (6, 2, 1, 0, 3, 19, 201, 33, 17) a) Linear search because a linear search can only be used to search a sorted list. b) Linear search because a linear search can be used to search any list. c) Binary search because a binary search can be used to search a sorted list. d) Binary search because a binary search can be used to search any list.

B is correct

Alex has written code implementing a prey-predator relationship. He has coded a class from the sharks (predator), the fish (prey), and a graphical view to show these creatures on a grid moving about in an ocean of blue. Though the code appears to work correctly, Alex finds that the implementation is terribly slow. If he has more than 25 or so creatures in his ocean, the computer slows to a crawl and it takes hours to run his simulation. He would like to have the simulation running with thousands of creatures in the ocean. What should you recommend to Alex to improve the implementation of his simulation? Select TWO answers. a) Consider implementing his code in a different language - some languages are better suited to running simulations with a large number of objects than others. b) Consider choosing a different problem - the ocean is too big a place to create a simulation on a modern computer. c) Consider his graphical implementation - perhaps there is a way to speed up the graphs he has paired with simulation. d) Consider adding a plankton class for the fish to consume - perhaps adding a layer of complexity will give insight into the fish-shark relationship.

Choice 'A' and Choice 'C' are the correct answers. Some languages are ill-suited to certain problems. It is possible that Alex is implementing his algorithm in a graphical language that is designed to handle showing only a small number of objects on the screen. He could consider a different programming language, or simplifying the graphical implementation

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 proved that there is no algorithm that works for the other inputs. What kind of problem is Eric reading about? a) Undecidable b) Unreasonable c) Unsolvable d) Undetermined

Choice 'A' is the correct answer. An undecidable problem is one for which a single algorithm cannot be created to always lead to a yes or no answer. The problem that Eric is studying fits this description perfectly; an algorithm works for some of the possible inputs, but for others there is not an algorithm that can be used to reach a decision.

Consider the following lists. 1. list1 [2,4,5,7, 11,33] 11. list2 [-2,-1,0, 1, 2, 3, 4, 5, ..., 900, 901, 902] III. list3[-12,4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30,0] For which of the following lists would a binary search be more efficient than a linear search? a) II only b) III only c) II and III only d) I, II, and III

Choice 'A' is the correct answer. Binary searches are used to search through sorted lists. The efficiency of the binary search increases as the size of the list increases. Therefore, the only list that is both large and sorted is list2.

A salesperson is given a list of cities and the distances between them. The salesperson has to visit each city exactly once and then return to the first city. What is the shortest possible route the salesperson could take? Assume an actual salesperson is trying to determine the shortest route she can take to visit 18 cities. She could use a computer program to calculate the distance of every possible route and then select the shortest one. Alternatively, she could use a heuristic to find a route. Which of the following reasons would justify the use of a heuristic? a) She has to pay for her own gas. b) She has to leave in an hour. c) She could potentially get a raise for being more efficient on her sales route than her coworkers. d) She doesn't want to put too many miles on her car.

Choice 'B' is correct. A heuristic is a shortcut that leads to an approximate solution, and in this scenario, the salesperson can accept an approximate solution. Her only concern is leaving quickly, so a shortcut to find the route would be ideal.

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? a) Unreasonable b) Undecidable c) Unfixable d) Undefined

Choice 'B' is correct. An undecidable problem is one for which there is no algorithm that results in a yes-or-no answer for every possible input. Since Stan cannot come up with an algorithm that always produces a yes or a no, his problem is undecidable.

Chandler realizes that this program might be useful for people who have collections of things other than stuffed animals. When he writes his program, he leaves out details about stuffed animals and opts for more general terms. For example, instead of including "type of animal", "type of fur", "name" in the list of information, he opts for "name", "year", and "description". Which of the following computing concepts is Chandler using when he does this? a) Sequencing b) Abstraction c) Algorithms d) Efficiency Testing

Choice 'B' is correct. Chandler is removing details from the problem to make his program more functional. By removing specifics about stuffed animals, his program can now be used by people organizing collections of coins, art, antiques, or other items.

Monica realizes there is probably a big market for a program that could help users organize a stuffed animal collection. She envisions a program that will essentially be a list of lists. Each stuffed animal will have a list of information (year made, value, condition, etc.) and those lists will be stored in a master list called masterList. Monica writes the following algorithm for the "pickToSell" procedure: The procedure will sort masterList according to the value of the stuffed animals (most valuable to least valuable). Then the procedure will ask the user for a desired value. The procedure will print out the names of the stuffed animals that have a value greater than the desired value. Rachel and Chandler will each create a version of this program. Rachel plans to use Python to implement the program and Chandler is going to use Java. Which of the following statements are true? Select TWO answers. a) Monica's algorithm will be more helpful for Chandler than Rachel b) Rachel and Chandler will have to use iteration, selection, and sequencing to execute this algorithm. c) It's important that Monica's algorithm is clear and readable. d) The algorithm that Monica wrote can be implemented on a computer as is.

Choice 'B' is correct. The algorithm that Monica described involves putting a list in order (sequencing), going through each item in that list (iteration) and picking items that match a certain criteria (selection). Choice 'C' is also correct. Since Monica is telling Chandler and Rachel what she wants the program to do, she will need to be very clear and make sure her algorithm is readable.

Consider the code below: numbers < [12, 17, 15, 72, 3] big < 0 FOR EACH number IN numbers { IF(number>15) big < big +10 ELSE big < big - 10 } display (big) Line 5 is BEST described as: a) sequencing b) selection c) iteration d) algorithm

Choice 'B' is the correct answer. Selection refers to a boolean expression that is used to determine which subsequent operations are to be carried out. As line 5 is a boolean expression telling us which numbers to select.

Consider the following code: a< RANDOM(1,10) If (a>5){ REPEAT a TIMES{ DISPLAY('you win!') } Which line of the code above includes a Boolean expression? a) Line 1 b) Line 2 c) Line 3 d) Line 4

Choice 'B' is the correct answer. A Boolean expression is an expression that evaluates to True or False. Line 2: Has a Boolean condition, (a > 5), which is used to determine which part of the code will be executed.

12. In data compression, there are many different methods for compressing data. We have many different protocols because there is no one method that provides the absolute best compression for all files in a reasonable amount of time. Which of the following is the BEST term for the above example? a) An algorithm b) A heuristic c) A selection d) An iteration

Choice 'B' is the correct answer. The definition of a heuristic is a technique that allows the user to find an approximate answer in a reasonable amount of time. We use heuristic algorithms when problems cannot be solved in a reasonable time and they do not have an exact answer

The following procedure was written to implement an algorithm whose purpose is to return the sum of all the even numbers in a list. This code will regularly be used by a company and possibly modified in the future. PROCEDURE SumEm (numlist) { s<0 FOR EACH num in numlist { IF (num MOD 2 = 0) { S<S + num } } RETURN S } From a programmer's perspective, it would make sense to make a few improvements to this code. Which of the following is the LEAST needed improvement in order to add clarity to this code? a) Change the name of the procedure from sumEm to sumEvenNumbers b) Change the name of the element from num to evenOrOddPositiveNumber ; c) Change the name of variables to sum d) Add comments to describe the purpose of this procedure and explain its parameter

Choice 'B' is the correct answer. The name of the element is num which is short but descriptive enough in this case, evenOrOddPositiveNumber is much too long a name for a variable because it would be time consuming and error prone to retype each time you need to use it in the code.

By using a password that contains a mixture of 8 letters and numbers, a hacker could crack your password in a little over 16 minutes. However, by adding two more letters or numbers, it increases the time to about 15 days! By adding the @ symbol to your password, the time is increased to almost 1628 years! Which of the following is TRUE regarding passwords and the length of time it takes to crack them? a) As you increase the number of characters in your password the ability to crack the password is solvable. b) As you increase the number of characters in your password the ability to crack the password is unsolvable. c) As you increase the number of characters in your password the ability to crack the password becomes more unreasonable to solve. d) As you increase the number of characters in your password the ability to crack the password becomes more reasonable to solve.

Choice 'C' is correct

The game of tic-tac-toe has long been explored by computer scientists. The game has a small finite list of permutations, but does not contain an algorithm for guaranteed victory. How might you describe the algorithm used by Al to play the game? a) Computer because a win state is always possible. b) Incomplete because a win state cannot always be obtained. c) Decidable because the algorithm can always answer whether or not the game is winnable given the state of the board. d) Undecidable because of the possibilities of ties.

Choice 'C' is correct The ability for the game to end in three different possibilities is important to consider. The wording of Choice 'C' phrases it as winnable or not. This forces the algorithm to have two choices "win" vs "not win". Due to the finite number of choices, the algorithm can determine whether the game is still winnable on any given turn. This makes it decidable.

Rowan is playing an app on his phone based on the game 20 questions. The app asks the user to think of something and then asks 20 yes/no questions to determine the thing. Rowan has played 10 times in a row where the phone was able to guess the item. Which of the following is the best answer to should the app be thought of as decidable? a) Yes, it got the solution 10 times in a row b) Yes, twenty yes/no questions allow for a very large data set of solutions. c) No, a decidable program must cover all solutions and 10 trials is not enough. d) No, a decidable program can only accept one input and cannot be applied to twenty inputs.

Choice 'C' is correct. A decidable problem should be able to answer yes or no for all inputs. The sample of 10 runs of the app is not enough to guarantee that it will work for all inputs. An undecidable may still work for some inputs and the 10 trial runs may be outliers that are covered under the vast set of possibilities the app has been designed for.

Which of the following is NOT an example of a heuristic? a) Meredith estimates that each floor tile is 10 inches by 10 inches. She counts floor tiles to determine the size of a room. b) Avaya begins reading a positive, well written review for a product online. Based on the quality of the writing, she assumes that the product must be good without reading the rest of the review. c) 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. d) Sarah, a college junior, goes to the campus center to give a tour to a high school student. She sees a crowd of people and assumes that the person wearing the high school letter jacket is the prospective student.

Choice 'C' is correct. In this scenario, Martha must count every item in three aisles of a grocery store. There is no shortcut and she gets an exact answer, not an approximate one. A heuristic can be described as a shortcut that leads to an approximate answer, so this choice is not a heuristic.

Pierre de Fermat was a French lawyer who practiced mathematics as an amateur. He was famous for challenging some of the greatest mathematical minds of his time to solve problems that he created. Generally considered one of the key pioneers in analytical geometry, probability, and optics. However, he may be most famous for a note he left in the margin of a book where he claimed that a^n+ b^n does not equal c^n For any power over 2. Fermat's Last Theorem confounded mathematicians for centuries because they could not provide it to be correct or incorrect. In the year 1994; approximately 300 years after he posed the statement a mathematician from Princeton was about to prove that it was correct for all values n > 2. A textbook from 1980 might describe the problem as which of the following? a) Decidable, because a solution was certain but had not been written down yet. b) Decidable, 200 years had offered time for some numbers to be tested correct. c) Undecidable, no algorithm had been determined to work for all inputs. d) Undecidable, computers were too simple to test many cases at the time

Choice 'C' is correct." The full solution was discovered in 1994, so in the year 1980 the problem would have been thought of as incomplete. Without an algorithm to solve the problem, the theorem would have been considered undecidable.

A programmer wrote the following segment of code to find the lowest test score in a list of test scores. Note that there is at least one test score. Line 15. min 999 Line 2: FOR EACH score IN testScores Line 3: { Line 4: IF (score < min) Line 5: { Line 6: min & score Line 7: } Line 8: } Line 9: DISPLAY (min) Now the programmer has been asked to write some code to find the maximum test score from a list of test scores, so she uses the previous code as a starting point. The first thing that the programmer does is change the variable name from min to max everywhere it is referenced in the code. What else needs to be changed in order to find the maximum test score from the list? 1. Replace Line 1 with the following: max < -1. II. Replace Line 4 with the following: IF (score > max) III. Replace Line 6 with the following: score & max a) I only b). II only c) Both I and II d) Both II and III

Choice 'C' is the correct answer

Algorithms need to run in a "reasonable" amount of time in order to be considered practically useful. Which of the following BEST describes how programmers determine if an algorithm takes a reasonable amount of time? a) Programmers time how long it takes a program to execute using multiple inputs. An average time is calculated after several trials. b) Programmers count the number of lines of code in an algorithm. c) Programmers count the number of steps an algorithm takes and compare that number to a polynomial function of the size of the input. d) Programmers run a standard base algorithm at the same time as their algorithm and note which one finishes executing first.

Choice 'C' is the correct answer Run time is determined by first counting the number of steps an algorithm takes and then comparing that number to a polynomial function of the size of the input, as described in Choice 'C.

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: Algorithm 1: 1. look at the middle card in your deck. 2. if correct, done! You have found what you are searching for! 3. if you are looking for a larger number, discard the lower half of the deck 4. else, discard the upper half of the deck 5. return to step 1 Algorithm 2: 1. look at the first card in your deck. 2. if this is what you are looking for, great! You have found what you are searching for! 3. discard the first card in your deck 4. return to step 1 Which of the following statements is TRUE? a) Both algorithms will find the value you are looking for in any list. b) Neither algorithm will find the value that you are looking for in any list. c) Algorithm 1 requires the list be already sorted. Algorithm 2 will always work. d) Algorithm 2 requires the list be already sorted. Algorithm 1 will always work.

Choice 'C' is the correct answer.

Assume you have note cards with 20 student names on them. You want to sort them, and your friends suggest two different methods of sorting the cards. Alice suggests the following: - Put all the cards on the table - Find the one which is first in alphabetical order, and place it in a pile Find the next one in alphabetical order, and place it in the pile. Repeat until done. Elizabeth suggests: - Put one card on the table. - Look at the next card. - Place it in front of or behind the first card based on alphabetical order. - Look at the card. - Place it alphabetically in the correct location relative to the cards currently on the table. - Repeat until done. Which of the following best describes the situation outlined above? a) Alice has a more efficient algorithm for sorting the names. b) Elizabeth's algorithm is the most efficient sorting algorithm ever designed. c) Either Elizabeth's or Alice's algorithm could be used to sort the names. d) This is an example of combining the algorithms suggested to create a better solution to the problem.

Choice 'C' is the correct answer. Multiple algorithms can be used to solve the same problem.

Which of the following BEST provides what the purpose of a heuristic in programming? a) To provide an answer to a problem that can be solved in a reasonable time and an approximate solution is acceptable. b) To provide an answer to a problem that can be solved in a reasonable time and an exact solution is needed. c) To provide an answer to a problem that cannot be solved in a reasonable time and an approximate solution is acceptable. d) To provide an answer to a problem that cannot be solved in a reasonable time and an exact solution is needed.

Choice 'C' is the correct answer. The definition of a heuristic is a technique that allows the user to find an approximate answer in a reasonable amount of time. We use heuristic algorithms when problems cannot be solved in a reasonable time and they do not have an exact answer.

The Entscheidungs problem was a problem posed by David Hibert. The Entscheidungs problem 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? a) Unpredictable b) Unsolvable c) Unreasonable d) Undecidable

Choice 'D' is the correct answer. The definition of an undecidable problem is that we can write an algorithm that will run in some instances, but will not always lead to a correct "yes" or "no" answer

The following quotes are from Wikipedia regarding different computer languages. Given the following information, which would you likely recommend to a precocious 6th grader who wants an introduction to computer programming? Select TWO answers. A.) Java: "Java is a general-purpose computer programming language that is concurrent, class-based, object-oriented, ...It is intended to let application developers 'write once, run anywhere' B.) Alice: "Alice uses a drag and drop environment to create computer animations using 3D models." C.) Scratch: "Scratch is a visual programming language...[It can be used to create games and provide a stepping stone to the more advanced world of computer programming." D.) Python: "Python is a widely used general-purpose, high-level programming language. Its design philosophy emphasizes code readability. The language provides constructs intended to enable clear programs on both a small and large scale."

Choices 'B' and 'C' are the correct answers. Different computer languages are better suited to different tasks. Visual, drag-and-drop style languages are better suited than general purpose text-based languages for younger students.

Which of the following could be used if you want a computer to implement an algorithm that you have created? Select TWO answers. a) Natural language. b) Pseudocode c) Visual programming language d) Textual programming language

Choices 'C' and 'D' are the correct answers. Textual programming languages, such as Java and Python, or a graphical programming language, such as SNAP or Scratch, are required if you want a computer to carry out the algorithm you are considering,

Which of the following are true statements about run time? Select TWO answers. a) There is always a way to solve a problem in a reasonable amount of time. b) Reasonable run time is determined by counting the number of steps an algorithm takes to solve a problem. c) Two algorithms can solve the same problem using very different run times. d) Reasonable run time can be defined by individuals writing or using a program, and thus might vary from person to person.

Programmers determine whether or not a runtime is "reasonable" by counting the number of steps an algorithm takes to solve a problem. This makes Choice 'B' correct. Choice 'C' is also correct; it is possible for two programmers to solve a problem using different algorithms, and it's possible for those algorithms to vary in the number of steps.

Organizing Monica wants to sell her stuffed animal collection online. Her plan is to organize them alphabetically, then use the Internet to look up the value of each stuffed animal one by one. She'll put the data in a spreadsheet which will be organized alphabetically. Which of the following are part of Monica's algorithm? a) Only sequencing b) Only iteration c) Sequencing and selection d) Sequencing and iteration

The first part of Monica's algorithm requires sorting or sequencing the stuffed animals. She must then go through them one by one, which is iteration. This makes Choice 'D' correct.


Related study sets

Java - Chapter 11: Exception Handling

View Set

Biology: How Life Works Chapter 3 Pre-Class Assignment

View Set

BIO: Chapter 18 (pt 1) Gametes, Male Sexual Reproductive System

View Set

Ethical and Legal Issues Chapter 6

View Set