0% found this document useful (0 votes)
6 views2 pages

Micro Copy DS

The document covers key concepts in data structures, including trees, graphs, sorting algorithms, and searching algorithms. It explains binary trees, AVL trees, traversal techniques, and the differences between directed and undirected graphs, as well as BFS and DFS. Additionally, it discusses various sorting algorithms, their efficiencies, and the significance of Big O notation in analyzing time and space complexities.

Uploaded by

hakeemab49
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)
6 views2 pages

Micro Copy DS

The document covers key concepts in data structures, including trees, graphs, sorting algorithms, and searching algorithms. It explains binary trees, AVL trees, traversal techniques, and the differences between directed and undirected graphs, as well as BFS and DFS. Additionally, it discusses various sorting algorithms, their efficiencies, and the significance of Big O notation in analyzing time and space complexities.

Uploaded by

hakeemab49
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/ 2

Data Structures Data Structures Data Structures

1. Trees 1. Trees 1. Trees


Q1: What is a binary tree, and how does it differ from a binary Q1: What is a binary tree, and how does it differ from a binary Q1: What is a binary tree, and how does it differ from a binary
search tree (BST)? search tree (BST)? search tree (BST)?
A: A binary tree is a hierarchical data structure where each node A: A binary tree is a hierarchical data structure where each node A: A binary tree is a hierarchical data structure where each node
has at most two children. A BST is a binary tree with a sorting has at most two children. A BST is a binary tree with a sorting has at most two children. A BST is a binary tree with a sorting
rule: the left child contains values smaller than the parent, and rule: the left child contains values smaller than the parent, and rule: the left child contains values smaller than the parent, and
the right child contains values larger. the right child contains values larger. the right child contains values larger.

Q2: What are the different types of tree traversal techniques? Q2: What are the different types of tree traversal techniques? Q2: What are the different types of tree traversal techniques?
A: A: A:
1.Inorder Traversal (Left → Root → Right) – Used for BSTs to 1.Inorder Traversal (Left → Root → Right) – Used for BSTs to 1.Inorder Traversal (Left → Root → Right) – Used for BSTs to
retrieve sorted order. retrieve sorted order. retrieve sorted order.
2.Preorder Traversal (Root → Left → Right) – Used for copying 2.Preorder Traversal (Root → Left → Right) – Used for copying 2.Preorder Traversal (Root → Left → Right) – Used for copying
trees. trees. trees.
3.Postorder Traversal (Left → Right → Root) – Used for deleting 3.Postorder Traversal (Left → Right → Root) – Used for deleting 3.Postorder Traversal (Left → Right → Root) – Used for deleting
trees. trees. trees.

Q3: What is an AVL tree, and why is it useful? Q3: What is an AVL tree, and why is it useful? Q3: What is an AVL tree, and why is it useful?
A: An AVL tree is a self-balancing binary search tree. It maintains A: An AVL tree is a self-balancing binary search tree. It maintains A: An AVL tree is a self-balancing binary search tree. It maintains
balance through rotations, ensuring O(log n) time complexity for balance through rotations, ensuring O(log n) time complexity for balance through rotations, ensuring O(log n) time complexity for
operations. operations. operations.

2. Graphs 2. Graphs 2. Graphs


Q4: What is the difference between a directed and an undirected Q4: What is the difference between a directed and an undirected Q4: What is the difference between a directed and an undirected
graph? graph? graph?
A: In a directed graph, edges have a direction (one-way A: In a directed graph, edges have a direction (one-way A: In a directed graph, edges have a direction (one-way
connection), whereas in an undirected graph, edges allow connection), whereas in an undirected graph, edges allow connection), whereas in an undirected graph, edges allow
two-way connections. two-way connections. two-way connections.

Q5: Explain the difference between BFS and DFS in graph Q5: Explain the difference between BFS and DFS in graph Q5: Explain the difference between BFS and DFS in graph
traversal. traversal. traversal.
A: A: A:
•Breadth-First Search (BFS) explores level by level using a queue •Breadth-First Search (BFS) explores level by level using a queue •Breadth-First Search (BFS) explores level by level using a queue
(useful for shortest paths). (useful for shortest paths). (useful for shortest paths).
•Depth-First Search (DFS) explores deeper nodes first using •Depth-First Search (DFS) explores deeper nodes first using •Depth-First Search (DFS) explores deeper nodes first using
recursion or a stack (useful for pathfinding). recursion or a stack (useful for pathfinding). recursion or a stack (useful for pathfinding).

