Sunday, April 17, 2016

Interview/oral questions and answers for Data structures using C++

Q1. What is a data structure?
Ans: It represents a storage in memory. As a subject, it deals with algorithms to store data with required fashion(like Last-In-First-Out or First-In-First-Out) by utilizing optimal(sufficient, neither more nor less, i.e. exact) memory in such a way that it should be retrieved fastly.

Examples:
Simplest: int x; x is an integer data structure
Simple: int a[100]; a is a data structure that stores 100 integers in adjacent memory location.

The examples of important data structures are, stack,queue,linked list, trees , graphs and hash tables.

Q2. What is time complexity and space complexity ?
Ans: Through time complexity one can analyze the running time of an algorithm where as Space complexity indicates the amount memory needed to load the program.

There are three asymptotic notations, used to study an analyze the algorithms.
Big 'O' notation - for specifying upper bound
Theta notation- to specify minimum steps required
 Omega notation - to specify lower bound.

Example:
The complexities of various algorithms..
Bubble sort, ---  O(n2
insertion sort,---  O(n2
 selection sort---  O(n2
Linear search ---  O(n)
Binary search ---  O(log2N)
Matrix Multiplication -  O(n3)
Find min/max among N numbers-  Q(N)
Quick sort ---  O(Nlog2N)
Popping an item from stack-  O(1)
Find maximum/minimum in a BST- O(d)
 where d is depth of tree

Q3. What is Stack and mention some applications of it.
Ans: Stack is a data structure which stores data in Last-In-First-out fashion.
It uses single end called stack pointer for pushing and popping an element from it.
Applications:
i.Used for Lexical analyzer and parser in compiler design
ii.Used to simulate recursive calls
iii.Used to check correctness of expressions(balancing of paranthesis)
iv.Used to convert infix expression to postfix expression.

Q4. What is priority queue? and what are its types?
Ans: It is a queue, where insertion is done in order, but item with certain priority will be removed first.
There are two types,
Ascending Priority queue: In which minimum item is removed first.
Descending Priority queue: In which maximum item is removed first. 

Q5. Which is the data structure used to store hierarchical data/information?
Ans: Trees

Similar way try to Answer following questions:
1. What is height of a tree?
2. What is skewed binary tree?
3. What is minimum spanning tree?
4. What are the graph traversing algorithms?
5. What is the purpose of Dijkstra algo?
6. What are application of queues?
7. Where do you find applications of graphs.
8. What is sequential file ?
9. What is indexed sequential file?
10. What is random access file?
11. Why we need Hash tables? and what are characteristics of a good hasing function?
12.Where do you use Heap data structure?
13. What is the time complexity of Heap sort?
14. What is a threaded binary tree?
15. Where do you find the applications of Expression trees?

OOP and C++ based question:
1. What is the difference between procedure oriented and object oriented programming?
2. What are the features of OOP?
3. What is the purpose of Data abstraction?
4. What we achieve by implementing Data encapsulation?
5. How C++ implements static polymorphism?
6. How C++ implements dynamic polymorphism?
7. What is reference variable in C++?
8. What is the criteria to overload two functions?
9. Why we need  operator overloading in C++?
10. What is the purpose of a namespace?
11. What are templates in C++?
12. What are the different access specifies in C++?
13. Why we need this pointer?
14. What are inline functions?
15. Why we define member functions outside the class using scope resolution operator?
16. What is a constructor? and list it's characteristics.
17. What is a destructor and explain it's purpose
18. What is static and non static data/methods in C++?
19. How C++ allocates memory at run time?
20. What are the different types of inheritances available in C++.

You can find solution for most of the questions in my other posts...

For more such interesting stuff, please subscribe by visiting 

No comments:

Post a Comment