##
Find if an array of strings can be chained to form a circle | Set 2
December 7, 2016

Given an array of strings, find if the given strings can be chained to form a circle.

A computer science portal for geeks

December 7, 2016

Given an array of strings, find if the given strings can be chained to form a circle.

October 17, 2016

We are given a map of cities connected with each other via cable lines such that there is no cycle between any two cities. We need to find the maximum length of cable between any two cities for given city map. Input : n = 6 1 2 3 // Cable length from 1 to… Read More »

September 8, 2016

Given two integers ‘n’ and ‘m’, find all the stepping numbers in range [n, m]. A number is called stepping number if all adjacent digits have an absolute difference of 1. 321 is a Stepping Number while 421 is not. Examples: Input : n = 0, m = 21 Output : 0 1 2 3… Read More »

July 23, 2016

We have discussed flattening of a multi-level linked list where nodes have two pointers down and next. In the previous post, we flattened the linked list level wise. How to flatten a linked list when we always need to process down pointer before next at every node. Input: 1 – 2 – 3 – 4… Read More »

May 19, 2016

There are two common ways to traverse a graph, BFS and DFS. Considering a Tree (or Graph) of huge height and width, both BFS and DFS are not very efficient due to following reasons. DFS first traverses nodes going through one adjacent of root, then next adjacent. The problem with this approach is, if there… Read More »

March 28, 2016

What is a Mother Vertex? A mother vertex in a graph G = (V,E) is a vertex v such that all other vertices in G can be reached by a path from v. Example : Input : Below Graph Output : 5 There can be more than one mother vertices in a graph. We need… Read More »

March 12, 2016

Given a directed graph, check whether the graph contains a cycle or not. Your function should return true if the given graph contains at least one cycle, else return false. For example, the following graph contains three cycles 0->2->0, 0->1->2->0 and 3->3, so your function must return true. Solution Depth First Traversal can be used… Read More »

February 22, 2016

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 Inorder Traversal (Left-Root-Right) Preorder Traversal (Root-Left-Right) Postorder Traversal (Left-Right-Root) BFS and DFSs of above Tree Breadth First Traversal : 1 2 3 4 5 Depth First Traversals: Preorder Traversal… Read More »

December 16, 2015

In this post “Important top 10 algorithms and data structures for competitive coding “. Topics : Graph algorithms Dynamic programming Searching and Sorting: Number theory and Other Mathematical Geometrical and Network Flow Algorithms Data Structures The below links cover all most important algorithms and data structure topics: Graph Algorithms Breadth First Search (BFS) Depth First… Read More »

December 9, 2015

In this post “Top 10 coding problems of important topics with their solutions ” are written. If you are preparing for a coding interview, going through these problems is a must. Topics : 1. Graph 2. Linked List 3. Dynamic Programming 4. Sorting And Searching 5. Tree / Binary Search Tree 6. Number Theory 7. BIT… Read More »

October 23, 2015

Depth First Traversal (or Search) for a graph is similar to Depth First Traversal (DFS) of a tree. The only catch here is, unlike trees, graphs may contain cycles, so we may come to the same node again. To avoid processing a node more than once, we use a boolean visited array. For example, a… Read More »