0% found this document useful (0 votes)
8 views8 pages

DS Viva Questions and Answers

The document provides an overview of data structures, including definitions and comparisons of various types such as linear and non-linear structures, stacks, queues, trees, and hashing. It discusses concepts like abstract data types, time complexities of algorithms, and specific implementations like linked lists and binary search trees. Additionally, it covers applications and advantages of different data structures, as well as collision resolution techniques in hashing.

Uploaded by

sarojinidevi.cse
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)
8 views8 pages

DS Viva Questions and Answers

The document provides an overview of data structures, including definitions and comparisons of various types such as linear and non-linear structures, stacks, queues, trees, and hashing. It discusses concepts like abstract data types, time complexities of algorithms, and specific implementations like linked lists and binary search trees. Additionally, it covers applications and advantages of different data structures, as well as collision resolution techniques in hashing.

Uploaded by

sarojinidevi.cse
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/ 8

Unit I: Introduction to Data Structures

1. What is a data structure?


A data structure is a way of organizing, managing, and storing data efficiently so that it can be
accessed and modified effectively.

2. Define abstract data type (ADT).


An ADT is a theoretical model for a data type, where only behavior (operations) is defined but
not the implementation.

3. Differentiate between linear and non-linear data structures.


Linear data structures store data in a sequential manner (e.g., arrays, linked lists), while non-
linear structures store data hierarchically (e.g., trees, graphs).

4. What is the time complexity of binary search?


The time complexity of binary search is O(log n) in the best and average case, assuming sorted
data.

5. Name three sorting algorithms and mention their average time complexities.

 Bubble Sort – O(n²)


 Selection Sort – O(n²)
 Insertion Sort – O(n²)

Unit II: Linked Lists


1. What are the advantages of linked lists over arrays?
Dynamic size and ease of insertion/deletion.

2. Explain a circular linked list.


In a circular linked list, the last node points to the first node, forming a circle.

3. How is a node defined in a singly linked list in C?

c
CopyEdit
struct Node {
int data;
struct Node* next;
};

4. Can we traverse a singly linked list backward? Why not?


No, because each node only stores a pointer to the next node, not the previous one.
5. What are the use cases of linked lists?
Dynamic memory allocation, implementing stacks/queues, memory-efficient data structures.

Unit III: Stacks


1. Define stack. What is its principle?
A stack is a linear data structure that follows the LIFO (Last In First Out) principle.

2. List any two applications of stacks.

 Expression evaluation
 Undo operation in editors

3. How can you implement a stack using linked list?


By adding or removing elements at the head of the list (push/pop operations).

4. What is postfix notation?


Postfix is an expression notation where the operator comes after the operands, e.g., AB+.

5. What happens when you try to pop from an empty stack?


A stack underflow condition occurs.

Unit IV: Queues and Deques


1. What is a queue?
A queue is a linear data structure that follows the FIFO (First In First Out) principle.

2. What are deques?


Deques (Double Ended Queues) allow insertion and deletion from both front and rear.

3. Name some applications of queues.


Job scheduling, BFS in graphs, resource management.

4. Differentiate between circular and linear queue.


In a circular queue, the last position is connected back to the first, optimizing space.

5. What is priority queue?


A data structure where each element has a priority and is served based on priority rather than
FIFO.
Unit V: Trees and Hashing
1. What is a binary search tree (BST)?
A tree where each node has at most two children, and the left child has lesser value than the
parent, right child has greater.

2. List three types of binary trees.


Full binary tree, complete binary tree, perfect binary tree.

3. Define hashing.
Hashing is a technique used to uniquely identify a specific object from a group of similar objects
using a hash function.

4. What are collision resolution techniques?

 Chaining
 Open Addressing (Linear probing, Quadratic probing, Double hashing)

5. Mention applications of hashing.


Symbol tables, caches, unique ID generation, password storage.

UNIT I: Introduction to Data Structures

1. Explain Abstract Data Types (ADT) with examples.

Answer:
An Abstract Data Type defines the logical behavior of a data structure without specifying
implementation.
Example:

 Stack ADT: Operations: push(), pop(), peek()


 Queue ADT: Operations: enqueue(), dequeue(), peek()
