U302 SAC Notes Flashcards

1
Q

What is BFS?

A

A traversal algorithm that visits all neighbours of the current node at the same time (LEVEL BY LEVEL APPROACH)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How does BFS work?

A

1) It starts from a starting vertex, enqueues it into a queue, and marks it as visited.

2) Then, it dequeues a vertex from the queue, visits it, and enqueues all its unvisited neighbors into the queue.

3) This process continues until the queue is empty.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Advantages/Applications of BFS

A

Applications:
- shortest path
- Maze

Advantages:
- easy to implement
- level by level approach is more efficient
- guarantee that every node in the graph is visited, so sol is def found

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is DFS and what ADT does it use?

A

Depth first search is a traversal algorithm that fully explores a single pathway, going all the way down, then backtracking to the other pathways until the entire graph has been traversed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is Prim’s algorithm used for?

A

Prim’s algorithm is a greedy algorithm that finds a minimum spanning tree for a WEIGHTED, UNDIRECTED, graph.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What ADT does prims use?

A

Min priority queue, to determine which edge should be connected next (greedy approach- lowest cost edge)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is Dijikstra’s Algorithm

A

Algorithm that uses a greedy approach to find the shortest paths between one node andALL THE OTHER NODES in a WEIGHTED, DIRECTED graph that are NON-NEGATIVE.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Why doesn’t Dijikstra’s work on negative weights?

A

Since Dijkstra follows a Greedy Approach, once a node is marked as visited it cannot be reconsidered even if there is another path with less cost or distance. This issue arises only if there exists a negative weight or edge in the graph.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the concept of relaxation?

A

Updating the path distance values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is Bellman-Ford’s used for?

A

Single source shortest path problem for weighted, directed graphs, and can work with negative weights.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does WARSHALL’S algorithm find?

A

Warshall’s Algorithm finds the transitive closure of a graph (whether a path exists between two nodes.)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is Floyd-Warshall’s algorithm used for?

A

Finds the shortest path for all pairs of nodes in the graph.

The algorithm checks if a path through an intermediate vertex offers a shorter distance between two nodes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is dynamic programming?

A

The algorithm is first broken down into sub-problems and then the sub-problems are optimised to find the overall solution

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is backtracking

A

generating possible solutions to a problem and then going back and regenerating a part of the solution when it reaches a dead end

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is a greedy algorithm?

A

One that picks the best/most optimal option or solution at each step/iteration

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Advantages of BFS

A
  • Simple to implement
  • Uses a level by level approach, so is more efficient
  • Guarantees that all the nodes in the graph are visited so the solution is found
17
Q

Advantages of DFS

A

1) Memory efficient
2) time efficient

18
Q

Disadvantages of BFS

A

2) memory intensive
3) slower for large number of nodes compared to DFS

19
Q

Disadvantages of DFS

A

1) Not guaranteed to find solution, can potentially keep looping forever
2) may not find the SHORTEST path immediately