Q6: What is an adjacency matrix, and how does it compare to an Q6: What is an adjacency matrix, and how does it compare to an Q6: What is an adjacency matrix, and how does it compare to an
adjacency list? adjacency list? adjacency list?
A: A: A:
•Adjacency Matrix: Uses a 2D array to represent connections •Adjacency Matrix: Uses a 2D array to represent connections •Adjacency Matrix: Uses a 2D array to represent connections
(space complexity O(V²)). (space complexity O(V²)). (space complexity O(V²)).
•Adjacency List: Uses linked lists to store neighbors (space •Adjacency List: Uses linked lists to store neighbors (space •Adjacency List: Uses linked lists to store neighbors (space
complexity O(V + E)). complexity O(V + E)). complexity O(V + E)).

3. Sorting Algorithms 3. Sorting Algorithms 3. Sorting Algorithms


Q7: How does Bubble Sort work, and why is it inefficient? Q7: How does Bubble Sort work, and why is it inefficient? Q7: How does Bubble Sort work, and why is it inefficient?
A: Bubble Sort repeatedly swaps adjacent elements if they are out A: Bubble Sort repeatedly swaps adjacent elements if they are out A: Bubble Sort repeatedly swaps adjacent elements if they are out
of order. It has O(n²) time complexity, making it slow for large of order. It has O(n²) time complexity, making it slow for large of order. It has O(n²) time complexity, making it slow for large
datasets. datasets. datasets.

Data Structures Data Structures Data Structures


1. Trees 1. Trees 1. Trees
Q1: What is a binary tree, and how does it differ from a binary Q1: What is a binary tree, and how does it differ from a binary Q1: What is a binary tree, and how does it differ from a binary
search tree (BST)? search tree (BST)? search tree (BST)?
A: A binary tree is a hierarchical data structure where each node A: A binary tree is a hierarchical data structure where each node A: A binary tree is a hierarchical data structure where each node
has at most two children. A BST is a binary tree with a sorting has at most two children. A BST is a binary tree with a sorting has at most two children. A BST is a binary tree with a sorting
rule: the left child contains values smaller than the parent, and rule: the left child contains values smaller than the parent, and rule: the left child contains values smaller than the parent, and
the right child contains values larger. the right child contains values larger. the right child contains values larger.

Q2: What are the different types of tree traversal techniques? Q2: What are the different types of tree traversal techniques? Q2: What are the different types of tree traversal techniques?
A: A: A:
1.Inorder Traversal (Left → Root → Right) – Used for BSTs to 1.Inorder Traversal (Left → Root → Right) – Used for BSTs to 1.Inorder Traversal (Left → Root → Right) – Used for BSTs to
retrieve sorted order. retrieve sorted order. retrieve sorted order.
2.Preorder Traversal (Root → Left → Right) – Used for copying 2.Preorder Traversal (Root → Left → Right) – Used for copying 2.Preorder Traversal (Root → Left → Right) – Used for copying
trees. trees. trees.
3.Postorder Traversal (Left → Right → Root) – Used for deleting 3.Postorder Traversal (Left → Right → Root) – Used for deleting 3.Postorder Traversal (Left → Right → Root) – Used for deleting
trees. trees. trees.

Q3: What is an AVL tree, and why is it useful? Q3: What is an AVL tree, and why is it useful? Q3: What is an AVL tree, and why is it useful?
A: An AVL tree is a self-balancing binary search tree. It maintains A: An AVL tree is a self-balancing binary search tree. It maintains A: An AVL tree is a self-balancing binary search tree. It maintains
balance through rotations, ensuring O(log n) time complexity for balance through rotations, ensuring O(log n) time complexity for balance through rotations, ensuring O(log n) time complexity for
operations. operations. operations.

2. Graphs 2. Graphs 2. Graphs


Q4: What is the difference between a directed and an undirected Q4: What is the difference between a directed and an undirected Q4: What is the difference between a directed and an undirected
graph? graph? graph?
A: In a directed graph, edges have a direction (one-way A: In a directed graph, edges have a direction (one-way A: In a directed graph, edges have a direction (one-way
connection), whereas in an undirected graph, edges allow connection), whereas in an undirected graph, edges allow connection), whereas in an undirected graph, edges allow
two-way connections. two-way connections. two-way connections.