The actual implementation can vary (array or linked list).

2. Compare Linear Search and Binary Search. Which is better and when?
Feature Linear Search Binary Search

Time Complexity O(n) O(log n)

Requirement No order needed Sorted array

Best Use Small datasets Large, sorted datasets


Binary Search is better for sorted data as it reduces comparisons exponentially.

3. Discuss Sorting Techniques with time complexities.


Algorithm Best Average Worst Space Stable

Bubble Sort O(n) O(n²) O(n²) O(1) Yes

Selection Sort O(n²) O(n²) O(n²) O(1) No

Insertion Sort O(n) O(n²) O(n²) O(1) Yes

Best Technique: Use Insertion Sort for small datasets or nearly sorted arrays.

UNIT II: Linked Lists

1. How are Singly, Doubly, and Circular Linked Lists different?


Type Direction Memory Traversal Applications

Singly One way 1 pointer Forward only Stacks, dynamic arrays

Doubly Two way 2 pointers Forward/backward Navigators, undo

Circular Circular end 1 or 2 pointers Circular Scheduling, buffers

Best Technique: Use Doubly Linked Lists when bidirectional access is needed.

2. Explain node insertion in a singly linked list.

 At beginning: O(1)
 At end: O(n)
 After specific node: O(1)

c
CopyEdit
newNode->next = current->next;
current->next = newNode;
3. Compare arrays and linked lists.
Feature Array Linked List

Size Fixed Dynamic

Access Time O(1) O(n)

Insert/Delete O(n) O(1) (at head)

Memory Contiguous Non-contiguous

Linked Lists are preferred for frequent insertions/deletions.

UNIT III: Stacks

1. Implement stack using arrays and linked list. Compare both.

 Array:

c
CopyEdit
top++;
stack[top] = value; // push
value = stack[top]; top--; // pop

 Linked List:

c
CopyEdit
push: insert at head
pop: delete from head
Feature Array Linked List

Size Fixed Dynamic

Overflow Possible No (until memory full)

Underflow Possible Possible

Best Practice: Use linked list if memory flexibility is required.


2. Explain expression evaluation using stack.

Postfix Evaluation:

1. Scan expression left to right.


2. If operand: push.
3. If operator: pop two, apply, push result.
4. Result at top.

Time Complexity: O(n)

UNIT IV: Queues and Deques

1. Compare Circular Queue and Linear Queue.


Feature Linear Queue Circular Queue

Overflow At rear end Efficient reuse

Space Utilization Poor Good

Time Complexity O(1) O(1)

Best Technique: Use circular queue to avoid unused space.

2. What is a deque? Explain types.

Deque: Double Ended Queue

 Input-restricted: insert rear, delete both ends


 Output-restricted: insert both ends, delete front

Operations:

 insertFront(), insertRear(), deleteFront(), deleteRear()

Time Complexity: O(1) for all operations in linked-list implementation.


UNIT V: Trees and Hashing

1. What is a Binary Search Tree (BST)?

 Each node has:


o Left < Node < Right
 Insertion, Search, Deletion: O(log n) average, O(n) worst (skewed tree)

Best Practice: Use self-balancing trees (AVL/B-Trees) to maintain O(log n).

2. Discuss tree traversal methods with complexity.


Traversal Order Use

Inorder L-N-R Sorted output

Preorder N-L-R Copy of tree

Postorder L-R-N Delete tree

Time Complexity: O(n)


Space Complexity: O(h), where h = height

3. Explain Hashing and techniques to resolve collision.

Hash Function: index = key % table_size

Collision Resolution:

 Chaining: Linked list at each index → O(n/k)


 Open Addressing:
o Linear Probing: (h + i) % m
o Quadratic: (h + i²) % m
o Double Hashing: h1(k) + i*h2(k)

Technique Space Time Issue

Chaining Extra memory Efficient Cache inefficient

Open Addressing In-place Slower at high load Clustering

Best Technique: Use Double Hashing for minimal clustering and high load factors.

You might also like