Polytechnic Computer Science 1 — Questions and Answers
Question 1: What is the time complexity of binary search?
- O(log n) (Correct answer)
- O(n)
- O(n²)
- O(1)
Correct answer: O(log n)
Binary search halves the search space at each step, resulting in O(log n) time complexity.
Question 2: Which data structure uses LIFO (Last In, First Out) order?
- Stack (Correct answer)
- Queue
- Linked List
- Tree
Correct answer: Stack
A stack follows LIFO order, where the last element added is the first one to be removed.
Question 3: What does HTML stand for?
- HyperText Markup Language (Correct answer)
- High-Level Text Machine Language
- Hyper Transfer Markup Language
- HyperText Management Language
Correct answer: HyperText Markup Language
HTML stands for HyperText Markup Language, the standard language for structuring web pages.
Question 4: Which sorting algorithm has the best average-case time complexity?
- Merge Sort (O(n log n)) (Correct answer)
- Bubble Sort (O(n²))
- Insertion Sort (O(n²))
- Selection Sort (O(n²))
Correct answer: Merge Sort (O(n log n))
Merge Sort consistently achieves O(n log n) time complexity in all cases by using a divide-and-conquer approach.
Question 5: What is a primary key in a relational database?
- A unique identifier for each row in a table (Correct answer)
- The first column of a table
- A foreign reference to another table
- An index for faster queries
Correct answer: A unique identifier for each row in a table
A primary key uniquely identifies each record in a database table and cannot be null.
Question 6: What is the base of the binary number system?
- 2 (Correct answer)
- 8
- 10
- 16
Correct answer: 2
The binary number system uses base 2, consisting only of the digits 0 and 1.
What is the time complexity of binary search?