Welcome to Day 53 of the DSA Coding Challenge:
Todays Goals:
Question 1:Number of connected components
You are given a graph with n vertices. To indicate the connections in the graph you are given an array edges whose each element is an array of the form [u,v]. [u,v] indicates that there is an edge between u and v where u and v denote two vertices or nodes. Write a function that takes in ‘n’ and the ‘edges’ array and returns the number of connected components in the graph.
Question 2:Course Scheduler / Topological sort
You have to take a total of n courses leabled from 0 to n-1. Before you can take some courses you need to take it’s prerequisite courses. You are given an array prerequisites where each element [x,y] indicates that to take course x you have to take y first. E.g. [2,3] indicates that to take course 2 one has to first take course 3. Write a function that takes in n and the prerequisite array and returns true if you can complete all courses, else return false.
All the best!