Final Exam Review: Data Structures and Algorithms

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/20

flashcard set

Earn XP

Description and Tags

These flashcards cover critical concepts related to Red-Black Trees, graphs, traversal algorithms, spanning trees, and dynamic programming as per the provided lecture notes.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

21 Terms

1
New cards

What are the properties of a Red-Black Tree?

  1. Every node is either red or black. 2. The root node and leaves (NIL) are black. 3. If a node is red, then both its children are black. 4. All paths from any node to its descendant leaves contain the same number of black nodes.

2
New cards

Why do we use Red-Black Trees instead of regular binary search trees?

Red-Black Trees maintain their height at O(log n), which guarantees O(log n) time complexity for operations such as search, insert, and delete, preventing the O(n) worst-case scenario of skewed trees.

3
New cards

What defines a Directed Acyclic Graph (DAG)?

A Directed Acyclic Graph (DAG) is a graph with directed edges that does not contain any cycles.

4
New cards

What are the two ways to represent graphs?

Graphs can be represented as an Adjacency Matrix or an Adjacency List.

5
New cards

What is an advantage of using an Adjacency List?

An Adjacency List uses O(V + E) space, which is more efficient than O(V^2) when the graph has fewer edges.

6
New cards

What is the traversal order in Breadth-First Search (BFS)?

BFS explores level by level, visiting all immediate neighbors before moving to the next level.

7
New cards

What is a Minimum Spanning Tree (MST)?

A Minimum Spanning Tree is a spanning tree that has the smallest total edge weight among all possible spanning trees.

8
New cards

What is the main difference between Dijkstra's Algorithm and Bellman-Ford Algorithm?

Dijkstra's Algorithm works with graphs having non-negative edge weights, while Bellman-Ford can handle negative edge weights and detect negative cycles.

9
New cards

What is the relax operation in shortest path algorithms?

The relax operation updates the distance to a vertex if a shorter path is found via another vertex.

10
New cards

What are the components of Dynamic Programming?

  1. Optimal Substructure. 2. Overlapping Subproblems.
11
New cards

What is the key idea of the Bottom-Up approach in Dynamic Programming?

To solve all smaller problems first and build up to the final solution iteratively.

12
New cards

How is Dynamic Programming used in the Fibonacci sequence calculation?

By storing previously computed Fibonacci numbers to avoid redundant calculations, achieving a time complexity of O(n) with a Bottom-Up approach.

13
New cards

Prims Algorithm Compelxity

Array:O(V^2) with an adjacency matrix; O(E log V) with adjacency list and priority queue.

Binary heaps: O(E log V)

14
New cards

Kruksals Algorithm Complexity

O(E log V) or O(E log V), depending on the data structure used for the disjoint set operations and the graph representation.

overall complexity is O(E log E + E log V)

15
New cards

Dijkstra’s algorithm complexity

Array or linked list is O(|V|² + |E|)

sparse graph and min-Priority Queue with binary minheap is is O((|E| + |V|) log|V|)

16
New cards

Bellman Ford Complexity

overall complexity is O(|V| * |E|)

sparse graph is O(|V|²

complete graph is O(|V|³)

17
New cards

Red Black tree complexity

The average and worst-case time complexity for search, insertion, and deletion operations in a Red-Black Tree is O(log n), maintaining balanced structure.

18
New cards

AVL tree

AVL Tree is a Binary Search Tree where the difference in height between the left and right subtrees of any node is at most 1

19
New cards

Pros/Cons Adjacency List

Pros: Space-efficient for sparse graphs (few edges).

Faster iteration over a node’s neighbors.

Dynamic — easy to add/remove edges.

Cons: Slower to check if a specific edge exists (O(n) in worst case).

Slightly more complex to implement than a matrix.

20
New cards

Pros/Cons Adjacency matrix

Pros: Fast edge lookup: check if edge exists in O(1) time.

Simple and easy to implement.

Good for dense graphs (many edges).

Cons: Uses more space: O(n²), even if the graph is sparse.

Iterating over neighbors takes O(n) time per node.

Less efficient for dynamic graph changes (like inserting/removing edges).

21
New cards