Cognizant Core Knowledge and Fundamentals 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 operates on LIFO principle where the last element added is the first to be removed.
Question 2: What is the time complexity of binary search 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 iteration, resulting in O(log n) time complexity.
Question 3: In object-oriented programming, which concept allows a subclass to provide a specific implementation of a method already defined in its superclass?
- Encapsulation
- Abstraction
- Overloading
- Overriding (Correct answer)
Correct answer: Overriding
Method overriding allows a subclass to redefine a method from its parent class with its own implementation.
Question 4: Which SQL clause is used to filter results after a GROUP BY operation?
- WHERE
- HAVING (Correct answer)
- FILTER
- ORDER BY
Correct answer: HAVING
The HAVING clause filters groups created by GROUP BY, whereas WHERE filters individual rows before grouping.
Question 5: What does the OSI model's Transport layer primarily handle?
- Physical transmission of bits
- Logical addressing and routing
- End-to-end communication and error recovery (Correct answer)
- Session management between applications
Correct answer: End-to-end communication and error recovery
The Transport layer (Layer 4) is responsible for end-to-end communication, flow control, and error recovery using protocols like TCP and UDP.
Question 6: Which of the following is NOT a characteristic of a relational database?
- Data stored in tables
- Use of primary keys
- Schema-less data storage (Correct answer)
- Support for SQL queries
Correct answer: Schema-less data storage
Schema-less storage is a characteristic of NoSQL databases, not relational databases, which require a defined schema.
Question 7: In a C program, what is the output of: printf("%d", 5 % 2);
- 2
- 1 (Correct answer)
- 2.5
- 0
Correct answer: 1
The modulo operator % returns the remainder of division; 5 divided by 2 gives remainder 1.
Which data structure uses LIFO (Last In, First Out) order?