Q5: Explain the difference between BFS and DFS in graph Q5: Explain the difference between BFS and DFS in graph Q5: Explain the difference between BFS and DFS in graph
traversal. traversal. traversal.
A: A: A:
•Breadth-First Search (BFS) explores level by level using a queue •Breadth-First Search (BFS) explores level by level using a queue •Breadth-First Search (BFS) explores level by level using a queue
(useful for shortest paths). (useful for shortest paths). (useful for shortest paths).
•Depth-First Search (DFS) explores deeper nodes first using •Depth-First Search (DFS) explores deeper nodes first using •Depth-First Search (DFS) explores deeper nodes first using
recursion or a stack (useful for pathfinding). recursion or a stack (useful for pathfinding). recursion or a stack (useful for pathfinding).

Q6: What is an adjacency matrix, and how does it compare to an Q6: What is an adjacency matrix, and how does it compare to an Q6: What is an adjacency matrix, and how does it compare to an
adjacency list? adjacency list? adjacency list?
A: A: A:
•Adjacency Matrix: Uses a 2D array to represent connections •Adjacency Matrix: Uses a 2D array to represent connections •Adjacency Matrix: Uses a 2D array to represent connections
(space complexity O(V²)). (space complexity O(V²)). (space complexity O(V²)).
•Adjacency List: Uses linked lists to store neighbors (space •Adjacency List: Uses linked lists to store neighbors (space •Adjacency List: Uses linked lists to store neighbors (space
complexity O(V + E)). complexity O(V + E)). complexity O(V + E)).

3. Sorting Algorithms 3. Sorting Algorithms 3. Sorting Algorithms


Q7: How does Bubble Sort work, and why is it inefficient? Q7: How does Bubble Sort work, and why is it inefficient? Q7: How does Bubble Sort work, and why is it inefficient?
A: Bubble Sort repeatedly swaps adjacent elements if they are out A: Bubble Sort repeatedly swaps adjacent elements if they are out A: Bubble Sort repeatedly swaps adjacent elements if they are out
of order. It has O(n²) time complexity, making it slow for large of order. It has O(n²) time complexity, making it slow for large of order. It has O(n²) time complexity, making it slow for large
datasets. datasets. datasets.
Q8: What is the primary advantage of Quick Sort over Bubble Q8: What is the primary advantage of Quick Sort over Bubble Q8: What is the primary advantage of Quick Sort over Bubble
Sort? Sort? Sort?
A: Quick Sort uses a divide-and-conquer approach for sorting, A: Quick Sort uses a divide-and-conquer approach for sorting, A: Quick Sort uses a divide-and-conquer approach for sorting,
achieving an average O(n log n) complexity, making it achieving an average O(n log n) complexity, making it achieving an average O(n log n) complexity, making it
significantly faster than Bubble Sort. significantly faster than Bubble Sort. significantly faster than Bubble Sort.

Q9: Which sorting algorithm is best for nearly sorted data? Q9: Which sorting algorithm is best for nearly sorted data? Q9: Which sorting algorithm is best for nearly sorted data?
A: Insertion Sort works well for nearly sorted data, as it has a A: Insertion Sort works well for nearly sorted data, as it has a A: Insertion Sort works well for nearly sorted data, as it has a
best-case complexity of O(n) when elements are mostly in order. best-case complexity of O(n) when elements are mostly in order. best-case complexity of O(n) when elements are mostly in order.

Q10: How does Merge Sort differ from Quick Sort in terms of Q10: How does Merge Sort differ from Quick Sort in terms of Q10: How does Merge Sort differ from Quick Sort in terms of
stability? stability? stability?
A: Merge Sort is stable (preserves order of equal elements), while A: Merge Sort is stable (preserves order of equal elements), while A: Merge Sort is stable (preserves order of equal elements), while
Quick Sort is unstable unless modified. Quick Sort is unstable unless modified. Quick Sort is unstable unless modified.

Q11: What is the key feature of Heap Sort? Q11: What is the key feature of Heap Sort? Q11: What is the key feature of Heap Sort?
A: Heap Sort uses a heap data structure to extract the A: Heap Sort uses a heap data structure to extract the A: Heap Sort uses a heap data structure to extract the
smallest/largest element, with O(n log n) complexity. smallest/largest element, with O(n log n) complexity. smallest/largest element, with O(n log n) complexity.

