AP AP Computer Science & Technology 1 — Questions and Answers
Question 1: In AP Computer Science, which data structure operates on a Last-In-First-Out (LIFO) principle?
- Queue
- Stack (Correct answer)
- Linked List
- Binary Tree
Correct answer: Stack
A stack uses LIFO, meaning the last element added is the first one removed.
Question 2: What is the time complexity of a binary search algorithm on a sorted array of n elements?
- O(n)
- O(n²)
- O(log n) (Correct answer)
- O(n log n)
Correct answer: O(log n)
Binary search halves the search space each step, resulting in O(log n) time complexity.
Question 3: Which of the following best describes an algorithm with O(n²) time complexity?
- Constant time
- Linear time
- Logarithmic time
- Quadratic time (Correct answer)
Correct answer: Quadratic time
O(n²) is called quadratic time because execution time grows as the square of the input size.
Question 4: In AP Computer Science Principles, what does abstraction allow programmers to do?
- Write code without testing
- Manage complexity by hiding unnecessary details (Correct answer)
- Avoid using variables
- Run programs faster
Correct answer: Manage complexity by hiding unnecessary details
Abstraction lets programmers manage complexity by focusing on essential features and hiding implementation details.
Question 5: What is a Boolean expression?
- An expression that returns a number
- An expression that returns true or false (Correct answer)
- An expression that returns a string
- An expression that returns null
Correct answer: An expression that returns true or false
A Boolean expression evaluates to either true or false and is fundamental to conditional logic in programming.
Question 6: Which of the following describes a recursive function?
- A function that only runs once
- A function that calls itself (Correct answer)
- A function with no parameters
- A function that returns void
Correct answer: A function that calls itself
A recursive function calls itself with a modified argument until a base case terminates the recursion.
In AP Computer Science, which data structure operates on a Last-In-First-Out (LIFO) principle?