0% found this document useful (0 votes)
8 views

Data Structures Lab- Viva

The document provides a comprehensive overview of data structures, including definitions, types, and applications. It covers linear and non-linear data structures, algorithms, and specific structures like arrays, linked lists, stacks, queues, trees, and graphs. Additionally, it discusses concepts like recursion, hashing, and various tree and graph types, along with their applications.

Uploaded by

bindushreekj
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Data Structures Lab- Viva

The document provides a comprehensive overview of data structures, including definitions, types, and applications. It covers linear and non-linear data structures, algorithms, and specific structures like arrays, linked lists, stacks, queues, trees, and graphs. Additionally, it discusses concepts like recursion, hashing, and various tree and graph types, along with their applications.

Uploaded by

bindushreekj
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

MAHARAJA INSTITUTE OF TECHNOLOGY MYSORE

Belawadi, Naguvanahalli Post, Srirangapatna Taluk, Mandya – 571477

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING(ARTIFICIAL INTELLIGENCE)

Data Structures Lab [M23BCSL307]


Viva question and answers

1. What is a data structure?


A data structure is a way of organizing, storing, and managing data efficiently for performing
operations like searching, insertion, deletion, and sorting. It helps in organizing data to use it
efficiently.
2. What are the different types of Data Structures and give examples?
There are two types of Data Structures:
Linear Data Structures:
A data structure is said to be linear if the elements form a sequence. It is sequential and
continues in nature i.e. access the data in sequential manner. In linear data structure we cannot
insert an item in middle place and it maintains a linear relationship between its elements
egs: Array, Linked list, Stack, Queue, Dequeue etc.
Non Linear Data Structures:
A data structure is said to be non-linear if elements do not form a sequence. (Not sequential).
It does not maintain any linear relationship between their elements. Every data item is attached to several other data
items in a way that is specific for reflecting relationships. The data items are not arranged in a sequential structure.
egs: Trees, Graphs.
3. Define ADT?
An abstract data type is a set of objects together with a set of operations. Abstract data types are
mathematical abstraction. Objects such as lists, sets, graphs, trees can be viewed as abstract data
types.
4. What are some applications of Data Structures?
Numerical analysis, Operating system, AI, Compiler Design, Database management, Graphics,
Statistical analysis and simulation.
5. What is an array?
An array is a collection of elements of the same data type stored in contiguous memory
locations. It allows random access to elements using an index.
6. What are the advantages of using an array?
 Easy access to elements via indices.
 Efficient memory utilization.
 Fast searching for elements.
7. What is a linked list?
A linked list is a linear data structure where each element (node) contains data and a reference
(or link) to the next node in the sequence. It can dynamically grow and shrink in size.

8. Are linked lists considered linear or non-linear Data Structures?


Linked lists are considered both linear and non-linear data structures depending upon the
application they are used for. When used for access strategies, it is considered as a linear data-
structure. When used for data storage, it is considered a non-linear data structure.
9. What are the advantages of a linked list over an array?
Advantages of a linked list over an array are:
1. Insertion and Deletion Insertion and deletion of nodes is an easier process, as we only update
the address present in the next pointer of a node. Its expensive to do the same in an array as the
room has to be created for the new elements and existing elements must be shifted.
2. Dynamic Data Structure As a linked list is a dynamic data structure, there is no need to give
an initial size as it can grow and shrink at runtime by allocating and deallocating memory.
However, the size is limited in an array as the number of elements is statically stored in the main
memory.
3. No Wastage of Memory As the size of a linked list can increase or decrease depending on the
demands of the program, and memory is allocated only when required, there is no memory
wasted. In the case of an array, there is memory wastage.
4. Implementation Data structures like stack and queues are more easily implemented using a
linked list than an array.
41. What are dynamic Data Structures? Name a few.
They are collections of data in memory that expand and contract to grow or shrink in size as a
program runs. This enables the programmer to control exactly how much memory is to be
utilized. Examples are the dynamic array, linked list, stack, queue, and heap.
10. What is an algorithm?
An algorithm is a step by step method of solving a problem or manipulating data. It defines a set
of instructions to be executed in a certain order to get the desired output.
11. What are the types of linked lists?
 Singly Linked List: Each node points to the next node.
 Doubly Linked List: Each node points to both the next and the previous node.
 Circular Linked List: The last node points to the first node, forming a circular structure.
12. What is a Singly Linked List?
Singly Linked List is a Sequence of dynamically allocated Storage elements, each element of
which contains a pointer to its successor. A pointer to the first element of the list is called as head
and a pointer to the last element of the list is called as tail used to keep track of the list elements.
13. What is Doubly Linked List?
In Doubly Linked List each element contains two pointers: One Pointer points to its
successor and another to its predecessor (previous element).It is also called as two way linked list
(traversing can be done in both directions)
14. What is a stack?
A stack is a linear data structure that follows the Last-In-First-Out (LIFO) principle. The last
element added to the stack is the first one to be removed.
15. What are the operations in a stack?
 Push: Add an element to the stack.
 Pop: Remove the top element from the stack.
 Peek/Top: View the top element without removing it.
 isEmpty: Check if the stack is empty.
16. What is Stack Underflow?
If Stack is empty and POP operation is performed it is not possible to delete the items. This
situation is called Stack Underflow.
17. What is Stack Overflow?
If Stack is full and PUSH operation is performed it is not possible to insert or Push the new
items into the stack. This situation is called Stack Overflow.
18. What are the Applications of Stack?
i) Stacks are used to convert Infix expression into Postfix. ii) Stacks are used to Evaluate
Postfix Expression.iii) Stacks are used in recursion etc.
19. What is the use of Postfix expressions?
Postfix Expressions are easy to evaluate as postfix expressions does not make use of operator
precedence not does it require the use of parenthesis.

20. What is a queue?


A queue is a linear data structure that follows the First-In-First-Out (FIFO) principle. The first
element added is the first one to be removed.
21. What are the operations in a queue?
 Enqueue: Add an element to the rear of the queue.
 Dequeue: Remove an element from the front of the queue.
 Front: View the front element without removing it.
 isEmpty: Check if the queue is empty.
22. List some applications of queue Data Structure.
To prioritize jobs as in the following scenarios: As waiting lists for a single shared resource in a
printer, CPU, call center systems, or image uploads; where the first one entered is the first to be
processed In the asynchronous transfer of data; or example pipes, file IO, and sockets As buffers
in applications like MP3 media players and CD players To maintain the playlist in media players
(to add or remove the songs), Queues are used in Breadth First Traversal of a Graph.

23. What is a Circular Queue?


A Circular Queue is a type of queue in which the last position is connected back to the first
position to form a circular structure. This helps in efficiently utilizing the available space in a
queue and prevents wastage of space, unlike a regular linear queue, where unused space
cannot be reused.
24. Differentiate Linear Queue and Circular Queue?
In Linear Queue once the queue is full and the deletion is performed, even if first position is
free(vacant) it is not possible to insert the item in that position whereas in Circular Queue it is
possible since the first position is kept behind the last position.
25. What is Dequeue? (Double Ended Queue)
In Double Ended Queue insertion and deletion are possible from both the ends.

26. What is a Tree?

A tree is a hierarchical data structure consisting of nodes connected by edges. It is a non-linear


data structure, unlike arrays or linked lists. Trees are widely used in computer science for
organizing data in a structured way to allow efficient searching, sorting, and hierarchical
relationships.

 Root: The top node of the tree, where the hierarchy starts.
 Node: Each element in the tree that contains data and pointers to other nodes (children).
 Edge: A connection between two nodes in the tree.
 Parent: A node that has one or more child nodes.
 Child: A node that is a descendant of a parent node.
 Leaf: A node that does not have any children.
 Subtree: A tree formed by a node and all its descendants.
 Height of a Tree: The length of the longest path from the root to a leaf node.
 Depth of a Node: The length of the path from the root to the node.

27. What is a binary tree?


A binary tree is a hierarchical data structure where each node has at most two children, referred
to as the left child and right child. It is used in searching and sorting algorithms.
28. What are the types of binary trees?
 Full Binary Tree: Every node has 0 or 2 children.
 Complete Binary Tree: All levels are fully filled except possibly the last level, which is
filled from left to right.
 Perfect Binary Tree: All internal nodes have two children and all leaf nodes are at the
same level.
 Binary Search Tree (BST): A binary tree where the left child is smaller and the right
child is larger than the root.
29. What is Tree Traversal? List different Tree Traversal Techniques?
Visiting all nodes of a tree exactly once in a systematic way is called Tree Traversal.
Different types of tree traversals are
 In-Order Traversal
 Pre-Order Traversal
 Post-Order Traversal
 Level-Order Traversal
30. List one application of trees (Search trees)?
Search trees are used to implement dictionaries.
31. What is a graph?
A graph is a non-linear data structure consisting of a set of nodes (vertices) and edges
(connections between nodes). Graphs can be directed or undirected and can have cycles or be
acyclic.
32. What are the types of graphs?
 Directed Graph (Digraph): The edges have a direction.
 Undirected Graph: The edges do not have a direction.
 Weighted Graph: Each edge has a weight or cost associated with it.
 Unweighted Graph: All edges are equal.
33. What is the difference between a stack and a queue?
 Stack: Follows the Last-In-First-Out (LIFO) principle.
 Queue: Follows the First-In-First-Out (FIFO) principle.
34. What is the difference between an array and a linked list?
 Array: Fixed size, stores elements in contiguous memory locations, fast access via
indices.
 Linked List: Dynamic size, stores elements in non-contiguous memory locations, slower
access due to sequential traversal.
35. Explain the concept of recursion.
Recursion is a process where a function calls itself directly or indirectly to solve a problem. A
base case is needed to terminate the recursion and prevent infinite recursion.
36. What is the difference between a binary search tree (BST) and a binary tree?
 Binary Tree: A tree where each node has at most two children, with no specific ordering
of values.
 Binary Search Tree (BST): A binary tree where for each node, the left child contains
values less than the parent node, and the right child contains values greater than the
parent node.
37. What is difference between a Graph and a Tree?
A Graph contains Cycles (loops) but a Tree does not contain any cycles.[A Tree contains a
root node but Graph does not contain the root node.]
38. What are the applications of graph Data Structure?
Graphs are used in various applications, including social networks, transportation networks,
computer networks, recommendation systems.
39. What is a Spanning Tree?
A spanning tree of a graph is a sub graph that includes all the vertices of the original graph and
is a tree (i.e., it is connected and acyclic). A spanning tree does not have any cycles, and it
connects all the vertices with the minimum number of edges possible.
40. What is a hash table?
A hash table is a data structure that stores key-value pairs. It uses a hash function to compute an
index (hash code) into an array of buckets or slots, from which the desired value can be found.
41. What are the advantages of a hash table?
 Fast lookup: Average time complexity for search, insertion, and deletion is O(1).
 Efficient memory usage due to direct addressing via hash codes.
 Ideal for scenarios where fast retrieval of data is necessary.
42. What is Hashing?
Hashing is used to determine the position of a Key by using the Key itself. To determine the
position of the key it makes use of Function called Hash function.
Hash function maps a key into a bucket in the hash table.
43. List different Hashing methods.
i) Division method
ii) Mid Square method
iii) Folding method

You might also like