# Category: Position

## Graph – Detect Cycle in a Directed Graph

Objective: Given a directed graph write an algorithm to find out whether graph contains cycle or not. Example: Approach: Graph contains cycle if there are any back edges. There are two types of back...

## Graph – Software Installation Problem

Objective: Given a list of software’s which you need to install in a computer. Few software’s has dependency on other software’s in the list, means these software can be installed only when all of...

## Snake and Ladder Problem

Objective – Given a snake and ladder game, write a function that returns the minimum number of jumps to take top or destination position. You can assume the dice you throw results in always...

## Graph – Depth First Search in Disconnected Graph

Objective: Given a Graph in which one or more vertices are disconnected, do the depth first traversal. Earlier we have seen DFS where all the vertices in graph were connected. In this article we...

## Topological Sort

Topological Sort: A topological sort or topological ordering of a directed graph is a linear ordering of its vertices such that for every directed edge uv from vertex u to vertex v, u comes before v in the ordering. A topological ordering is possible if and only if the graph has no directed...

## Graph – Depth First Search using Recursion

Objective: Given a graph, do the depth first traversal using recursion. Earlier we have seen DFS using stack. In this article we will see how to do DFS using recursion. (Recursion also uses stack...

## Minimum Copy Paste Operations

Objective: You have given a character ‘A’ which is already printed. You are allowed to perform only 2 operations – Copy All – This operation will copy all the printed characters. Paste – This...

## Count and print all Subarrays with product less than K in O(n)

Objec­tive:  Given an array of positive integers and integer ‘K’. Write an algorithm to count all the possible sub arrays where product of all the elements in the sub array is less than k. Example:...

## Sliding Window Algorithm (Track the maximum of each subarray of size k)

Objective: Given an array and integer k, write an algorithm to find the maximum element in each subarray of size k. Example: int [] nums = { 1, 2, 3, 2, 4, 1, 5,...

## Print all sub sequences of a given String

Objec­tive:  Given a String write an algorithm to print all the possible sub subsequences. Example: String input = “abc”; Output: Possible sub sequences – {Empty}, {a}, {b}, {c}, {ab} ,{a,c}, {b, c}, {a, b, c}...

## Graph – Print all paths between source and destination

Objective: Given a graph, source vertex and destination vertex. Write an algorithm to print all possible paths between source and destination. This problem also known as “Print all paths between two nodes” Example: Approach:...

## Graph – Depth First Traversal

Objective – Given a graph, do the depth first traversal(DFS). What is depth-first traversal– Depth-first search (DFS) is an algorithm for traversing or searching tree or graph data structures. One starts at the root (selecting some arbitrary node as the root in the...

## Print all sub sequences of a given array

Objec­tive:  Given an array write an algorithm to print all the possible sub subsequences. Example: int [] a = {1, 2, 3}; Output: Possible sub sequences – {Empty}, {1}, {2}, {3}, {1, 2} ,{1,3}, {2,...

## Print all substrings of a given string

Objec­tive:  Given a string write an algorithm to print all the possible sub strings. Example: String input = “abcd”; Output: Possible sub strings – a          a b      a b c   a b c d b...

## Sum of all sub arrays in O(n) Time

Objec­tive:  Given an array write an algorithm to find the sum of all the possible sub arrays. Example: int [] a = {1, 2, 3}; Output: Possible subarrays – {1}, {2}, {3}, {1, 2} ,...