Welcome To Tutorialspoint.dev
Officially launched 18th May 2019
Technical Scripter Tree BFS

Diameter of n-ary tree using BFS

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...

BFS vs DFS for Binary Tree

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...
Graph Tree BFS

Count the number of nodes at given level in a tree using BFS.

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 ...
Graph BFS Graph

Water Jug problem using BFS

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...
Graph BFS Graph

BFS using vectors & queue as per the algorithm of CLRS

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...
Graph BFS Graph

Level of Each node in a Tree from source node (using BFS)

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...
Competitive Programming Graph BFS

BFS using STL for competitive coding

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...
Graph BFS Graph

Print all paths from a given source to a destination using BFS

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

BFS for Disconnected Graph

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...
Graph BFS Shortest Path

0-1 BFS (Shortest Path in a Binary Weight Graph)

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...

Subscribe to Our Newsletter