AP Computer Science Principles Big Idea 3: Algorithms and Programming Practice Questions

Practice questions for AP Computer Science Principles Big Idea 3 (Algorithms and Programming), covering variables, algorithms, and program logic, with explanations for every answer.

151 questions · AP Computer Science Principles · by Study Foxy

Study these questions free

Questions

  1. What is a variable?

    • A named place to store a value
    • A value that stays exactly the same for as long as the program runs
    • A comment that describes a procedure
    • A type of error that occurs at runtime
  2. Consider: a ← 5; b ← a; a ← 8. What is the value of b?

    • 5
    • 8
    • 13
    • It changes to 8 when a changes
  3. Consider: x ← 3; y ← x * 2; x ← y + 1. What are the final values of x and y?

    • x = 7, y = 6
    • x = 3, y = 6
    • x = 7, y = 14
    • x = 6, y = 7
  4. Consider: a ← 4; b ← 9; temp ← a; a ← b; b ← temp. What are the final values?

    • a = 9, b = 4
    • a = 4, b = 9
    • a = 9, b = 9
    • a = 4, b = 4
  5. A student tries to swap two values: a ← 4; b ← 9; a ← b; b ← a. What are the final values?

    • a = 9, b = 9
    • a = 9, b = 4
    • a = 4, b = 9
    • a = 4, b = 4
  6. Consider: x ← 10; x ← x + 5; x ← x * 2. What is the final value of x?

    • 30
    • 25
    • 20
    • 15
  7. Consider: p ← 2; q ← p; q ← q + p; p ← q * q. What are the final values?

    • p = 16, q = 4
    • p = 4, q = 4
    • p = 16, q = 2
    • p = 8, q = 4
  8. When a new value is assigned to a variable, the previous value is replaced.

    True or false

  9. The statement x ← x + 1 is an error because x cannot equal x + 1.

    True or false

  10. Why is it good practice to give variables meaningful names, such as totalScore instead of t?

    • It makes the code easier to read and maintain
    • Meaningful names make the program run noticeably faster on most computers
    • Short variable names cause syntax errors in most languages
    • Meaningful names take up less of the computer's memory
  11. In the statement score ← score + 10, what happens first?

    • score + 10 is calculated using the current value
    • score is set to 0 before anything else in the statement happens
    • The value 10 is stored in score, replacing the old value
    • score is compared with 10 to see whether they are equal
  12. Consider: n ← 7; n ← n * 2; n ← n - 4. What is the final value of n?

  13. Which statements correctly describe variables?

    • A variable can store a number, string, Boolean, or list
    • A variable's value can be changed by assignment
    • A variable keeps every value ever assigned to it
    • A variable can hold only whole numbers
  14. In this course's pseudocode, lists start at index 1. If list ← [10, 20, 30, 40], what is list[2]?

    • 20
    • 30
    • 10
    • 2
  15. list ← [10, 20, 30, 40]. After APPEND(list, 50), what is LENGTH(list)?

    • 5
    • 4
    • 50
    • 6
  16. list ← [10, 20, 30, 40]. What is the list after INSERT(list, 2, 15)?

    • [10, 15, 20, 30, 40]
    • [10, 20, 15, 30, 40]
    • [15, 10, 20, 30, 40]
    • [10, 15, 30, 40]
  17. list ← [10, 20, 30, 40]. What is the list after REMOVE(list, 1)?

    • [20, 30, 40]
    • [10, 20, 30]
    • [10, 30, 40]
    • [20, 30, 40, 10]
  18. list ← [5, 8, 2]. After list[1] ← list[3], what is the list?

    • [2, 8, 2]
    • [5, 8, 5]
    • [2, 8, 5]
    • [8, 5, 2]
  19. letters ← ["a", "b", "c"]. After REMOVE(letters, 2) and then APPEND(letters, "d"), what is the list?

    • ["a", "c", "d"]
    • ["a", "b", "d"]
    • ["a", "d", "c"]
    • ["d", "a", "c"]
  20. nums ← [4, 7, 2, 9]. What does nums[LENGTH(nums)] evaluate to?

    • 9
    • 4
    • 2
    • An error, since that index is past the end of the list
  21. In this course's pseudocode, where lists start at index 1, what happens when a program evaluates list[0]?

    • An error occurs
    • It returns the first element of the list
    • It returns the last element of the list
    • It returns 0
  22. A program stores 30 test scores. Why is a list better than 30 separate variables?

    • One list can be processed with a loop
    • Lists can store only numbers, which keeps the data safely consistent
    • Separate variables cannot hold test scores
    • Lists never cause any errors when a program runs
  23. Using a list to store related data is an example of data abstraction.

    True or false

  24. A list is allowed to contain just a single element.

    True or false

  25. A list can hold only values of the same type.

    True or false

  26. What does it mean to traverse a list?

    • To access its elements one at a time
    • To sort the list into alphabetical order and remove any repeated values
    • To delete the list and all of its elements from memory
    • To compress the list so it takes up less storage
  27. vals ← [1, 2, 3]. What is vals after this code? i ← 1; REPEAT LENGTH(vals) TIMES { vals[i] ← vals[i] * vals[i]; i ← i + 1 }

    • [1, 4, 9]
    • [1, 2, 3]
    • [2, 4, 6]
    • [1, 4, 9, 16]
  28. nums ← [8, 3, 9, 1]. What does this code display? minIndex ← 1; i ← 2; REPEAT 3 TIMES { IF (nums[i] < nums[minIndex]) { minIndex ← i }; i ← i + 1 }; DISPLAY(minIndex)

    • 4
    • 1
    • 2
    • 3
  29. Which operations change the length of a list?

    • APPEND
    • INSERT
    • REMOVE
    • Assigning a new value to list[2]
    • Reading list[1]
  30. list ← [3, 6, 9, 12]. What is list[3]?

  31. A list contains [2, 7, 7, 3, 7]. A loop counts how many elements equal 7. What is the count?

    • 3
    • 2
    • 7
    • 5
  32. What is 17 MOD 5?

    • 2
    • 3
    • 3.4
    • 85
  33. What is 20 MOD 4?

    • 0
    • 5
    • 4
    • 1
  34. What is 3 MOD 7?

    • 3
    • 0
    • 4
    • 7
  35. What is the value of 7 + 3 * 2?

    • 13
    • 20
    • 12
    • 17
  36. What is the value of (7 + 3) * 2?

    • 20
    • 13
    • 17
    • 10
  37. Which expression is true exactly when the integer n is even?

    • n MOD 2 = 0
    • n MOD 2 = 1
    • n / 2 = 0
    • n MOD 0 = 2
  38. Which expression gives the last digit of a positive integer n?

    • n MOD 10
    • n / 10
    • n MOD 2
    • 10 MOD n
  39. Which expression is true when n is a multiple of 3?

    • n MOD 3 = 0
    • n / 3 = 0
    • 3 MOD n = 0
    • n MOD 3 = 3
  40. A procedure substring(str, start, length) returns length characters beginning at position start (positions start at 1). What does substring("COMPUTER", 4, 3) return?

    • "PUT"
    • "MPU"
    • "PUTE"
    • "UTE"
  41. What does concatenating the strings "tic" and "tac" produce?

    • "tictac"
    • "tic tac"
    • "tactic"
    • 6
  42. Consider: word ← ""; FOR EACH ch IN ["c", "a", "t"] { word ← concat(ch, word) }. What is word?

    • "tac"
    • "cat"
    • "act"
    • "ttt"
  43. In this course's pseudocode, 10 / 4 evaluates to 2.5.

    True or false

  44. The expression 9 MOD 3 evaluates to 3.

    True or false

  45. What is 25 MOD 10?

  46. What is 14 MOD 4?

  47. What is a string?

    • An ordered sequence of characters
    • A number that is stored in binary form using only the digits 0 and 1
    • A list of Boolean values that are each true or false
    • A type of loop that repeats a fixed number of times
  48. A program computes the average of a, b, and c. Which expression is correct?

    • (a + b + c) / 3
    • a + b + c / 3
    • a + b + (c / 3)
    • (a + b) + c / 3
  49. What is the value of NOT (true AND false)?

    • true
    • false
    • true AND false
    • undefined
  50. If x is 10, what is the value of (x > 5) AND (x < 10)?

    • false
    • true
    • 10
    • 5

Showing 50 of 151. Open the quiz to study them all.