Tag: graphs

Data Structures & Algorithms in Java – Graphs – Alien Dictionary.
Problem: You are given a list of English words arranged lexically (as in a dictionary). But not in the order of English alphabets but in the order of an alien language which uses English script. With the given words you need to arrange the letters in the right order of the alien dictionary. For example,…

Data Structures & Algorithms in Java – Graphs – Valid Tree
Problem: Given the number of nodes in a graph and the list of edges in the graph , find if it is a valid tree. For example, Given n = 5 and the edges [[0,1] ,[0,2],[0,3],[3,4] It is a valid tree because there are no cycles in it and every node is connected with an…

Data Structures & Algorithms in Java – Graphs – Number of Islands
Problem: Given a m * n grid representing a map with the value 1 representing land and the value 0 representing water, find out the number of islands in the grid. That is find out the piece of area containing ‘1’s surrounded on all sides by ‘0’s or the grid boundaries (Assume the entire grid…

Data Structures & Algorithms in Java – Graphs – Course Schedule
Problem: Given the number of courses to take in a class and the dependency of the courses (before taking one course you should have taken another course) find out if all the courses can be taken. The dependency is mentioned by a list of pairs in the form [ [a1,b1],[a2,b2] …] where to take the…