Q12: When is Radix Sort preferred? Q12: When is Radix Sort preferred? Q12: When is Radix Sort preferred?
A: Radix Sort works best for sorting large integers or A: Radix Sort works best for sorting large integers or A: Radix Sort works best for sorting large integers or
fixed-length strings, achieving O(nk) complexity. fixed-length strings, achieving O(nk) complexity. fixed-length strings, achieving O(nk) complexity.

4. Searching Algorithms 4. Searching Algorithms 4. Searching Algorithms


Q13: Compare Linear Search and Binary Search in terms of Q13: Compare Linear Search and Binary Search in terms of Q13: Compare Linear Search and Binary Search in terms of
efficiency. efficiency. efficiency.
A: A: A:
•Linear Search: Checks each element (O(n)) – useful for unsorted •Linear Search: Checks each element (O(n)) – useful for unsorted •Linear Search: Checks each element (O(n)) – useful for unsorted
lists. lists. lists.
•Binary Search: Divides search space (O(log n)) – requires sorted •Binary Search: Divides search space (O(log n)) – requires sorted •Binary Search: Divides search space (O(log n)) – requires sorted
data. data. data.

Q14: Why is binary search preferred over linear search? Q14: Why is binary search preferred over linear search? Q14: Why is binary search preferred over linear search?
A: Binary search is much faster for large datasets since it reduces A: Binary search is much faster for large datasets since it reduces A: Binary search is much faster for large datasets since it reduces
the problem size logarithmically. the problem size logarithmically. the problem size logarithmically.

5. Big O Notation & Time/Space Complexities 5. Big O Notation & Time/Space Complexities 5. Big O Notation & Time/Space Complexities
Q15: Define Big O notation. Q15: Define Big O notation. Q15: Define Big O notation.
A: Big O notation expresses an algorithm’s worst-case A: Big O notation expresses an algorithm’s worst-case A: Big O notation expresses an algorithm’s worst-case
complexity, describing how performance scales with input size. complexity, describing how performance scales with input size. complexity, describing how performance scales with input size.

Q16: Rank the following complexities from fastest to slowest: Q16: Rank the following complexities from fastest to slowest: Q16: Rank the following complexities from fastest to slowest:
O(1), O(n), O(log n), O(n²). O(1), O(n), O(log n), O(n²). O(1), O(n), O(log n), O(n²).
A: A: A:
1.O(1) – Constant time (fastest). 1.O(1) – Constant time (fastest). 1.O(1) – Constant time (fastest).
2.O(log n) – Logarithmic (binary search). 2.O(log n) – Logarithmic (binary search). 2.O(log n) – Logarithmic (binary search).
3.O(n) – Linear (loop operations). 3.O(n) – Linear (loop operations). 3.O(n) – Linear (loop operations).
4.O(n²) – Quadratic (nested loops, bubble sort). 4.O(n²) – Quadratic (nested loops, bubble sort). 4.O(n²) – Quadratic (nested loops, bubble sort).

Q17: What is the trade-off between time complexity and space Q17: What is the trade-off between time complexity and space Q17: What is the trade-off between time complexity and space
complexity? complexity? complexity?
A: Some algorithms optimize time at the cost of space (storing A: Some algorithms optimize time at the cost of space (storing A: Some algorithms optimize time at the cost of space (storing
additional structures), while others optimize space at the cost of additional structures), while others optimize space at the cost of additional structures), while others optimize space at the cost of
time. time. time.

Q8: What is the primary advantage of Quick Sort over Bubble Q8: What is the primary advantage of Quick Sort over Bubble Q8: What is the primary advantage of Quick Sort over Bubble
Sort? Sort? Sort?
A: Quick Sort uses a divide-and-conquer approach for sorting, A: Quick Sort uses a divide-and-conquer approach for sorting, A: Quick Sort uses a divide-and-conquer approach for sorting,
achieving an average O(n log n) complexity, making it achieving an average O(n log n) complexity, making it achieving an average O(n log n) complexity, making it
significantly faster than Bubble Sort. significantly faster than Bubble Sort. significantly faster than Bubble Sort.

Q9: Which sorting algorithm is best for nearly sorted data? Q9: Which sorting algorithm is best for nearly sorted data? Q9: Which sorting algorithm is best for nearly sorted data?
A: Insertion Sort works well for nearly sorted data, as it has a A: Insertion Sort works well for nearly sorted data, as it has a A: Insertion Sort works well for nearly sorted data, as it has a
best-case complexity of O(n) when elements are mostly in order. best-case complexity of O(n) when elements are mostly in order. best-case complexity of O(n) when elements are mostly in order.

