{"id":1360,"date":"2015-04-29T11:18:12","date_gmt":"2015-04-29T18:18:12","guid":{"rendered":"http:\/\/sites.evergreen.edu\/compcog15\/?page_id=1360"},"modified":"2015-04-29T11:18:12","modified_gmt":"2015-04-29T18:18:12","slug":"ch-8-answers","status":"publish","type":"page","link":"https:\/\/sites.evergreen.edu\/compcog15\/week-5\/april-29\/ch-8-answers\/","title":{"rendered":"Ch 8 Answers"},"content":{"rendered":"<p>8.1<br \/>\nA Balanced Introduction to Computer Science, 3\/E<br \/>\nDavid Reed \u00a9Pearson Prentice Hall, 2011<br \/>\nChapter 8 Review Question Solutions<br \/>\n1. TRUE or FALSE? An algorithm is a step-by-step sequence of instructions for carrying<br \/>\nout some task.<br \/>\nTRUE<br \/>\n2. TRUE or FALSE? A sequence of instructions for assembling a bookcase does not<br \/>\nqualify as an \u201calgorithm\u201d since the instructions are not written in formal, mathematical<br \/>\nnotation.<br \/>\nFALSE<br \/>\n3. TRUE or FALSE? For a precise, clearly-stated problem, there can be only one algorithm<br \/>\nthat solves that problem.<br \/>\nFALSE<br \/>\n4. TRUE or FALSE? Big-Oh notation is used to measure the exact number of seconds<br \/>\nrequired by a particular algorithm when executing on a particular computer.<br \/>\nFALSE<br \/>\n5. TRUE or FALSE? Suppose you have been given a sorted list of 100 names and need to<br \/>\nfind a particular name in that list. Using sequential search, it is possible that you might<br \/>\nhave to look at every location in the list before finding the desired name.<br \/>\nTRUE<br \/>\n6. TRUE or FALSE? Suppose you have been given a sorted list of 100 names and need to<br \/>\nfind a particular name in that list. Using binary search, it is possible that you might have<br \/>\nto look at every location in the list before finding the desired name.<br \/>\nFALSE<br \/>\n7. TRUE or FALSE? Binary search is an example of an O(log N) algorithm, where the<br \/>\nnumber of items in the list to be searched is N.<br \/>\n8.2<br \/>\nTRUE<br \/>\n8. TRUE or FALSE? One advantage of assembly languages over machine languages is that<br \/>\nthey enable the programmer to use words to identify instructions instead of using binarynumber<br \/>\nsequences.<br \/>\nTRUE<br \/>\n9. TRUE or FALSE? JavaScript, C++, and Java are all examples of high-level<br \/>\nprogramming languages.<br \/>\nTRUE<br \/>\n10. TRUE or FALSE? When a Web page is loaded into a Web browser, JavaScript code in<br \/>\nthat page is executed by a JavaScript interpreter that is embedded in the browser.<br \/>\nTRUE<br \/>\n11. An algorithm must be clear to its intended executor in order to be effective. Give an<br \/>\nexample of a real-world algorithm that you have encountered and felt was not clear. Do<br \/>\nyou think that the algorithm writer did a poor job, or do you think that the algorithm was<br \/>\nformalized with a different audience in mind? Explain your answer. Then, give an<br \/>\nexample of a real-world algorithm that you felt was clearly stated. What features of this<br \/>\nalgorithm allow you to understand it more easily?<br \/>\nStudent responses will vary.<br \/>\n12. Write an algorithm for directing a person to your house, apartment, or dorm from a<br \/>\ncentral location. For example, if you live on campus, the directions might originate at a<br \/>\ncampus landmark. Assume that the person following the directions is familiar with the<br \/>\nneighborhood or campus.<br \/>\nStudent responses will vary.<br \/>\n13. Write an alternative algorithm for directing a person to your residence, but this time,<br \/>\nassume that the person is unfamiliar with the area. How does this condition affect the<br \/>\nway you describe the algorithm?<br \/>\nStudent responses will vary.<br \/>\n14. Suppose that you were asked to arrange a group of people in sequence from oldest to<br \/>\nyoungest. You must organize a line that begins with the oldest person and continues in<br \/>\ndescending order according to age. Describe an algorithm for completing this task.<br \/>\n8.3<br \/>\nStudent responses will vary. One possible solution is to apply the algorithm from the<br \/>\nbook for finding the oldest person repeatedly. That is, find the oldest person using the<br \/>\nalgorithm, and place that person at the front of a line. Then, repeat the process on the<br \/>\nremaining people, placing the next oldest second in line, and so on until all people have<br \/>\nbeen placed.<br \/>\n15. Suppose that you have been given an O(N) algorithm that averages student grades, where<br \/>\nN is the number of grades. If it takes 1 minute to average 100 grades using the algorithm,<br \/>\nhow long would you expect it to take to average 200 grades? 400 grades? Justify your<br \/>\nanswer.<br \/>\nSince the algorithm is O(N), doubling the size of the problem should roughly double the<br \/>\ntime required for a solution. Thus, 200 grades would require roughly 2 minutes, and 400<br \/>\ngrades would require roughly 4 minutes.<br \/>\n16. Suppose you needed to look up a number in your local phone book. Roughly, what is the<br \/>\npopulation of your city? How many checks would be required, in the worst case, to find<br \/>\nthe phone number using sequential search? How many checks would be required, in the<br \/>\nworst case, to find the phone number using binary search?<br \/>\nStudent answers will depend upon local population. For sequential search: In the best<br \/>\ncase, the name will appear first in the book, requiring only 1 inspection. In the worst<br \/>\ncase, the name will appear last in the book, requiring all entries to be inspected. For<br \/>\nbinary search: In the best case, the name will appear in the exact middle of the book,<br \/>\nrequiring only 1 inspection. There are many worst case positions, including the first and<br \/>\nlast positions in the book, requiring log2 N inspections, where N is the number of entries<br \/>\nin the book.<br \/>\n17. Consider the list of states from Figure 8.5. Which state in the list is the &#8220;easiest&#8221; to find<br \/>\nusing binary search? That is, which state could be located in the fewest number of<br \/>\nchecks? Generalize your answer so that it applies to any sorted list of items.<br \/>\nThe easiest state to find would be &#8220;Missouri&#8221; since it appears at the middle position in the<br \/>\nlist. In general, the middle position is the easiest since it is the first place inspected.<br \/>\n18. Again, consider the list of states from Figure 8.5. Which state in the list is the &#8220;hardest&#8221;<br \/>\nto find using binary search? That is, which state would require the largest number of<br \/>\nchecks to be located? Generalize your answer so that it applies to any sorted list of items.<br \/>\nOne of the hardest states would be &#8220;WY&#8221;, which appears at the end of the list. Since the<br \/>\nsearch always checks the middle of the range, the end will only be reached when the<br \/>\nrange is reduced to size 1.<br \/>\n19. Refer to the Newton.html page. How many refinements does Newton&#8217;s algorithm<br \/>\nrequire to compute the square root of 900? 10,000? 152,399,025?<br \/>\n8.4<br \/>\n900 converges to 300 in 10 refinements.<br \/>\n10,000 converges to 100 in 11 refinements.<br \/>\n152,399,025 converges to 12,345 in 18 refinements.<br \/>\n20. Imagine that, while you are using Newton&#8217;s algorithm, the approximations converge on<br \/>\nthe actual square root of the number. What would happen if you tried to further refine the<br \/>\nsquare root? Would the value change? Why or why not?<br \/>\nAttempting to further refine the actual square root will produce no change, since<br \/>\n( + N\/ ) \/ 2 = ( + ) \/ 2 = .<br \/>\n21. A disadvantage of machine languages is that they are machine dependent. That is, each<br \/>\nmachine language is specific to a particular computer, and different computers require<br \/>\ndifferent machine languages. Describe why this is the case.<br \/>\nMachine language instructions correspond to the low-level operations that can be<br \/>\nexecuted by the hardware of the machine. Since different computers have different<br \/>\nCPUS, register configurations, and ALU operations, their machine languages will differ.<br \/>\n22. Describe two advantages of high-level language programming over machine-language<br \/>\nprogramming.<br \/>\nHigh-level languages allow the programmer to code at a higher level of abstraction,<br \/>\nfocusing on problem-solving constructs such as conditionals and loops, instead of lowlevel<br \/>\nmachine details. In addition, high-level languages are not specific to the underlying<br \/>\ncomputer\u2019s hardware configuration, so programs are portable across computers.<br \/>\n23. What is the difference between a compiler and an interpreter? What characteristics of an<br \/>\ninterpreter make it better suited for executing JavaScript programs?<br \/>\nA compiler is a program that translates an entire high-level language program into its<br \/>\nequivalent machine-language instructions. In contrast, an interpreter translates and<br \/>\nexecutes the statements in the high-level language program one statement at a time.<br \/>\nWhile this can make the execution of programs slower, it does provide immediate<br \/>\nfeedback as the output of statements can be displayed as they are executed in turn.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>8.1 A Balanced Introduction to Computer Science, 3\/E David Reed \u00a9Pearson Prentice Hall, 2011 Chapter 8 Review Question Solutions 1. TRUE or FALSE? An algorithm is a step-by-step sequence of instructions for carrying out some task. TRUE 2. TRUE or FALSE? A sequence of instructions for assembling a bookcase does not qualify as an \u201calgorithm\u201d [&hellip;]<\/p>\n","protected":false},"author":274,"featured_media":0,"parent":1329,"menu_order":0,"comment_status":"closed","ping_status":"open","template":"","meta":{"_mi_skip_tracking":false},"_links":{"self":[{"href":"https:\/\/sites.evergreen.edu\/compcog15\/wp-json\/wp\/v2\/pages\/1360"}],"collection":[{"href":"https:\/\/sites.evergreen.edu\/compcog15\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/sites.evergreen.edu\/compcog15\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/sites.evergreen.edu\/compcog15\/wp-json\/wp\/v2\/users\/274"}],"replies":[{"embeddable":true,"href":"https:\/\/sites.evergreen.edu\/compcog15\/wp-json\/wp\/v2\/comments?post=1360"}],"version-history":[{"count":0,"href":"https:\/\/sites.evergreen.edu\/compcog15\/wp-json\/wp\/v2\/pages\/1360\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/sites.evergreen.edu\/compcog15\/wp-json\/wp\/v2\/pages\/1329"}],"wp:attachment":[{"href":"https:\/\/sites.evergreen.edu\/compcog15\/wp-json\/wp\/v2\/media?parent=1360"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}