Here we have mentioned most frequently asked Data Structure Interview Questions and Answers specially for freshers and experienced.

**1. What is data structure?**

Ans:

Data structure refers to the way data is organized and manipulated. It seeks to find ways to make data access more efficient. When dealing with the data structure, we not only focus on one piece of data but the different set of data and how they can relate to one another in an organized manner.

**2. Differentiate between file and structure storage structure.**

Ans:

The key difference between both the data structure is the memory area that is being accessed. When dealing with the structure that resides the main memory of the computer system, this is referred to as storage structure. When dealing with an auxiliary structure, we refer to it as file structures.

**3. When is a binary search best applied?**

Ans:

A binary search is an algorithm that is best applied to search a list when the elements are already in order or sorted. The list is searched starting in the middle, such that if that middle value is not the target search key, it will check to see if it will continue the search on the lower half of the list or the higher half. The split and search will then continue in the same manner.

**4. What is a linked list?**

Ans:

A linked list is a sequence of nodes in which each node is connected to the node following it. This forms a chain-like link for data storage.

**5. How do you reference all the elements in a one-dimension array?**

Ans:

To reference all the elements in a one -dimension array, you need to use an indexed loop, So that, the counter runs from 0 to the array size minus one. In this manner, You can reference all the elements in sequence by using the loop counter as the array subscript.

**6. In what areas do data structures are applied?**

Ans:

Data structures are essential in almost every aspect where data is involved. In general, algorithms that involve efficient data structure is applied in the following areas: numerical analysis, operating system, A.I., compiler design, database management, graphics, and statistical analysis, to name a few.

**7. What is LIFO?**

Ans:

LIFO is a short form of Last In First Out. It refers how data is accessed, stored and retrieved. Using this scheme, data that was stored last should be the one to be extracted first. This also means that in order to gain access to the first data, all the other data that was stored before this first data must first be retrieved and extracted.

**8. What is a queue?**

Ans:

A queue is a data structure that can simulate a list or stream of data. In this structure, new elements are inserted at one end, and existing elements are removed from the other end.

**9. What are binary trees?**

Ans:

A binary tree is one type of data structure that has two nodes, a left node, and a right node. In programming, binary trees are an extension of the linked list structures.

**10. Which data structures are applied when dealing with a recursive function?**

Ans:

Recursion, is a function that calls itself based on a terminating condition, makes use of the stack. Using LIFO, a call to a recursive function saves the return address so that it knows how to return to the calling function after the call terminates.

**11. What is a stack?**

Ans:

A stack is a data structure in which only the top element can be accessed. As data is stored in the stack, each data is pushed downward, leaving the most recently added data on top.

**12. Explain Binary Search Tree**

Ans:

A binary search tree stores data in such a way that they can be retrieved very efficiently. The left subtree contains nodes whose keys are less than the node’s key value, while the right subtree contains nodes whose keys are greater than or equal to the node’s key value. Moreover, both subtrees are also binary search trees.

**13. What are multidimensional arrays?**

Ans:

Multidimensional arrays make use of multiple indexes to store data. It is useful when storing data that cannot be represented using single dimensional indexing, such as data representation in a board game, tables with data stored in more than one column.

**14. Are linked lists considered linear or non-linear data structures?**

Ans:

It depends on where you intend to apply linked lists. If you based it on storage, a linked list is considered non-linear. On the other hand, if you based it on access strategies, then a linked list is considered linear.

**15. How does dynamic memory allocation help in managing data?**

Ans:

Apart from being able to store simple structured data types, dynamic memory allocation can combine separately allocated structured blocks to form composite structures that expand and contract as needed.

**16. What is FIFO?**

Ans:

FIFO stands for First-in, First-out, and is used to represent how data is accessed in a queue. Data has been inserted into the queue list the longest is the one that is removed first.

**17. What is an ordered list?**

Ans:

An ordered list is a list in which each node’s position in the list is determined by the value of its key component, so that the key values form an increasing sequence, as the list is traversed.

**18. What is merge sort?**

Ans:

Merge sort, is a divide-and-conquer approach for sorting the data. In a sequence of data, adjacent ones are merged and sorted to create bigger sorted lists. These sorted lists are then merged again to form an even bigger sorted list, which continues until you have one single sorted list.

**19. Differentiate NULL and VOID**

Ans:

Null is a value, whereas Void is a data type identifier. A variable that is given a Null value indicates an empty value. The void is used to identify pointers as having no initial size.

**20. What is the primary advantage of a linked list?**

Ans:

A linked list is an ideal data structure because it can be modified easily. This means that editing a linked list works regardless of how many elements are in the list.

**21. What is the difference between a PUSH and a POP?**

Ans:

Pushing and popping applies to the way data is stored and retrieved in a stack. A push denotes data being added to it, meaning data is being “pushed” into the stack. On the other hand, a pop denotes data retrieval, and in particular, refers to the topmost data being accessed.

**22. What is a linear search?**

Ans:

A linear search refers to the way a target key is being searched in a sequential data structure. In this method, each element in the list is checked and compared against the target key. The process is repeated until found or if the end of the file has been reached.

**23. How does variable declaration affect memory allocation?**

Ans:

The amount of memory to be allocated or reserved would depend on the data type of the variable being declared. For example, if a variable is declared to be of integer type, then 32 bits of memory storage will be reserved for that variable.

**24. What is the advantage of the heap over a stack?**

Ans:

The heap is more flexible than the stack. That’s because memory space for the heap can be dynamically allocated and de-allocated as needed. However, the memory of the heap can at times be slower when compared to that stack.

**25. What is a postfix expression?**

Ans:

A postfix expression is an expression in which each operator follows its operands. The advantage of this form is that there is no need to group sub-expressions in parentheses or to consider operator precedence.

**26. What is Data abstraction?**

Ans:

Data abstraction is a powerful tool for breaking down complex data problems into manageable chunks. This is applied by initially specifying the data objects involved and the operations to be performed on these data objects without being overly concerned with how the data objects will be represented and stored in memory.

**27. How do you insert a new item in a binary search tree?**

Ans:

Assuming that the data to be inserted is a unique value (that is, not an existing entry in the tree), check first if the tree is empty. If it’s empty, just insert the new item in the root node. If it’s not empty, refer to the new item’s key. If it’s smaller than the root’s key, insert it into the root’s left subtree, otherwise, insert it into the root’s right subtree.

**28. How does a selection sort work for an array?**

Ans:

The selection sort is a fairly intuitive sorting algorithm, though not necessarily efficient. In this process, the smallest element is first located and switched with the element at subscript zero, thereby placing the smallest element in the first position.

The smallest element remaining in the subarray is then located next to subscripts 1 through n-1 and switched with the element at subscript 1, thereby placing the second smallest element in the second position. The steps are repeated in the same manner till the last element.

**29. How do signed and unsigned numbers affect memory?**

Ans:

In the case of signed numbers, the first bit is used to indicate whether positive or negative, which leaves you with one bit short. With unsigned numbers, you have all bits available for that number. The effect is best seen in the number range (an unsigned 8-bit number has a range 0-255, while the 8-bit signed number has a range -128 to +127.

**30. What is the minimum number of nodes that a binary tree can have?**

Ans:

A binary tree can have a minimum of zero nodes, which occurs when the nodes have NULL values. Furthermore, a binary tree can also have 1 or 2 nodes.

**31. What are dynamic data structures?**

Ans:

Dynamic data structures are structures that expand and contract as a program runs. It provides a flexible means of manipulating data because it can adjust according to the size of the data.

**32. In what data structures are pointers applied?**

Ans:

Pointers that are used in linked list have various applications in the data structure. Data structures that make use of this concept include the Stack, Queue, Linked List and Binary Tree.

**33. Do all declaration statements result in a fixed reservation in memory?**

Ans:

Most declarations do, with the exemption of pointers. Pointer declaration does not allocate memory for data, but for the address of the pointer variable. Actual memory allocation for the data comes during run-time.

**34. What are ARRAYs?**

Ans:

When dealing with arrays, data is stored and retrieved using an index that refers to the element number in the data sequence. This means that data can be accessed in any order. In programming, an array is declared as a variable having a number of indexed elements.

**35. What is the minimum number of queues needed when implementing a priority queue?**

Ans:

The minimum number of queues needed in this case is two. One queue is intended for sorting priorities while the other queue is used for actual storage of data.

**36. Which sorting algorithm is considered the fastest?**

Ans:

There are many types of sorting algorithms: quick sort, bubble sort, balloon sort, radix sort, merge sort, etc. Not one can be considered the fastest because each algorithm is designed for a particular data structure and data set. It would depend on the data set that you would want to sort.

**37. Differentiate STACK from ARRAY.**

Ans:

Stack follows a LIFO pattern. It means that data access follows a sequence wherein the last data to be stored when the first one to be extracted. Arrays, on the other hand, does not follow a particular order and instead can be accessed by referring to the indexed element within the array.

**38. Give a basic algorithm for searching a binary search tree.**

Ans:

if the tree is empty, then the target is not in the tree, end search

2. if the tree is not empty, the target is in the tree

3. check if the target is in the root item

4. if a target is not in the root item, check if a target is smaller than the root’s value

5. if a target is smaller than the root’s value, search the left subtree

6. else, search the right subtree

**39. What is a dequeue?**

Ans:

A dequeue is a double-ended queue. This is a structure wherein elements can be inserted or removed from either end.

**40. What is a bubble sort and how do you perform it?**

Ans:

A bubble sort is one sorting technique that can be applied to data structures such as an array. It works by comparing adjacent elements and exchanges their values if they are out of order. This method lets the smaller values “bubble” to the top of the list, while the larger value sinks to the bottom.

**41. What are the parts of a linked list?**

Ans:

A linked list typically has two parts: the head and the tail. Between the head and tail lie the actual nodes. All these nodes are linked sequentially.

**42. How does selection sort work?**

Ans:

Selection sort works by picking the smallest number from the list and placing it at the front. This process is repeated for the second position towards the end of the list. It is the simplest sort algorithm.

**43. What is a graph?**

Ans:

A graph is one type of data structure that contains a set of ordered pairs. These ordered pairs are also referred to as edges or arcs and are used to connect nodes where data can be stored and retrieved.

**44. Differentiate linear from a nonlinear data structure.**

Ans:

The linear data structure is a structure wherein data elements are adjacent to each other. Examples of linear data structure include arrays, linked lists, stacks, and queues. On the other hand, a non-linear data structure is a structure wherein each data element can connect to more than two adjacent data elements. Examples of nonlinear data structure include trees and graphs.

**45. What is an AVL tree?**

Ans:

An AVL tree is a type of binary search tree that is always in a state of partially balanced. The balance is measured as a difference between the heights of the subtrees from the root. This self-balancing tree was known to be the first data structure to be designed as such.

**46. What are doubly linked lists?**

Ans:

Doubly linked lists are a special type of linked list wherein traversal across the data elements can be done in both directions. This is made possible by having two links in every node, one that links to the next node and another one that connects to the previous node.

**47. What is Huffman’s algorithm?**

Ans:

Huffman’s algorithm is used for creating extended binary trees that have minimum weighted path lengths from the given weights. It makes use of a table that contains the frequency of occurrence for each data element.

**48. What is Fibonacci search?**

Ans:

Fibonacci search is a search algorithm that applies to a sorted array. It makes use of a divide-and-conquer approach that can significantly reduce the time needed in order to reach the target element.

**49. Briefly explain recursive algorithm.**

Ans:

Recursive algorithm targets a problem by dividing it into smaller, manageable sub-problems. The output of one recursion after processing one sub-problem becomes the input to the next recursive process.

**50. How do you search for a target key in a linked list?**

Ans:

To find the target key in a linked list, you have to apply sequential search. Each node is traversed and compared with the target key, and if it is different, then it follows the link to the next node. This traversal continues until either the target key is found or if the last node is reached.

**51.What is data structure?**

Ans:

A data structure is a way of organizing data that considers not only the items stored, but also their relationship to each other. Advance knowledge about the relationship between data items allows designing of efficient algorithms for the manipulation of data.

**52.Minimum number of queues needed to implement the priority queue?**

Ans:

Two. One queue is used for actual storing of data and another for storing priorities.

**53.What are the notations used in Evaluation of Arithmetic Expressions using prefix and postfix forms?**

Ans:

Polish and Reverse Polish notations.

**54.List out few of the Application of tree data-structure?**

Ans:

i)The manipulation of Arithmetic expression

ii)Symbol Table construction

iii)Syntax analysis.

**55.What is the type of the algorithm used in solving the 8 Queens problem?**

Ans:

Backtracking

**56.In RDBMS, what is the efficient data structure used in the internal storage representation?**

Ans:

B+ tree. Because in B+ tree, all the data is stored only in leaf nodes, that makes searching easier. This corresponds to the records that shall be stored in leaf nodes.

**57. What is a spanning Tree?**

Ans:

A spanning tree is a tree associated with a network. All the nodes of the graph appear on the tree once. A minimum spanning tree is a spanning tree organized so that the total edge weight between nodes is minimized.

**58. List out the areas in which data structures are applied extensively?**

Ans:

Compiler Design, Operating System, Database Management System, Statistical analysis package, Numerical Analysis, Graphics, Artificial Intelligence, Simulation

**59. Translate infix expression into its equivalent post fix expression: (A-B)*(D/E)**

Ans:

(A-B)*(D/E) = [AB-]*[DE/] = AB-DE/*

**60. What are priority queues?**

Ans:

A priority queue is a collection of elements such that each element has been assigned a priority.

**61. What is a string?**

Ans:

A sequential array of characters is called a string.

**62. What is Brute Force algorithm?**

Ans:

Algorithm used to search the contents by comparing each element of array is called Brute Force algorithm.

**63. What are the limitations of arrays?**

Ans:

i)Arrays are of fixed size.

ii)Data elements are stored in continuous memory locations which may not be available always.

iii)Adding and removing of elements is problematic because of shifting the locations.

**64. How can you overcome the limitations of arrays?**

Ans:

Limitations of arrays can be solved by using the linked list.

**65. What is a linked list?**

Ans:

Linked list is a data structure which store same kind of data elements but not in continuous memory locations and size is not fixed. The linked lists are related logically.

**66. What is a node?**

Ans:

The data element of a linked list is called a node.

**67. What does node consist of?**

Ans:

Node consists of two fields:data field to store the element and link field to store the address of the next node.

**68. What is a queue ?**

Ans:

A Queue is a sequential organization of data. A queue is a first in first out type of data structure. An element is inserted at the last position and an element is always taken out from the first position.

**69. What are the types of Collision Resolution Techniques and the methods used in each of the type?**

Ans:

Open addressing (closed hashing),The methods used include:Overflow block

Closed addressing (open hashing),The methods used include:Linked list,Binary tree

**70. What are the methods available in storing sequential files ?**

Ans:

Straight merging, Natural merging, Polyphase sort, Distribution of Initial runs.

**71. Mention some of the problem solving strategies?**

Ans:

The most widely strategies are listed below

i)Divide and conquer

ii)Binary doubling strategy

iii)Dynamic programming

**72. What is divide and conquer method?**

Ans:

The basic idea is to divide the problem into several sub problems beyond which cannot be further subdivided. Then solve the sub problems efficiently and join then together to get the solution for the main problem.

**73. What is the need for the header?**

Ans:

Header of the linked list is the first element in the list and it stores the number of elements in the list. It points to the first data element of the list.

**74. Define leaf?**

Ans:

In a directed tree any node which has out degree o is called a terminal node or a leaf.

**75. What are the applications of binary tree?**

Ans:

Binary tree is used in data processing.

**76. What are the different types of traversing?**

Ans:

The different types of traversing are

i)Pre-order traversal-yields prefix from of expression.

ii)In-order traversal-yields infix form of expression.

iii)Post-order traversal-yields postfix from of expression.

**77. Define pre-order traversal?**

Ans:

i)Process the root node

ii)Process the left subtree

iii)Process the right subtree

**78. Define post-order traversal?**

Ans:

i)Process the left subtree

ii)Process the right subtree

iii)Process the root node

**79. Define in -order traversal?**

Ans:

i)Process the left subtree

ii)Process the root node

iii)Process the right subtree

**80. What is meant by sorting?**

Ans:

Ordering the data in an increasing or decreasing fashion according to some relationship among the data item is called sorting.

**81. What’s the major distinction in between Storage structure and file structure and how?**

Ans:

The expression of an specific data structure inside memory of a computer system is termed storage structure in contrast to a storage structure expression in auxiliary memory is normally known as a file structure.

**82. Stack can be described as a pointer. Explain?**

Ans:

Because stack will contain a head pointer which will always point to the top of the Stack.All Stack Operations are done using Head Pointer. Hence Stack ca be Described as a Pointer

**83. What do you mean by: Syntax Error, Logical Error, Run time Error?**

Ans:

Syntax Error-Syntax Error is due to lack of knowledge in a specific language. It is due to somebody does not know how to use the features of a language.We can know the errors at the time of compilation.

logical Error-It is due to the poor understanding of the requirement or problem.

Run time Error-The exceptions like divide a number by 0,overflow and underflow comes under this.

**84. What is mean by d-queue?**

Ans:

D-queue stands for double ended queue. It is a abstract data structure that implements a queue for which elements can be added to front or rear and the elements can be removed from the rear or front. It is also called head-tail linked list

**85. What is AVL tree?**

Ans:

Avl tree is self binary tree in which balancing factor lie between the -1 to 1.It is also known as self balancing tree.

**86. What is binary tree?**

Ans:

Binary tree is a tree which has maximum no. of childrens either 0 or 1 or 2. i.e., there is at the most 2 branches in every node.

**87. What is the difference between a stack and a Queue?**

Ans:

Stack – Represents the collection of elements in Last In First Out order. Operations includes testing null stack, finding the top element in the stack, removal of top most element and adding elements on the top of the stack.

Queue – Represents the collection of elements in First In First Out order.Operations include testing null queue, finding the next element, removal of elements and inserting the elements from the queue.

Insertion of elements is at the end of the queue.Deletion of elements is from the beginning of the queue

**88. What actions are performed when a function is called?**

Ans:

i)arguments are passed

ii)local variables are allocated and initialized

iii)transferring control to the function

**89. What is precision?**

Ans:

Precision refers the accuracy of the decimal portion of a value. Precision is the number of digits allowed after the decimal point.

**90. What do you mean by overflow and underflow?**

Ans:

When new data is to be inserted into the data structure but there is no available space i.e.free storage list is empty this situation is called overflow.When we want to delete data from a data structure that is empty this situation is called underflow.

**91. The postfix form of the expression (A+ B)*(C*D- E)*F / G is?**

**a) AB+ CD*E – FG /******b) AB + CD* E – F **G /****c) AB + CD* E – *F *G /****d) AB + CDE * – * F *G /**

Ans:

a) AB+ CD*E – FG /**

Explanation: Applying the postfix expression evaluation.

**92. The data structure required to check whether an expression contains balanced parenthesis is?**

**a) Stack****b) Queue****c) Array****d) Tree**

Ans:

a) Stack

Explanation: Self Explanatory.

**93. What data structure would you mostly likely see in a non recursive implementation of a recursive algorithm?**

**a) Linked List****b) Stack****c) Queue****d) Tree**

Ans:

b) Stack

Explanation: Self Explanatory.

**94. The process of accessing data stored in a serial access memory is similar to manipulating data on a ________**

**a) Heap****b) Binary Tree****c) Array****d) Stack**

Ans:

d) Stack

Explanation: Self Explanatory.

**95. The postfix form of A*B+C/D is?**

**a) *AB/CD+****b) AB*CD/+****c) A*BC+/D****d) ABCD+/***

Ans:

b) AB*CD/+

Explanation: Applying the postfix expression evaluation.

**96. Which data structure is needed to convert infix notation to postfix notation?**

**a) Branch****b) Tree****c) Queue****d) Stack**

Ans:

d) Stack

Explanation: Self Explanatory.

**97. The prefix form of A-B/ (C * D ^ E) is?**

**a) -/*^ACBDE****b) -ABCD*^DE****c) -A/B*C^DE****d) -A/BC*^DE**

Ans:

c) -A/B*C^DE

Explanation: Applying the prefix expression evaluation.

**98. What is the result of the following operation**

**Top (Push (S, X))****a) X****b) Null****c) S****d) None**

Ans:

a) X

Explanation: Self Explanatory.

**99. The prefix form of an infix expression p + q – r * t is?**

**a) + pq – *rt****b) – +pqr * t****c) – +pq * rt****d) – + * pqrt**

Ans:

c) – +pq * rt

Explanation: Applying the prefix expression evaluation.

**100. Which data structure is used for implementing recursion?**

**a) Queue****b) Stack****c) Array****d) List**

Ans:

b) Stack

Explanation: Stacks are used for implementation of Recursion.

**101. What is data-structure?**

Ans:

Data structure is a way of defining, storing & retriving of data in a structural & systemetic way. A data structure may contain different type of data items.

**102. What are various data-structures available?**

Ans:

Data structure availability may vary by programming languages. Commonly available data structures are list, arrays, stack, queues, graph, tree etc.

**103. What is algorithm?**

Ans:

Algorithm is a step by step procedure, which defines a set of instructions to be executed in certain order to get the desired output.

**104. Why we need to do algorithm analysis?**

Ans:

A problem can be solved in more than one ways. So, many solution algorithms can be derived for a given problem. We analyze available algorithms to find and implement the best suitable algorithm.

**105. What are the criteria of algorithm analysis?**

Ans:

An algorithm are generally analyzed on two factors – time and space. That is, how much execution time and how much extra space required by the algorithm.

**106. What is asymptotic analysis of an algorithm?**

Ans:

Asymptotic analysis of an algorithm, refers to defining the mathematical boundation/framing of its run-time performance. Using asymptotic analysis, we can very well conclude the best case, average case and worst case scenario of an algorithm.

**107. What are asymptotic notations?**

Ans:

Asymptotic analysis can provide three levels of mathematical binding of execution time of an algorithm –

Best case is represented by O(n) notation.

Worst case is represented by ?(n) notation.

Average case is represented by T(n) notation.

**108. What is linear data structure?**

Ans:

A linear data-structure has sequentially arranged data items. The next time can be located in the next memory address. It is stored and accessed in a sequential manner. Array and list are example of linear data structure.

**109. What are common operations that can be performed on a data-structure?**

Ans:

The following operations are commonly performed on any data-structure –

Insertion – adding a data item

Deletion – removing a data item

Traversal – accessing and/or printing all data items

Searching – finding a particular data item

Sorting – arranging data items in a pre-defined sequence

Briefly explain the approaches to develop algorithms.

There are three commonly used approaches to develop algorithms –

Greedy Approach – finding solution by choosing next best option

Divide and Conquer – diving the problem to a minimum possible sub-problem and solving them independently

Dynamic Programming – diving the problem to a minimum possible sub-problem and solving them combinedly

Give some examples greedy algorithms.

The below given problems find their solution using greedy algorithm approach –

Travelling Salesman Problem

Prim’s Minimal Spanning Tree Algorithm

Kruskal’s Minimal Spanning Tree Algorithm

Dijkstra’s Minimal Spanning Tree Algorithm

Graph – Map Coloring

Graph – Vertex Cover

Knapsack Problem

Job Scheduling Problem

**110. What are some examples of divide and conquer algorithms?**

Ans:

The below given problems find their solution using divide and conquer algorithm approach –

Merge Sort

Quick Sort

Binary Search

Strassen’s Matrix Multiplication

Closest pair (points)

**111. What are some examples of dynamic programming algorithms?**

Ans:

The below given problems find their solution using divide and conquer algorithm approach –

Fibonacci number series

Knapsack problem

Tower of Hanoi

All pair shortest path by Floyd-Warshall

Shortest path by Dijkstra

Project scheduling

**112. What is a linked-list?**

Ans:

A linked-list is a list of data-items connected with links i.e. pointers or references. Most modern high-level programming language does not provide the feature of directly accessing memory location, therefore, linked-list are not supported in them or available in form of inbuilt functions.

**113. What is stack?**

Ans:

In data-structure, stack is an Abstract Data Type (ADT) used to store and retrieve values in Last In First Out method.

**114. Why do we use stacks?**

Ans:

Stacks follows LIFO method and addition and retrieval of a data item takes only ?(n) time. Stacks are used where we need to access data in the reverse order or their arrival. Stacks are used commonly in recursive function calls, expression parsing, depth first traversal of graphs etc.

**115. What operations can be performed on stacks?**

Ans:

The below operations can be performed on a stack –

push() – adds an item to stack

pop() – removes the top stack item

peek() – gives value of top item without removing it

isempty() – checks if stack is empty

isfull() – checks if stack is full

**116. What is a queue in data-structure?**

Ans:

Queue is an abstract data structure, somewhat similar to stack. In contrast to stack, queue is opened at both end. One end is always used to insert data (enqueue) and the other is used to remove data (dequeue). Queue follows First-In-First-Out methodology, i.e., the data item stored first will be accessed first.

**117. Why do we use queues?**

Ans:

As queues follows FIFO method, they are used when we need to work on data-items in exact sequence of their arrival. Every operating system maintains queues of various processes. Priority queues and breadth first traversal of graphs are some examples of queues.

**118. What operations can be performed on Queues?**

Ans:

The below operations can be performed on a stack –

enqueue() – adds an item to rear of the queue

dequeue() – removes the item from front of the queue

peek() – gives value of front item without removing it

isempty() – checks if stack is empty

isfull() – checks if stack is full

**119. What is linear searching?**

Ans:

Linear search tries to find an item in a sequentially arranged data type. These sequentially arranged data items known as array or list, are accessible in incrementing memory location. Linear search compares expected data item with each of data items in list or array. The average case time complexity of linear search is ?(n) and worst case complexity is ?(n2). Data in target arrays/lists need not to be sorted.

**120. What is binary search?**

Ans:

A binary search works only on sorted lists or arrays. This search selects the middle which splits the entire list into two parts. First the middle is compared.

This search first compares the target value to the mid of the list. If it is not found, then it takes decision on whether.

**121. What is bubble sort and how bubble sort works?**

Ans:

Bubble sort is comparison based algorithm in which each pair of adjacent elements is compared and elements are swapped if they are not in order. Because the time complexity is ?(n2), it is not suitable for large set of data.

**122. Tell me something about ‘insertion sort’?**

Ans:

Insertion sort divides the list into two sub-list, sorted and unsorted. It takes one element at time and finds it appropriate location in sorted sub-list and insert there. The output after insertion is a sorted sub-list. It iteratively works on all the elements of unsorted sub-list and inserts them to sorted sub-list in order.

**123. What is selection sort?**

Ans:

Selection sort is in-place sorting technique. It divides the data set into two sub-lists: sorted and unsorted. Then it selects the minimum element from unsorted sub-list and places it into the sorted list. This iterates unless all the elements from unsorted sub-list are consumed into sorted sub-list.

**124. How insertion sort and selection sorts are different?**

Ans:

Both sorting techniques maintains two sub-lists, sorted and unsorted and both take one element at a time and places it into sorted sub-list. Insertion sort works on the current element in hand and places it in the sorted array at appropriate location maintaining the properties of insertion sort. Whereas, selection sort searches the minimum from the unsorted sub-list and replaces it with the current element in hand.

**125. What is merge sort and how it works?**

Ans:

Merge sort is sorting algorithm based on divide and conquer programming approach. It keeps on dividing the list into smaller sub-list until all sub-list has only 1 element. And then it merges them in a sorted way until all sub-lists are consumed. It has run-time complexity of 0(n log n) and it needs 0(n) auxiliary space.

**126. What is shell sort?**

Ans:

Shell sort can be said a variant of insertion sort. Shell sort divides the list into smaller sublist based on some gap variable and then each sub-list is sorted using insertion sort. In best cases, it can perform upto 0(n log n).

**127. How quick sort works?**

Ans:

Quick sort uses divide and conquer approach. It divides the list in smaller ‘partitions’ using ‘pivot’. The values which are smaller than the pivot are arranged in the left partition and greater values are arranged in the right partition. Each partition is recursively sorted using quick sort.

**128. What is a graph?**

Ans:

A graph is a pictorial representation of a set of objects where some pairs of objects are connected by links. The interconnected objects are represented by points termed as vertices, and the links that connect the vertices are called edges.

**129. How depth first traversal works?**

Ans:

Depth First Search algorithm(DFS) traverses a graph in a depthward motion and uses a stack to remember to get the next vertex to start a search when a dead end occurs in any iteration.

**130. How breadth first traversal works?**

Ans:

Breadth First Search algorithm(BFS) traverses a graph in a breadthwards motion and uses a queue to remember to get the next vertex to start a search when a dead end occurs in any iteration.

**131. What is a tree?**

Ans:

A tree is a minimally connected graph having no loops and circuits.

**132. What is a binary tree?**

Ans:

A binary tree has a special condition that each node can have two children at maximum.

**133. What is a binary search tree?**

Ans:

A binary search tree is a binary tree with a special provision where a node’s left child must have value less than its parent’s value and node’s right child must have value greater than it’s parent value

**134. What is tree traversal?**

Ans:

Tree traversal is a process to visit all the nodes of a tree. Because, all nodes are connected via edges (links) we always start from the root (head) node. There are three ways which we use to traverse a tree –

In-order Traversal

Pre-order Traversal

Post-order Traversal

**135. What is an AVL Tree?**

Ans:

AVL trees are height balancing binary search tree. AVL tree checks the height of left and right sub-trees and assures that the difference is not more than 1. This difference is called Balance Factor.

BalanceFactor = height(left-sutree) – height(right-sutree)

**136. What is a spanning tree?**

Ans:

A spanning tree is a subset of Graph G, which has all the vertices covered with minimum possible number of edges. A spanning tree does not have cycles and it can not be disconnected.

**137. How many spanning trees can a graph has?**

Ans:

It depends on how connected the graph is. A complete undirected graph can have maximum nn-1 number of spanning trees, where n is number of nodes.

**138. How Kruskal’s algorithm works?**

Ans:

This algorithm treats the graph as a forest and every node it as an individual tree. A tree connects to another only and only if it has least cost among all available options and does not violate MST properties.

**139. What is a minimum spanning tree (MST) ?**

Ans:

In a weighted graph, a minimum spanning tree is a spanning tree that has minimum weight that all other spanning trees of the same graph.

**140. What is a heap in data structure?**

Ans:

Heap is a special balanced binary tree data structure where root-node key is compared with its children and arranged accordingly. A min-heap, a parent node has key value less than its childs and a max-heap parent node has value greater than its childs.

**141. What is a recursive function?**

Ans:

A recursive function is one which calls itself, directly or calls a function that in turn calls it. Every recursive function follows the recursive properties – base criteria where functions stops calling itself and progressive approach where the functions tries to meet the base criteria in each iteration.

**142. What is tower of hanoi?**

Ans:

Tower of Hanoi, is a mathematical puzzle which consists of three tower (pegs) and more than one rings. All rings are of different size and stacked upon each other where the large disk is always below the small disk. The aim is to move the tower of disk from one peg to another, without breaking its properties.

**143. What is fibonacci series?**

Ans:

Fibonacci Series generates subsequent number by adding two previous numbers. For example – 0 1 1 2 3 5 8 13.

**144. What is hashing?**

Ans:

Hashing is a technique to convert a range of key values into a range of indexes of an array. By using hash tables, we can create an associative data storage where data index can be find by providing its key values.

**145. What is interpolation search technique?**

Ans:

Interpolation search is an improved variant of binary search. This search algorithm works on the probing position of required value.

**146. What is the prefix and post fix notation of (a + b) * (c + d) ?**

Ans:

Prefix Notation – * + a b + c d

Postfix Notation – a b + c d + *

**147. How Prim’s algorithm finds spanning tree?**

Ans:

Prim’s algorithm treats the nodes as a single tree and keeps on adding new nodes to the spanning tree from the given graph.

#### About the author

### Leave a Reply Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.