Computer Science Interview Questions and Answers
Ques 1. What is the difference between a stack and a queue?
A stack follows the Last In, First Out (LIFO) principle, while a queue follows the First In, First Out (FIFO) principle.
Example:
Stack: Undo functionality in software. Queue: Print job scheduling.
Ques 2. Explain the concept of polymorphism in object-oriented programming.
Polymorphism allows objects of different types to be treated as objects of a common type. It includes method overloading and method overriding.
Example:
Method overloading: Same method name with different parameters. Method overriding: Subclass provides a specific implementation of a method defined in its superclass.
Ques 3. What is the purpose of an index in a database?
An index in a database improves the speed of data retrieval operations on a database table by providing a quick lookup mechanism.
Example:
Creating an index on a 'username' column for faster search queries.
Ques 4. Explain the term 'Big O' notation in algorithm analysis.
Big O notation is used to describe the upper bound on the growth rate of an algorithm's time complexity in the worst-case scenario.
Example:
O(n^2) for a nested loop algorithm.
Ques 5. What is the role of a constructor in object-oriented programming?
A constructor initializes an object's state and is called when an object is created. It typically assigns values to the object's attributes.
Example:
Java constructor: 'public MyClass(int value) { this.value = value; }'
Most helpful rated by users: