0% found this document useful (0 votes)
22 views18 pages

Data Structure VIVA

Uploaded by

foodbucket02013
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views18 pages

Data Structure VIVA

Uploaded by

foodbucket02013
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

This PDF is specially made for PMSCS students

Data structure and Algorithm (Viva Voce)

1. What is a Data Structure?

In computer science, a data structure is a particular way of storing and organizing data in a computer’s
memory so that it can be used efficiently.

2. What are the Subject Matter of DS?

- Logical or mathematical description of the structure

- Implementation of the structure on a computer

- Quantitative analysis of the structure, which includes determining the amount of memory needed to
store the structure and the time required to process the structure.

3. What are linear and non-linear data Structures?

• Linear: A data structure is said to be linear if its elements form a sequence or a linear list.
Examples: Array. Linked List, Stacks and Queues
• Non-Linear: A data structure is said to be non-linear if the traversal of nodes is nonlinear in
nature. Example: Graph and Trees.

4. What are the various operations that can be performed on different Data Structures?

• Insertion Add a new data item in the given collection of data items.
• Deletion Delete an existing data item from the given collection of data items.
• Traversal Access each data item exactly once so that it can be processed.
• Searching Find out the location of the data item if it exists in the given collection of data
items.
• Sorting Arranging the data items in some order i.e. in ascending or descending order in
case of numerical data and in dictionary order in case of alphanumeric data .
5. What do you understand by Complexity?

The complexity of an algorithm is the function which gives the running time and /or space in terms of the
input size. It describes the efficiency of the algorithm in terms of the amount of data the algorithm must
process. There are two main complexity measures of the efficiency of an algorithm:

Time complexity
Space complexity

6. How is an Array different from Linked List?

• The size of the arrays is fixed, Linked Lists are Dynamic in size.
• Inserting and deleting a new element in an array of elements is expensive, Whereas both
insertion and deletion can easily be done in Linked Lists.
• Random access is not allowed in Linked Listed.
• Extra memory space for a pointer is required with each element of the Linked list.
• Arrays have better cache locality that can make a pretty big difference in performance.

7. What are the control structures available in DS?

Three types of logic or flow of control are used in data structures.

– Sequence logic or Sequential flow


– Selection logic or Conditional flow
– Iteration logic or Repetitive flow

8. What is a Queue, how it is different from the stack and how is it implemented?

Queue is a linear structure that follows the order is First In First Out (FIFO) to access elements. Mainly the
following are basic operations on queue: Enqueue, Dequeue, Front, Rear
The difference between stacks and queues is in removing. In a stack we remove the item the most recently
added; in a queue, we remove the item the least recently added. Both Queues and Stacks can be
implemented using Arrays and Linked Lists.
9. What are Infix, prefix, Postfix notations?

• Infix notation: X + Y – Operators are written in-between their operands. This is the usual
way we write expressions. An expression such as
A*(B+C)/D

• Postfix notation (also known as “Reverse Polish notation”): X Y + Operators are written
after their operands. The infix expression given above is equivalent to
A B C + * D/

• Prefix notation (also known as “Polish notation”): + X Y Operators are written before
their operands. The expressions given above are equivalent to
/*A+BCD

10. What is a Linked List and What are its types?

A linked list is a linear data structure (like arrays) where each element is a separate object. Each element
(that is node) of a list is comprising of two items – the data and a reference to the next node.Types of
Linked List :

1. Singly Linked List : In this type of linked list, every node stores address or reference of
next node in list and the last node has next address or reference as NULL. For example 1 -
>2->3->4->NULL
2. Doubly Linked List : Here, here are two references associated with each node, One of the
reference points to the next node and one to the previous node. Eg. NULL<-1<->2<->3-
>NULL
3. Circular Linked List : Circular linked list is a linked list where all nodes are connected to
form a circle. There is no NULL at the end. A circular linked list can be a singly circular
linked list or doubly circular linked list. Eg. 1->2->3->1 [The next pointer of last node is
pointing to the first]

11. Which data structures are used for BFS and DFS of a graph?

• Queue is used for BFS


• Stack is used for DFS. DFS can also be implemented using recursion (Note that recursion also uses
function call stack).

12. What is the difference between a File Structure and a Data Structure?

File Structure Data Structure

Data stored on disk Data stored on both RAM and disk

Standard file storage policies Customized storage policies

Low compatibility with external apps High compatibility with external apps
13. What is a linked list?

A linked list is a data structure that consists of individual entities called nodes. These nodes have the
capability to connect to other nodes and create a chain in the process. This continuous chain structure forms
a linked list, as the name suggests.

14. What are the string operations?

Various string operations have been developed. These are described below.

• Substring
• Indexing
• Concatenation
• Length

15. What are the operations used for word processing?

The operations usually associated with word processing are the following:

• Insertion
• Deletion and
• Replacement

16. What is pattern Matching?

Pattern matching is the problem of deciding whether or not a given string pattern P appears in a string text
T.
17. Where are Data Structures primarily used?

Data structures are very much needed in almost all of the fields that you can think of. Algorithms are the
primary requirement in every data handling situation. Following are some of the scenarios where data
structures are widely used:

• Numerical computation

• Operating system design

• Artificial Intelligence

• Compiler design

• Database handling

• Lexical analysis

• Statistics

18. What are the types of searching used in Data Structures?

The two primary methods of searching are linear search and binary search.

Linear search involves iterating over a data unit in order to perform the required operation.

Binary search is more efficient in a way that it has the ability to split the data unit into chunks and then
perform a search operation.

19. What is a queue in Data Structures?

A queue is a widely used data structure that is used to denote the ordered access and manipulation of an
element. The operation of this data structure is exactly the same as a literal queue in the real world. Elements
are added one after the other and are processed on the front end.
20. Distinguish between Array and Link List

– Both are linear data structures.


– Array size is fixed (dense list or static data structure) but linked list size is not fixed (dynamic
data structure).
– Array requires less space as only information is stored. Linked list requires more space as
pointers are also stored along with information.
– Elements are stored in consecutive memory locations. In linked list Elements may or may
not be stored in consecutive memory locations.
– Array needs movements of elements for insertion and deletion. Linked list does not need
movement of nodes for insertion and deletion.
– It can’t be extended or reduced according to requirements. Linked list can be extended or
reduced according to requirements.
– Space is wasted in Array. Space is not wasted in Linked List.

21. What is Memory allocation and Garbage collection?

❑ Memory Allocation
– The maintenance of linked lists in memory assumes the possibility of inserting new nodes
into the lists and hence requires some mechanism which provides unused memory space
for the new nodes.
❑ Garbage Collection
– Suppose some memory space becomes reusable because a node is deleted from a list or
an entire list is deleted from a program. Clearly, we want the space to be available for
future use. One way to bring this about is to immediately reinsert the space into the free-
storage list.
22. What is Overflow and Underflow?

Overflow

– Sometimes new data are to be inserted into a data structure but there is no available space.
This situation is usually called overflow.
– Overflow will occur in linked list when AVAIL = NULL and there is an insertion.

Underflow

– Underflow refers to the situation where one wants to delete data from a data structure that
is empty.
– Underflow will occur in linked lists when START= NULL and there is a deletion.

23. What is Header linked List?

❑ HEADER LINKED LISTS

A header linked list is a linked list which always contains a special node, called the header node at
beginning of the list. The following are two kinds of widely used header lists:

– A grounded header list is a header list where the last node contains the null pointer.
– A circular header list is a header list where the last node points back to the header
node.

24. What is Two way Linked List?

A two-way list is a new list structure which can be traversed in two directions:

- in the usual forward direction from the beginning of the list to the end.

- in the backward direction from the end of the list to the beginning.
25. What is a Complete Binary Tree?

A tree is said to be complete if all its levels, except possibly the last, have the maximum number of possible
nodes, and if all the nodes at the last level appear as far left as possible.

26. What is Extended Binary Tree?

A binary tree T is said to be a 2-tree or an extended binary tree if each node N has either 0 or 2 children.

27. What is Source and Sink in Graph?

⮚ A node u is called a source if it has a positive outdegree but zero indegree.


⮚ Similarly, u is called a sink if it has a zero outdegree but a positive indegree.

28. What is a Complete Graph?

A graph G is said to be complete if every node u in G is adjacent to every other node v in G.

29. What is a Weighted graph?

A graph G is said to be labeled if its edges are assigned data.

30. What is the meaning of stack?

A stack is a widely used data structure that provides users with the ability to work with data at one point
only that is the top element.

31. What is the working of LIFO?

LIFO stands for the Last in, First out access order. It is directly corresponding to how the data can be worked
on and modified. The data entity that is stored or pushed in last is the first one to be worked on at any point
in time. If there is a requirement to access the very first element stored, then first you have to retrieve all of
the data that came in after that element.
32. What is a Binary Search Tree?

A binary search tree is a data structure that stores data in a very efficient manner. It consists of two primary
nodes from the root node. The main thing here is that the values of the nodes in the left sub-tree are less
in number than the value of the root node, and the values of the nodes on the right of the root node are
correspondingly higher than the root. Also, individually both of these left and right sub-trees are their own
binary search trees at all points of time.

33. What is the meaning of FIFO?

FIFO, also known as First in, First out, is a way of representing a data operation on factors such as how data
is accessed and in what order. Here, the data that is first put into the list will be the first entity to exit from
the ordered data structure.

34. What is the difference between void and null in Data Structures?

Void is a data type identifier in data structures, while null is considered to be a value with no physical
presence. When void is used, it indicates that there is no size while initializing the data structure.

35. What are push and pop operations in Data Structures?

Both push and pop operations denote how data can be stored and used when required in a stack. The push
operation denotes that users are adding data into the structure, and the pop operation denotes that the
data is being pulled or removed from the structure. Usually, the top-most element is considered when
performing push and pop operations.

36. How is a variable stored in memory when using Data Structures?

A variable is stored based on the amount of memory that is needed. First, the required quantity of memory
is assigned, and later, it is stored based on the data structure being used. Using concepts such as dynamic
allocation ensures high efficiency and that the storage units can be supplied based on the requirements in
real time.
37. What is merge sort?

Merge sort is a method of sorting, which is based on the divide and conquer technique. Here, data entities
adjacent to each other are first merged and sorted in every iteration to create sorted lists. These smaller
sorted lists are combined at the end to form the completely sorted list.

38. What is the meaning of a post-fix expression in Data Structures?

Post-fix expressions are used in a scenario where every operator is preceded by its operands. Using this
ensures to eliminate the need for parentheses or sub-expressions when it comes to the concept of operator
precedence.

39. What is the use of dynamic Data Structures?

Dynamic data structures provide users with a lot of flexibility in terms of the provision of data storage and
manipulation techniques, which can change during the operation of the algorithm or the execution of the
program.

40. What is the meaning of an AVL tree?

An AVL tree is a type of a binary search tree where the tree is only slightly balanced. Balance is the unit of
comparison between the heights of the subtrees from the main (root) node.

41. How does Huffman’s algorithm work?

Huffman’s algorithm uses a table, containing the frequency of the occurrence of every data entity on the
list. This is used for creating extended binary trees, which are known to have minimum weights for the path
lengths . This is considering each of the corresponding weights.

Next up on this compilation of top Data Structures interview questions, we can check out the questions
categorized as advanced.

42. What are recursive algorithms?

Recursive algorithms are algorithms that solve a problem by breaking it down into simpler sub-problems
and then solving them iteratively. The output of one recursion operation is usually the direct input for the
next iteration operation, and this process goes on.
43. How does bubble sort work?

Bubble sort is one of the most used sorting techniques out there. It is applied to arrays where elements
adjacent to each other are compared and values are exchanged based on the order of arrangement. It’s
called bubble sort because of the concept of exchanging elements like a bubble floating to the top of the
water and larger entities sinking down to the bottom end.

44. Which is the fastest sorting algorithm available?

Among the many types of algorithms such as bubble sort, quick sort, merge sort, and more, it is not right
to put one method on the podium for performance as this greatly varies based on data, the reaction after
the algorithm processes the data, and how it’s stored. The concept of time complexity is considered here.

45. What is the postfix form of: (X + Y) * ( Z - C)

The postfix form of the given expression is XY+ZC-

46. Where are Tree Data Structures used?

Tree data structures are used in a variety of applications. Following are some of them:

• Arithmetic expression handling


• Symbol table creation
• Lexical analysis
• Hierarchical data modeling

Next on this Data Structures and Algorithms interview questions is a question that is commonly asked, so
pay attention.

47. What are the Data Structures that are used in graphs?

To implement graphs, two data structures play a key role. They are:

• Adjacency matrix: Used for sequential data representation


• Adjacency list: Used to represent linked data
48. What are the Data Structures that are used in DFS and BFS algorithms?

In the depth-first search (DFS), the stack data structure is made use of.

In the case of the breadth-first search (BFS) technique, queues are used.

49. What are the time complexities of linear search and binary search?

Binary search is more effective as it takes lesser comparisons to search for an element in an array. The time
complexity for linear search is O(n), while it is O(log n) for binary search.

50. What are the disadvantages of implementing queues using arrays?

There are two main downsides when implementing queues using arrays. They are as follows:

• Array sizing: The queue has to be constantly extended to make way for more elements that
get implemented. Always extending the size of the array will not be feasible as there will be a
discrepancy in the creation of the correct array size.
• Memory dumps: The memory that is used to store the queue elements cannot be reused to
actually store the queue. This is because of the working of queues where insertion happens
at the head node only.

51. Give us one advantage of linked list?

One inherent advantage of linked list is that it is very easy to modify irrespective of the number of elements
that are there in the list.

52. What is the least number of nodes that a binary tree can have?

A binary tree can have zero nodes as the least number. Further, the number can be increased to 1 or 2
nodes.

53. When is a binary search best applied?

A binary search is an algorithm that is best applied to search a list when the elements are already in order
or sorted.
54. What is the advantage of the heap over a stack?

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.

55. What are doubly linked lists?

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.

56. What is Huffman’s algorithm?

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.

57. Why we need to do algorithm analysis?

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.

58. What is asymptotic analysis of an algorithm?

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.

59. What are asymptotic notations?

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

Best case is represented by Ω(n) notation.

Worst case is represented by Ο(n) notation.

Average case is represented by Θ(n) notation.


60. 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

61. 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

62. What are some examples of divide and conquer algorithms?

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)


63. What are some examples of dynamic programming algorithms?

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

64. Why do we use stacks?

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.

65. Why do we use queues?

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.

66. What is bubble sort and how bubble sort works?

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.
67. Tell me something about 'insertion sort'?

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.

68. What is selection sort?

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.

69. How insertion sort and selection sorts are different?

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.

70. What is merge sort and how it works?

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 Ο(n log n) and it needs Ο(n) auxiliary space.

71. What is shell sort?

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 Ο(n log
n).
72. How quick sort works?

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.

73. What is a graph?

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.

74. What is a binary search tree?

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.

75. What is an AVL Tree?

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.

76. What is a spanning tree?

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.

77. How many spanning trees can a graph has?

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.

78. What is a heap in data structure?

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.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy