0% found this document useful (0 votes)
4 views7 pages

DSA VIVA QS

Uploaded by

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

DSA VIVA QS

Uploaded by

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

Module 1: Pointers and Data Structures Fundamentals

Questions and Answers:


1. What is a pointer? A pointer is a variable that stores the memory address of another variable.
2. How do you declare a pointer in C? A pointer is declared using the * operator. For example: int *ptr;.
3. What are the advantages of using pointers?
o Dynamic memory allocation
o Efficient array handling
o Easy manipulation of data structures (e.g., linked lists, trees)
4. What is the relationship between arrays and pointers? The name of the array acts as a pointer to the first
element of the array.
5. Explain a structure in C. A structure is a user-defined data type that groups related variables of different
types. Syntax:
6. struct Example { int a; char b; };
7. What is a nested structure? A structure that contains another structure as a member.
8. How do you create an array of structures? Example:
9. struct Student { int id; char name[20]; };
10. struct Student arr[10];
11. What is a self-referential structure? A structure that contains a pointer to the same type of structure.
Example:
12. struct Node { int data; struct Node *next; };
13. How are structures passed to functions? By value or by reference using pointers.
14. What are the limitations of arrays?
o Fixed size
o Inefficient insertion and deletion operations
15. What are the key characteristics of a data structure?
o Efficiency in storage
o Ability to perform operations like insertion, deletion, searching, and traversal.
16. What is an abstract data type (ADT)? ADT is a data structure described by its behavior rather than its
implementation.
Example: Stack, Queue.
17. What are primitive data structures? Built-in data types such as int, float, char.
18. What are non-primitive data structures? User-defined data structures like arrays, linked lists, and trees.
19. What are the operations on data structures?
o Insertion
o Deletion
o Traversal
o Searching
o Sorting
20. What is dynamic memory allocation? Allocating memory at runtime using functions like malloc() and
calloc().
21. How does a pointer differ from a reference? A pointer stores the address of a variable, while a reference is
an alias for a variable.
22. Explain the sizeof operator in pointers. sizeof gives the size of the pointer type, not the data it points to.
23. What is a dangling pointer? A pointer that points to a memory location that has been deallocated.
24. What is pointer arithmetic? Operations like addition, subtraction on pointers to traverse arrays.

Module 2: Linked Lists


Questions and Answers:
1. What is a linked list? A linked list is a collection of nodes, where each node contains data and a pointer to
the next node.
2. How do you implement a singly linked list? By creating nodes with a structure and linking them using
pointers.
3. Write the structure for a node in a singly linked list.
4. struct Node { int data; struct Node *next; };
5. How is memory managed in linked lists? Memory is dynamically allocated for each node.
6. What is the difference between an array and a linked list? Arrays have a fixed size, whereas linked lists can
grow or shrink dynamically.
7. What are the advantages of a linked list?
o Dynamic size
o Efficient insertion and deletion
8. What is a circular linked list? A linked list where the last node points back to the first node.
9. How does a doubly linked list differ from a singly linked list? Doubly linked lists have pointers to both the
previous and next nodes.
10. What is the time complexity of searching in a linked list? O(n)O(n), as each node must be checked
sequentially.
11. How do you delete a node from a singly linked list? Update the pointer of the previous node to skip the
node to be deleted.
12. What is the key feature of a circular doubly linked list? Both ends of the list are connected, allowing
traversal in both directions.
13. What are sentinel nodes in linked lists? Dummy nodes used to simplify boundary conditions.
14. How do you detect a cycle in a linked list? Using the Floyd’s cycle detection algorithm (slow and fast pointer
approach).
15. What is the use of a tail pointer in linked lists? It keeps track of the last node for faster insertion.
16. How do you reverse a singly linked list? By iterating through the list and reversing the pointers of each node.
17. What is a skip list? A data structure that allows fast search by using multiple levels of linked lists.
18. Explain the concept of a sentinel node. A special node that does not store data but simplifies operations.
19. What is a sparse matrix representation using linked lists? Representing non-zero elements of a matrix using
a linked list.
20. What is the advantage of circular linked lists over singly linked lists? Efficient use in applications requiring
repetitive traversal.
21. How are linked lists used in implementing queues? By maintaining pointers to the front and rear nodes.

Module 3: Stacks and Queues


