N-ary tree refers to the rooted tree in which each node having atmost k child nodes. The diameter of n-ary tree is the longest path between two leaf nodes.
Various ap...

Share

What are BFS and DFS for Binary Tree?
A Tree is typically traversed in two ways:
Breadth First Traversal (Or Level Order Traversal)
Depth First Traversals
Inorde...

Share

Given a tree represented as undirected graph. Count the number of nodes at given level l. It may be assumed that vertex 0 is root of the tree.
Examples:
Input : 7
...

Share

You are given a m litre jug and a n litre jug . Both the jugs are initially empty. The jugs don’t have markings to allow measuring smaller quantities. You have...

Share

Breadth-first search traversal of a graph using the algorithm given in CLRS book.
BFS is one of the ways to traverse a graph. It is named so because it expands the fr...

Share

BFS(Breadth First Search) is a graph traversal technique where a node and its neighbors are visited first and then the neighbors of neighbors. In simple terms it trav...

Share

A STL based simple implementation of BFS using queue and vector in STL. The adjacency list is represented using vectors of vector.
In BFS, we start with a node.
1) C...

Share

Given a directed graph, a source vertex ‘src’ and a destination vertex ‘dst’, print all paths from given ‘src’ to ‘ds...

Share

In previous post, BFS only with a particular vertex is performed i.e. it is assumed that all vertices are reachable from the starting vertex. But in the case of disco...

Share

Given a graph where every edge has weight as either 0 or 1. A source vertex is also given in the graph. Find the shortest path from source vertex to every other vert...

Share