CS Programming & Software Development 3 — Questions and Answers
Question 1: Which data structure operates on a Last-In, First-Out (LIFO) basis?
- Stack (Correct answer)
- Queue
- Linked list
- Hash table
Correct answer: Stack
A stack removes the most recently added element first, which is LIFO behavior.
Question 2: What is the time complexity of binary search on a sorted array of n elements?
- O(n)
- O(n log n)
- O(1)
- O(log n) (Correct answer)
Correct answer: O(log n)
Binary search halves the search space each step, giving logarithmic time.
Question 3: In object-oriented programming, which concept allows a subclass to provide its own implementation of a method defined in its parent class?
- Method overloading
- Data hiding
- Method overriding (Correct answer)
- Garbage collection
Correct answer: Method overriding
Overriding replaces an inherited method's behavior with a subclass-specific implementation.
Question 4: A team integrates code changes into a shared repository several times a day, with automated builds and tests on every merge. What is this practice called?
- Waterfall development
- Continuous integration (Correct answer)
- Pair programming
- Code freezing
Correct answer: Continuous integration
Continuous integration merges changes frequently and verifies each one with automated builds and tests.
Question 5: Which of the following best describes an API?
- A defined interface that lets software components communicate (Correct answer)
- A tool that converts source code to machine code
- A database that stores user passwords
- A hardware component that speeds up graphics
Correct answer: A defined interface that lets software components communicate
An API specifies how programs request services and exchange data with each other.
Question 6: What does the modulo operator (%) return in the expression 17 % 5?
- 3
- 3.4
- 12
- 2 (Correct answer)
Correct answer: 2
17 divided by 5 is 3 with a remainder of 2, and modulo returns the remainder.
Question 7: Why are hard-coded values like tax rates usually replaced with named constants?
- They make the program run significantly faster
- They are required by all compilers
- They make code easier to read and update in one place (Correct answer)
- They prevent all runtime errors
Correct answer: They make code easier to read and update in one place
Named constants improve readability and let a value be changed in a single location.
Which data structure operates on a Last-In, First-Out (LIFO) basis?