AS Associate Degree In Computer Science 2 — Questions and Answers
Question 1: Which data structure uses LIFO (Last In, First Out) order?
- Queue
- Stack (Correct answer)
- Linked List
- Tree
Correct answer: Stack
A stack follows LIFO order, meaning the last element added is the first one removed.
Question 2: In Python, what does the 'len()' function return for the string 'hello'?
- 4
- 5 (Correct answer)
- 6
- None
Correct answer: 5
'hello' has 5 characters, so len('hello') returns 5.
Question 3: Which SQL clause is used to filter results after grouping?
- WHERE
- HAVING (Correct answer)
- ORDER BY
- FILTER
Correct answer: HAVING
HAVING filters grouped results, while WHERE filters individual rows before grouping.
Question 4: What is the worst-case time complexity of bubble sort?
- O(n)
- O(n log n)
- O(n²) (Correct answer)
- O(log n)
Correct answer: O(n²)
Bubble sort compares each pair of adjacent elements repeatedly, resulting in O(n²) worst-case complexity.
Question 5: Which layer of the OSI model handles IP addressing?
- Data Link
- Transport
- Network (Correct answer)
- Session
Correct answer: Network
The Network layer (Layer 3) is responsible for logical IP addressing and routing.
Question 6: In object-oriented programming, what is encapsulation?
- Inheriting methods from a parent class
- Bundling data and methods within a class (Correct answer)
- Overriding a parent method
- Creating multiple objects from one class
Correct answer: Bundling data and methods within a class
Encapsulation bundles data (attributes) and behavior (methods) together inside a class, hiding internal details.
Question 7: Which gate produces a HIGH output only when all inputs are HIGH?
- OR gate
- NOT gate
- AND gate (Correct answer)
- XOR gate
Correct answer: AND gate
An AND gate outputs HIGH (1) only when every input is HIGH (1).
Which data structure uses LIFO (Last In, First Out) order?