加载中...
加载中...
Assessment for Unit 3: Big Idea 3: Algorithms and Programming
Select the one best answer for each question.
1. Consider the following code segment: ``` score <- 50 score <- score + 10 score <- score * 2 ``` What is the value of score after this code segment is executed?
2. A programmer is creating a game and needs to store the player's remaining lives, which is a whole number. Which of the following is the most appropriate and meaningful variable name to use?
3. Consider the following code segment: ``` a <- 10 b <- 20 a <- b ``` What are the final values of variables a and b?
4. In programming, a variable is best described as an abstraction for which of the following?
5. A program is intended to calculate the total cost of an item including tax. The price of the item is stored in a variable price, and the tax rate is stored in taxRate. Which of the following code segments correctly calculates and stores the final cost in a variable totalCost?
6. A program needs to store the names of all 50 states in the United States. Which of the following data abstractions is the most effective way to store this information?
7. Consider the following list, where the first element is at index 1. ``` colors <- ["red", "green", "blue", "yellow"] ``` Which of the following expressions correctly accesses the element "blue"?
8. How does the use of a list to store a collection of related data, such as student grades, help manage complexity in a program?
9. Which of the following statements best describes the concept of data abstraction?
10. A programmer creates a list to store a player's inventory in a game. The list is defined as follows: ``` inventory <- ["sword", "shield", 15, "potion"] ``` Which of the following statements about the inventory list is true?
11. What is the result of the expression 10 + 4 * 2?
12. What is the result of the expression 17 MOD 5?
13. Consider the following code segment: ``` x <- 3 y <- 5 z <- (x + y) / 2 ``` What is the value of z after this code segment executes?
14. Which of the following concepts ensures that each step of an algorithm is executed in the order it is written?
15. A programmer wants to calculate the average of three exam scores stored in variables score1, score2, and score3. Which expression correctly calculates the average?
16. Consider the following code segment: ``` firstName <- "Ada" lastName <- "Lovelace" fullName <- firstName + " " + lastName ``` What is the value of fullName after this code is executed?
17. The joining of two strings, end-to-end, is known as which of the following?
18. If the variable word contains the string "COMPUTER", which of the following expressions would result in the substring "PUT"?
19. Consider the following code segment: ``` val1 <- "10" val2 <- "20" result <- val1 + val2 ``` What is the value of result?
20. A program needs to display a message Hello, <name>! where <name> is the value stored in the variable userName. Which of the following expressions correctly creates this message?
21. The variable age holds the value 18. Which of the following Boolean expressions evaluates to true?
22. Consider the expression (x > 5) AND (x < 10). For which of the following values of x will the expression evaluate to true?
23. The variable isRaining is false and the variable isSunny is true. What is the result of the expression NOT isRaining AND isSunny?
24. Which of the following expressions is equivalent to NOT (a = b)?
25. A theme park ride has the following requirements: a person must be at least 54 inches tall OR have an adult with them. Let height be the person's height and withAdult be a Boolean variable. Which expression is true if the person is allowed on the ride?
26. Consider the following code segment: ``` temperature <- 85 ``` IF (temperature > 80) ``` { DISPLAY("It's a hot day!") } ``` ELSE ``` { DISPLAY("It's a pleasant day.") } ``` What is displayed when this code is executed?
27. The use of an IF statement in an algorithm to execute different code based on a condition is an example of which programming construct?
28. Consider the following code segment, where score is 95. IF (score > 90) ``` { DISPLAY("A") } ``` IF (score > 80) ``` { DISPLAY("B") } ``` What is displayed when this code is executed?
29. Consider the following code segment: ``` x <- 10 y <- 10 ``` IF (x = y) ``` { x <- x + 5 } ``` ELSE ``` { y <- y + 5 } ``` What are the final values of x and y?
30. An algorithm needs to check if a number is positive. The number is stored in the variable num. Which code segment correctly displays "Positive" only if num is greater than 0?
31. Consider the following code segment, where age is 20 and hasLicense is true. IF (age >= 16) ``` { ``` IF (hasLicense) ``` { DISPLAY("Can drive") } ``` ELSE ``` { DISPLAY("Cannot drive yet") } } ``` ELSE ``` { DISPLAY("Too young to drive") } ``` What is the output of this code?
32. Consider the following code segment, where score is 85. ``` grade <- "F" ``` IF (score >= 60) ``` { grade <- "D" ``` IF (score >= 70) ``` { grade <- "C" ``` IF (score >= 80) ``` { grade <- "B" ``` IF (score >= 90) ``` { grade <- "A" } } } } DISPLAY(grade) ``` What is displayed when this code runs?
33. Which of the following logical expressions is equivalent to the nested conditional structure shown below? IF (isWeekend) ``` { ``` IF (isSunny) ``` { DISPLAY("Go to the park.") } } ```
34. Consider the following code segment where temp is 30. IF (temp <= 32) ``` { DISPLAY("Freezing") } ``` ELSE ``` { ``` IF (temp >= 100) ``` { DISPLAY("Boiling") } ``` ELSE ``` { DISPLAY("Liquid") } } ``` What is the output?
35. A programmer is writing code to determine a shipping cost. If an order total is over 100 dollars, shipping is free. If the order is 100 dollars or less, shipping is 5 dollars for standard shipping and 15 dollars for express shipping. Which of the following best describes the control structure needed?
36. Consider the following code segment: ``` count <- 0 REPEAT 5 TIMES { count <- count + 1 } DISPLAY(count) ``` What is the final value displayed?
37. Consider the following code segment: ``` x <- 10 REPEAT UNTIL (x = 5) { DISPLAY(x) x <- x - 1 } ``` Which of the following best describes the output of this code?
38. A program needs to process every item in a list of 100 student names. Which control structure is most appropriate for this task?
39. ``` What happens in a REPEAT UNTIL (condition) loop if the condition is true the very first time it is checked? ```
40. Consider the following code segment: ``` num <- 1 REPEAT UNTIL (num > 10) { num <- num + 2 } DISPLAY(num) ``` What value is displayed?
41. Consider the following two algorithms, which are intended to calculate the sum of the integers from 1 to 4. Algorithm A ``` sum <- 1 + 2 + 3 + 4 DISPLAY(sum) ``` Algorithm B ``` sum <- 0 count <- 1 REPEAT UNTIL (count > 4) { sum <- sum + count count <- count + 1 } DISPLAY(sum) ``` Which of the following statements is true?
42. A programmer has already created a correct algorithm findMax(list) that returns the largest value in a list of numbers. The programmer now needs to find the largest value in the first half of a list called myList. Which of the following represents the best approach?
43. Which of the following is NOT a benefit of using existing, correct algorithms as building blocks for creating new algorithms?
44. A developer wants to create an algorithm to find the average of a list of numbers. A known, correct algorithm for finding the sum of a list is available. Which of the following describes how the developer could create the new algorithm?
45. Consider the following code segment: IF (score > 70) ``` { passed <- true } ``` ELSE ``` { passed <- false } ``` Which of the following single lines of code is equivalent to the segment above?
46. ``` Consider the list nums <- [10, 20, 30, 40]. The following code is executed. sum <- 0 ``` FOR EACH item IN nums ``` { sum <- sum + item } DISPLAY(sum) ``` What is the output?
47. ``` The list letters <- ["a", "b", "c", "d"] is modified by the command INSERT(letters, 3, "x"). What is the state of the list letters after the command executes? ```
48. The following algorithm is intended to find the minimum value in a list of positive numbers called data. ``` minVal <- 0 ``` FOR EACH num IN data ``` { ``` IF (num < minVal) ``` { minVal <- num } } RETURN minVal ``` Which of the following best describes the behavior of this algorithm?
49. The process of accessing each element of a list, one at a time, is known as what?
50. A list items contains 5 elements. What happens if a program attempts to access items[6]?
51. What is the most important prerequisite for a list to be searched using a binary search algorithm?
52. Consider the sorted list [2, 8, 11, 15, 22, 29, 34, 40]. A binary search is performed to find the value 29. What is the first value in the list that will be checked?
53. Which of the following best explains why binary search is generally more efficient than linear search for finding an element in a large list?
54. A sorted list contains 1,000 elements. In the worst-case scenario, approximately how many comparisons will a binary search take to find a value or determine it is not in the list?
55. A linear search algorithm is used to find a value in a list of n items. In the worst-case scenario, how many elements of the list must be checked?
56. Consider the following procedure definition: ``` PROCEDURE calculateArea(length, width) { RETURN(length * width) } ``` Which of the following is a valid call to this procedure?
57. In the context of procedures, what is the difference between a parameter and an argument?
58. Consider the following code segment: ``` PROCEDURE updateScore(currentScore) { currentScore <- currentScore + 100 RETURN(currentScore) } score <- 50 newScore <- updateScore(score) DISPLAY(score) ``` What value is displayed by this program?
59. ``` What is the primary function of a RETURN statement in a procedure? ```
60. A program uses a procedure GET_INPUT() which waits for the user to type something and press Enter, then returns what the user typed. Which line of code correctly stores the user's input in a variable named userName?
61. Which of the following best describes how procedural abstraction helps manage program complexity?
62. A programmer needs to create a procedure that calculates the sales tax for a given price. The procedure should take the price and the tax rate as inputs and return the calculated tax amount. Which of the following procedure definitions is the most appropriate?
63. The process of breaking a large computer program into smaller, independent subprograms (procedures) is known as what?
64. A team of programmers is working on a large project. They decide to use procedural abstraction to divide the work. How does this approach help their collaboration?
65. A programmer writes a procedure findAverage(numList) to calculate the average of numbers in a list. Later, the programmer finds a more efficient way to calculate the sum inside the procedure. How does procedural abstraction benefit the programmer in this situation?
66. What is the primary purpose of a software library?
67. A developer is building an application that needs to perform complex mathematical calculations. Instead of writing the code for these calculations from scratch, the developer decides to use a pre-existing math library. This is an example of what concept?
68. What is an Application Program Interface (API)?
69. A programmer wants to use a procedure from a graphics library to draw a circle. The procedure call is drawCircle(x, y, radius, color). To understand what values to provide for x, y, radius, and color, what should the programmer consult?
70. Which of the following is a significant benefit of using libraries in programming?
71. A program uses the procedure RANDOM(a, b), which generates a random integer from a to b, inclusive. Which expression generates a random integer representing the roll of a standard six-sided die?
72. ``` A program executes the statement result <- RANDOM(1, 10). Which of the following values could result NOT possibly have? ```
73. ``` A programmer wants to simulate flipping a coin. The outcome should be either "Heads" or "Tails". They generate a random number like this: flip <- RANDOM(0, 1). Which of the following code segments correctly uses this random number to assign the outcome? ```
74. What is the primary effect of using random number generation in a program?
75. Which expression generates a random even integer between 2 and 10, inclusive (i.e., 2, 4, 6, 8, or 10)?
76. A computer program that models the movement of planets in the solar system is an example of what?
77. When creating a computer simulation of a real-world phenomenon, developers often remove or simplify complex details. This process is a form of what?
78. Which of the following is a primary benefit of using computer simulations?
79. A simulation is created to model traffic flow in a city. The creators of the simulation only include data for cars and do not include data for buses, bicycles, or pedestrians. This omission could lead to what issue?
80. How can random numbers be useful in a simulation of a customer service call center?
81. An algorithm's efficiency is typically measured in terms of its use of which two computational resources?
82. An algorithm has a running time that is proportional to n^2, where n is the size of the input. Another algorithm for the same problem has a running time proportional to 2^n. Which of the following statements is true for large values of n?
83. The "Traveling Salesperson Problem" asks for the shortest possible route that visits a set of cities and returns to the origin city. For a large number of cities, no efficient algorithm is known to find the absolute best solution. In such cases, programmers often use an approach that provides a "good enough" solution, even if it might not be the absolute best. What is this type of approach called?
84. Algorithm X performs a search on a list of n items. Its efficiency can be described as linear. Algorithm Y performs the same search, and its efficiency is constant. Which algorithm is more efficient for a very large list?
85. Which of the following is an example of an algorithm that runs in an unreasonable amount of time?
86. Which of the following best defines an undecidable problem?
87. Which of the following is a decidable problem?
88. What is the significance of the existence of undecidable problems in computer science?
89. A decision problem is a problem that can be answered with what kind of output?
90. Consider the following statement: "For an undecidable problem, it is impossible to find a solution for any specific instance of the problem." Is this statement accurate?