11. Path Exists
Required Input:
6
[[0, 1], [1, 2], [2, 3], [4, 5]]
0
3Expected Output:
True
Code In Python
def has_path(n, edges, start, end):
# Write your logic here
pass
# Prefilled input
n = 6
edges = [[0, 1], [1, 2], [2, 3], [4, 5]]
start = 0
end = 3
print(has_path(n, edges, start, end))
Run Code?
Click Run Button to view compiled output
12. Course Schedule I
Required Input:
4
[[1, 0], [2, 1], [3, 2]]Expected Output:
True
Code In Python
ef can_finish_courses(n, prerequisites):
# Write your logic here
pass
# Prefilled input
n = 4
prerequisites = [[1, 0], [2, 1], [3, 2]]
print(can_finish_courses(n, prerequisites))
Run Code?
Click Run Button to view compiled output
13. Dijkstra's Algorithm
Required Input:
0: [(1, 4), (2, 1)],
1: [(3, 1)],
2: [(1, 2), (3, 5)],
3: []
0Expected Output:
{0: 0, 1: 3, 2: 1, 3: 4}
Code In Python
import heapq
def dijkstra(graph, source):
# Write your logic here
pass
# Prefilled input
graph = {
0: [(1, 4), (2, 1)],
1: [(3, 1)],
2: [(1, 2), (3, 5)],
3: []
}
source = 0
print(dijkstra(graph, source))
Run Code?
Click Run Button to view compiled output
14. Bellman-Ford
Required Input:
[(0,1,4),(0,2,5),(1,2,-3),(2,3,4)]
4
0Expected Output:
[0, 4, 1, 5]
Code In Python
def bellman_ford(edges, n, source):
# Write your logic here
pass
# Prefilled input
edges = [
(0, 1, 4),
(0, 2, 5),
(1, 2, -3),
(2, 3, 4)
]
n = 4
source = 0
print(bellman_ford(edges, n, source))
Run Code?
Click Run Button to view compiled output
15. Floyd-Warshall
Required Input:
[0, 3, float('inf'), 5],
[2, 0, float('inf'), 4],
[float('inf'), 1, 0, float('inf')],
[float('inf'), float('inf'), 2, 0]Expected Output:
[[0, 3, 7, 5], [2, 0, 6, 4], [3, 1, 0, 5], [5, 3, 2, 0]]
Code In Python
def floyd_warshall(graph):
# Write your logic here
pass
# Prefilled input
graph = [
[0, 3, float('inf'), 5],
[2, 0, float('inf'), 4],
[float('inf'), 1, 0, float('inf')],
[float('inf'), float('inf'), 2, 0]
]
print(floyd_warshall(graph))
Run Code?
Click Run Button to view compiled output
16. Find Bridges
Required Input:
[[0,1],[1,2],[2,0],[1,3]]
4Expected Output:
[[1, 3]]
Code In Python
def find_bridges(edges, num_nodes):
# Write your logic here
pass
# Prefilled input
edges = [[0, 1], [1, 2], [2, 0], [1, 3]]
num_nodes = 4
print(find_bridges(edges, num_nodes))
Run Code?
Click Run Button to view compiled output
17. Articulation Points
Required Input:
[[0,1],[1,2],[2,0],[1,3],[3,4]]
5Expected Output:
[1, 3]
Code In Python
def find_articulation_points(edges, num_nodes):
# Write your logic here
pass
# Prefilled input
edges = [[0, 1], [1, 2], [2, 0], [1, 3], [3, 4]]
num_nodes = 5
print(find_articulation_points(edges, num_nodes))
Run Code?
Click Run Button to view compiled output
18. Kruskal's Algorithm
Required Input:
[
(0, 1, 10), (0, 2, 6), (0, 3, 5),
(1, 3, 15), (2, 3, 4)
]
4Expected Output:
[(2, 3, 4), (0, 3, 5), (0, 1, 10)]
Code In Python
def kruskal_mst(edges, num_nodes):
# Write your logic here
pass
# Prefilled input
edges = [
(0, 1, 10), (0, 2, 6), (0, 3, 5),
(1, 3, 15), (2, 3, 4)
]
num_nodes = 4
print(kruskal_mst(edges, num_nodes))
Run Code?
Click Run Button to view compiled output
19. Prim's Algorithm
Required Input:
0: [(1, 10), (2, 6), (3, 5)],
1: [(3, 15)],
2: [(3, 4)]
4Expected Output:
[(0, 3, 5), (0, 2, 6), (0, 1, 10)]
Code In Python
import heapq
def prims_mst(graph, num_nodes):
# Write your logic here
pass
# Prefilled input
graph = {
0: [(1, 10), (2, 6), (3, 5)],
1: [(3, 15)],
2: [(3, 4)]
}
num_nodes = 4
print(prims_mst(graph, num_nodes))
Run Code?
Click Run Button to view compiled output
20. Course Schedule II
Required Input:
4
[[1, 0], [2, 1], [3, 2]]Expected Output:
[0, 1, 2, 3]
Code In Python
from collections import deque
def find_course_order(n, prerequisites):
# Write your logic here
pass
# Prefilled input
n = 4
prerequisites = [[1, 0], [2, 1], [3, 2]]
print(find_course_order(n, prerequisites))
Run Code?
Click Run Button to view compiled output


