Data Structure Interview Questions

1)What is Data Structure?

   a) Data Structure is the way of collecting and organizing the data in such a way that
        we can perform various kinds of operations on these data in an effective way.

   b)Some examples of Data Structures are arrays, Linked List,Stack,Queue,etc..


2)What are the types of Data Structures?

  Data Structures are mainly classified into two types:

     a)Linear Data Structure

         i) A Data Structure is called linear if all of its elements are arranged in the
             sequential order.

        ii) In linear Data Structures, the elements are stored in a non-hierarchical way
             where each item has the successors and predecessors except the first and
             last element.

     b) Non-Linear Data Structure

         i) The Non-Linear Data Structure does not form a sequence.

        ii) That is each item (or) element is connected with two (or) more other items
             in a non-linear arrangement. The data elements are not arranged in the
             sequential structure.




3)What are the Applications of Data Structure?

       a)Compiler Design

      b)Operating System

      c)Database Management System

      d)Numerical Analysis

      e)Graphics

      f)Artificial Intelligence


4)What is a Stack?

   a)The stack is one of the data structure (or) stack is a container of objects that are
      inserted and removed according to the LAST IN FIRST OUT principle.

   b)A stack or LIFO (last in, first out) is an abstract data type that serves as a
          Collection of elements, with two principal operations:

                   i) Push, which adds an element to the collection
           
                   ii) Pop, which removes the last element that was added.

                  iii) In stack, both the operations of push and pop takes place at the same
                          end that is top of the stack. It can be implemented by using both
                          array and linked list. 


5)What are the Applications of Stack?

a) The stack is used by compilers to check for balancing of parenthesis, brackets, and braces.

b) The stack is used to convert an infix expression into a postfix/prefix form.

c) We can always remove recursion with the help of stacks.

d) Stacks are used for Maintaining function calls.

e) To implement back functionality in web browsers.


6)Give a real-life example of Stack?


 A good real-life example of a stack is the pile of dinner plates that you encounter when
 you eat at the local cafeteria: When you remove a plate from the pile, you take the plate
 on the top of the pile. But this is exactly the plate that was added ("inserted'') most recently
 to the pile by the dishwasher.


7)What is the Queue?

a) A queue is another special kind of data structure, where items are inserted at one end called the rear, and deleted at the other end called the front. Another name for a queue
    is a FIFO (Or) First-in-First-Out.
b) The operations for a queue are given below :
       Enqueue: which inserts an element at the end of the queue
      Dequeue: which deletes an element at the end of the queue


8)What are the Applications of Queue?

a) It is used to schedule the jobs to be processed by the CPU.
b) When multiple users send print jobs to a printer, each  printing job is kept in
    The printing queue. Then the printer prints those jobs according to FIFO basis.
c) The breadth-first search uses a queue data structure to find an element from a graph.        


9)What is Linked List?

 a) Linked List is a very commonly used linear data structure which consists of 
     group of nodes in a sequence.
 b) Each node holds its own data and the address of the next node hence forming 
     a chain-like structure.


10)What are  Advantages of Linked Lists?

a) Linked Lists are dynamic data structures. They can grow (or) shrink during the execution of a program
b) Linked Lists have efficient memory Utilization.
c)Linked Lists provide flexibility in inserting a data item at a specified position and Deletion of the data item from the given position
d) Many Complex applications can be easily carried out with linked lists.
e) Linked Lists are used to create graphs and trees.

11)What are the Disadvantages of Linked Lists?

a) It consumes more space because every node requires an an additional pointer to store
    address of the next node.
b)Searching a particular element in the list is difficult and time-consuming


12)What are  Applications of Linked Lists?

a) Linked Lists are used to represent and manipulate polynomial.

b) Linked Lists are to implement stack, queue, trees, and graphs.

c) Implement the symbol table in compiler construction.

13)Comparison between Array and Linked List?

ARRAY
LINKED LIST
Size of an array is fixed
Size of a list is not fixed
Memory is allocated from the stack
Memory is allocated from the heap
It is necessary to specify the number of elements during the declaration
It is not necessary to specify the number
of elements during declaration
It occupies less memory than a linked list for the same number of elements
It occupies more memory


14)What is Tree?

a) The tree is a non-linear data structure.
b) It is a hierarchical collection of nodes.
c) One of the nodes, known as the root, is at the top of the hierarchy.
d) Each node can have at most one link coming into it.
e) The node where the link originates is called the parent node.
f) The root node has no parent.
g) The links leaving a node point to child nodes.
h) Trees are recursive structures.
i) Each child node is itself the root of a subtree.


15)What is Binary Tree?

a) A binary tree is a tree data structure in which each node has at most two children,
   which are referred to as the left child and the right child. It is implemented mainly
     using Links.
b)In a binary tree a node should contain minimum zero sub-nodes maximum of two sub-nodes                         



16)Difference between Tree and Binary Tree?

TREE
BINARY TREE
Each element in a tree can have any number of subtrees.
Each element in a binary tree has at most
two subtrees.
The Subtrees in a tree are unordered.
The Subtrees of each element in a binary
a tree is ordered.



17)What is the Leaf node in a Tree?                                                                                                                   
A node with no children is called leaf nodes. A node which is not a leaf is called an internal
Node.


18)What is Level in a Tree?

The level of the node refers to its distance from the root. The maximum number of nodes at any level is 2^n.

 19)What is Height in a Tree?               

The maximum level in a tree determines its height. The height of a node in a tree is the length of the longest path from the node to a leaf.

 
20)What is Depth in a Tree?

The depth of a node is the number of nodes along the path from the root to that node.

 
21)What are the properties of binary trees?

   a)Height of the tree  is taken as lower  to upper
   b)Depth of tree is taken as upper to lower
   c)Height of tree=depth of tree=Level - 1
   d)Maximum no of nodes at level (L)=2^(L)-1
   e)Maximum no of nodes in a binary tree=2^(h+1) -1

  
22)What are the ways to Traverse a Binary Tree?      


 A Tree Traversal is a method of visiting every node in the tree. By visit, we mean that some types of operation are performed.
There are mainly three common ways to traverse a binary tree
 a)Inorder   - L P R
  b)Preorder - P L R
 c)Post order - L R P

 
23)Tell Some Applications of Tree Data Structure?

a) The file system on a computer.
b) Used in Compilers.
c) Manipulation of Arithmetic Expression
d) Used to implement indexing in databases.