Questions and Answers:
1. What is a stack?
A stack is a linear data structure that follows the Last In, First Out (LIFO) principle.
2. What are the basic operations of a stack?
o Push: Add an element to the top of the stack.
o Pop: Remove an element from the top of the stack.
o Peek/Top: Retrieve the top element without removing it.
3. How is a stack represented in memory?
Using arrays or linked lists.
4. What is the time complexity of stack operations?
O(1)O(1) for push, pop, and peek operations.
5. What is an application of stacks in programming?
o Function call management
o Parenthesis matching
o Expression evaluation
6. What is the difference between a stack and a queue?
A stack follows LIFO, while a queue follows First In, First Out (FIFO).
7. How do you implement a stack using arrays?
By maintaining an array and a variable to track the index of the top element.
8. How do you implement a stack using linked lists?
Each node contains data and a pointer to the next node. Push and pop modify the head pointer.
9. What is recursion, and how is it related to stacks?
Recursion is a process where a function calls itself. The function call stack is used to store return addresses
and variables.
10. What is a queue?
A queue is a linear data structure that follows the FIFO principle.
11. What are the basic operations of a queue?
o Enqueue: Add an element to the rear.
o Dequeue: Remove an element from the front.
12. What is a circular queue?
A queue where the last position is connected back to the first position.
13. How do you represent a queue using arrays?
By maintaining two pointers, front and rear, to track the first and last elements.
14. What is a priority queue?
A queue where each element is associated with a priority, and elements are dequeued based on their
priority.
15. What are the applications of queues?
o Job scheduling
o Print queue management
o Breadth-First Search (BFS) in graphs
16. How do you check if a stack is empty?
By checking if the top pointer is −1-1 (for array implementation).
17. What is the difference between a linear queue and a circular queue?
o Linear Queue: Has a fixed size, and space is wasted after dequeuing.
o Circular Queue: Reuses space by connecting the rear to the front.
18. Explain the conversion of an infix expression to a postfix expression.
o Use a stack to temporarily hold operators and parentheses.
o Operands are directly added to the postfix expression.
o Pop operators based on precedence.
19. How is a postfix expression evaluated?
o Traverse the postfix expression.
o Push operands onto a stack.
o When an operator is encountered, pop two elements, apply the operator, and push the result back.
20. What is the role of a stack in function calls?
The stack stores return addresses, local variables, and parameters for each function call.

Module 4: Trees
Questions and Answers:
1. What is a tree?
A tree is a non-linear hierarchical data structure consisting of nodes, with one node as the root and zero or
more child nodes.
2. What are the different types of trees?
o Binary Tree
o Binary Search Tree (BST)
o AVL Tree
o Heap Tree
3. What is a binary tree?
A tree where each node has at most two children (left and right).
4. What are the properties of a binary tree?
o Maximum nodes at level l=2ll = 2^l
o Height hh: Maximum number of edges from the root to a leaf
5. What are tree traversals?
o In-order: Left, Root, Right
o Pre-order: Root, Left, Right
o Post-order: Left, Right, Root
6. What is a binary search tree (BST)?
A binary tree where the left child contains nodes with values less than the root, and the right child contains
nodes with values greater than the root.
7. How do you insert a node in a BST?
Recursively compare the value to be inserted with the current node and move left or right until the correct
position is found.
8. What is an AVL tree?
A self-balancing binary search tree where the height difference (balance factor) of left and right subtrees is at
most 1.
9. What is a threaded binary tree?
A binary tree where null pointers are replaced with pointers to the in-order predecessor or successor.
10. What are the applications of trees?
o Hierarchical data representation (e.g., file systems)
o Expression parsing
o Decision-making algorithms
11. What is a complete binary tree?
A binary tree where all levels except possibly the last are completely filled, and nodes are as left as possible.
12. What is a full binary tree?
A binary tree where every node has either 0 or 2 children.
13. What is a perfect binary tree?
A binary tree where all internal nodes have two children, and all leaves are at the same level.
14. What is a balanced binary tree?
A binary tree where the height difference between left and right subtrees is minimal.
15. What is a binary heap?
A complete binary tree used for heap sort, where the parent node is either greater than or smaller than its
child nodes (max heap or min heap).
16. What are the operations on a binary search tree?
o Insertion
o Deletion
o Searching
17. What is a height-balanced tree?
A tree where the height difference between subtrees of any node is at most 1.
18. What are threaded binary trees used for?
To efficiently traverse trees without recursion or stacks.
19. How is a binary tree implemented in memory?
Using linked representations with nodes containing data and pointers to child nodes.
20. What is the time complexity of searching in a binary search tree?
O(h)O(h), where hh is the height of the tree.

Module 5: Sorting and Hashing


Questions and Answers:
1. What is sorting?
Sorting is the process of arranging elements in a specific order (ascending or descending).
2. What is radix sort?
A non-comparative sorting algorithm that processes digits of numbers from the least significant to the most
significant.
3. What is heap sort?
A comparison-based sorting technique that uses a binary heap data structure.
4. What are the advantages of radix sort?
o Stable sorting
o Efficient for large datasets with fixed-length keys
5. What is hashing?
A technique for mapping data to a fixed-size table using hash functions.
6. What is a hash table?
A data structure that stores key-value pairs for efficient data retrieval.
7. What are hash functions?
Functions that compute the index for storing elements in a hash table.
8. What are the common hashing techniques?
o Division method
o Multiplication method
o Folding method
9. What is a collision in hashing?
A situation where two keys hash to the same index.
10. What are collision resolution techniques?
o Chaining
o Open addressing (linear probing, quadratic probing)
11. What are the pros and cons of hashing?
o Pros: Fast data access
o Cons: Collisions and complexity of rehashing
12. What is rehashing?
Reorganizing the hash table when the load factor exceeds a threshold.
13. What is the load factor in hashing?
The ratio of the number of elements to the size of the hash table.
14. What are applications of hashing?
o Dictionary implementation
o Database indexing
o Password storage
15. What is the time complexity of hashing operations?
o Best case: O(1)O(1)
o Worst case: O(n)O(n) (when collisions occur)
16. How is a priority queue implemented using heaps?
By using a binary heap, where elements are inserted and removed based on priority.
17. What is the difference between a max heap and a min heap?
o Max heap: Parent nodes are greater than child nodes.
o Min heap: Parent nodes are smaller than child nodes.
18. What are the key features of heap sort?
o In-place sorting
o Not stable
19. How does chaining resolve collisions in hashing?
By storing multiple elements at the same index using a linked list.
20. What is the primary difference between open addressing and chaining?
o Open addressing: Resolves collisions within the hash table.
o Chaining: Uses external data structures like linked lists.

Additional Questions
Recursion
1. What is recursion?
A function that calls itself either directly or indirectly.
2. What are the two main parts of a recursive function?
o Base case: Stops the recursion.
o Recursive case: Calls the function itself.
3. What is direct recursion?
When a function directly calls itself.
Example:
4. void func() { func(); }
5. What is indirect recursion?
When a function calls another function, which in turn calls the original function.
Example:
6. void funcA() { funcB(); }
7. void funcB() { funcA(); }
8. What is tail recursion?
A recursive function where the recursive call is the last operation performed.
Example:
void tailRecursion(int n) {
if (n == 0) return;
tailRecursion(n - 1);
}
9. What is non-tail recursion?
A recursive function where the recursive call is not the last operation.
Example:
int factorial(int n) {
if (n == 1) return 1;
return n * factorial(n - 1);
}
10. What are the applications of recursion?
o Factorial calculation
o Fibonacci sequence
o Tower of Hanoi
o Depth-First Search (DFS) in graphs
11. What are the advantages and disadvantages of recursion?
o Advantages: Simplifies code for problems like tree traversals.
o Disadvantages: High memory usage due to function call stack.

Sorting and Searching


9. What is the difference between internal and external sorting?
o Internal Sorting: All data is in main memory during sorting.
o External Sorting: Data is too large to fit in main memory and uses external storage.
10. What is bubble sort?
A sorting algorithm where adjacent elements are swapped if they are in the wrong order.
11. What is selection sort?
A sorting algorithm that selects the smallest (or largest) element from the unsorted part and places it in the
correct position.
12. What is binary search?
A search algorithm that divides the search interval in half repeatedly. Requires a sorted array.
13. What is linear search?
A search algorithm that checks each element one by one until the desired element is found.

Advanced Topics
14. What is a trie (prefix tree)?
A tree-like data structure used to store strings, often used in applications like autocomplete.
15. What is a graph?
A non-linear data structure consisting of nodes (vertices) connected by edges.
16. What are the types of graphs?
o Directed and Undirected
o Weighted and Unweighted
o Cyclic and Acyclic
17. What is Depth-First Search (DFS)?
A graph traversal technique that explores as far as possible along each branch before backtracking.
18. What is Breadth-First Search (BFS)?
A graph traversal technique that explores all neighbors at the current depth before moving deeper.
19. What is a spanning tree?
A subgraph of a graph that connects all vertices without any cycles.

General Concepts
20. What is the difference between a mutable and immutable object?
o Mutable: Can be modified after creation (e.g., lists in Python).
o Immutable: Cannot be modified after creation (e.g., strings in Python).

You might also like