A few basic tech interview questions organized
- What is a stack?
A stack is a linear data structure with three basic operations: push (insertion of an element to the stack from the top), pop (removal of the latest element added to the stack). Some implementations of stack also allow peek, a function enabling you to see an element in a stack without modifying it. Stacks use a last-in, first-out structure — so the last element added to the stack is the first element that can be removed. Queues are a similar data structure, which work with a first-in, first-out structure. Stacks are usually implemented with an array or a linked list.
2. How does an array differ from a stack?
An array doesn’t have a fixed structure for how to add or retrieve data, but a stack has a strict LIFO approach (last in and first out).
3. Use Big O notation to describe QuickSort.
A quick sort usually works best on average cases, but there are worst-case scenarios. On average, it is O(N log N), but O(N2) in the worst case. You’ll want to use quick sort in situations where average-case performance matters a lot rather than dwelling on the worst.
4. Compare method and constructor
Constructor: Used to initialize the instance of a class. Doesn’t have a return type.
Method: Used to perform some function or operation. Has a return type.
5. What is the different type of access modifiers?
- Visible to the overall package. No modifier needed.
- Private — Visible to class only.
- Public — Visible to the world.
- Protected — Visible to package and subclass.
6. Difference between overloading and overriding?
Overloading is when two or more methods in the same class have the same method name but different parameters(i.e different method signatures).
Overriding is when two methods having the same method name and parameters (i.e., method signature) but one of the methods is in the parent class and the other is in the child class.
7. What is an algorithm?
An algorithm is a well-defined computational procedure that takes some values or the set of values, as an input and produces a set of values or some values, as an output.
8. What is Divide and Conquer algorithms?
Divide and Conquer is not an algorithm; it’s a pattern for the algorithm. It is designed in a way as to take dispute on a huge input, break the input into minor pieces, and decide the problem for each of the small pieces.
Divide: In this section, the algorithm divides the original problem into a set of subproblems.
Conquer: In this section, the algorithm solves every subproblem individually.
Combine: In this section, the algorithm puts together the solutions of the subproblems to get the solution to the whole problem.