Q10: How does Merge Sort differ from Quick Sort in terms of Q10: How does Merge Sort differ from Quick Sort in terms of Q10: How does Merge Sort differ from Quick Sort in terms of
stability? stability? stability?
A: Merge Sort is stable (preserves order of equal elements), while A: Merge Sort is stable (preserves order of equal elements), while A: Merge Sort is stable (preserves order of equal elements), while
Quick Sort is unstable unless modified. Quick Sort is unstable unless modified. Quick Sort is unstable unless modified.

Q11: What is the key feature of Heap Sort? Q11: What is the key feature of Heap Sort? Q11: What is the key feature of Heap Sort?
A: Heap Sort uses a heap data structure to extract the A: Heap Sort uses a heap data structure to extract the A: Heap Sort uses a heap data structure to extract the
smallest/largest element, with O(n log n) complexity. smallest/largest element, with O(n log n) complexity. smallest/largest element, with O(n log n) complexity.

Q12: When is Radix Sort preferred? Q12: When is Radix Sort preferred? Q12: When is Radix Sort preferred?
A: Radix Sort works best for sorting large integers or A: Radix Sort works best for sorting large integers or A: Radix Sort works best for sorting large integers or
fixed-length strings, achieving O(nk) complexity. fixed-length strings, achieving O(nk) complexity. fixed-length strings, achieving O(nk) complexity.

4. Searching Algorithms 4. Searching Algorithms 4. Searching Algorithms


Q13: Compare Linear Search and Binary Search in terms of Q13: Compare Linear Search and Binary Search in terms of Q13: Compare Linear Search and Binary Search in terms of
efficiency. efficiency. efficiency.
A: A: A:
•Linear Search: Checks each element (O(n)) – useful for unsorted •Linear Search: Checks each element (O(n)) – useful for unsorted •Linear Search: Checks each element (O(n)) – useful for unsorted
lists. lists. lists.
•Binary Search: Divides search space (O(log n)) – requires sorted •Binary Search: Divides search space (O(log n)) – requires sorted •Binary Search: Divides search space (O(log n)) – requires sorted
data. data. data.

Q14: Why is binary search preferred over linear search? Q14: Why is binary search preferred over linear search? Q14: Why is binary search preferred over linear search?
A: Binary search is much faster for large datasets since it reduces A: Binary search is much faster for large datasets since it reduces A: Binary search is much faster for large datasets since it reduces
the problem size logarithmically. the problem size logarithmically. the problem size logarithmically.

5. Big O Notation & Time/Space Complexities 5. Big O Notation & Time/Space Complexities 5. Big O Notation & Time/Space Complexities
Q15: Define Big O notation. Q15: Define Big O notation. Q15: Define Big O notation.
A: Big O notation expresses an algorithm’s worst-case A: Big O notation expresses an algorithm’s worst-case A: Big O notation expresses an algorithm’s worst-case
complexity, describing how performance scales with input size. complexity, describing how performance scales with input size. complexity, describing how performance scales with input size.

Q16: Rank the following complexities from fastest to slowest: Q16: Rank the following complexities from fastest to slowest: Q16: Rank the following complexities from fastest to slowest:
O(1), O(n), O(log n), O(n²). O(1), O(n), O(log n), O(n²). O(1), O(n), O(log n), O(n²).
A: A: A:
1.O(1) – Constant time (fastest). 1.O(1) – Constant time (fastest). 1.O(1) – Constant time (fastest).
2.O(log n) – Logarithmic (binary search). 2.O(log n) – Logarithmic (binary search). 2.O(log n) – Logarithmic (binary search).
3.O(n) – Linear (loop operations). 3.O(n) – Linear (loop operations). 3.O(n) – Linear (loop operations).
4.O(n²) – Quadratic (nested loops, bubble sort). 4.O(n²) – Quadratic (nested loops, bubble sort). 4.O(n²) – Quadratic (nested loops, bubble sort).

Q17: What is the trade-off between time complexity and space Q17: What is the trade-off between time complexity and space Q17: What is the trade-off between time complexity and space
complexity? complexity? complexity?
A: Some algorithms optimize time at the cost of space (storing A: Some algorithms optimize time at the cost of space (storing A: Some algorithms optimize time at the cost of space (storing
additional structures), while others optimize space at the cost of additional structures), while others optimize space at the cost of additional structures), while others optimize space at the cost of
time. time. time.

You might also like