## Stable Marriage Problem – Gale–Shapley Algorithm – Java

Stable Marriage Given N men and N women and the marriage preference order for each man and woman. Their marriage will be stable when these men and women marry in such a manner so...

## Given an array, find three-element sum closest to Zero

Objective: Given an array of integers, find the sum of any three elements which is closest to zero. The array may contain positive and negative elements.  Example:  Given Input: [-1, 4, -2, 5, 10,...

## Number of Intervals in which given value lies

Objective: Given a list of intervals with start and end for each interval. You have given a value V, write an algorithm to find the number of intervals in which the value V lies. ...

## Articulation Points OR Cut Vertices in a Graph

Objective: Given a graph, write an algorithm to find all the articulation points or cut vertices. Articulation Points: In a graph, a vertex is called an articulation point if removal of that vertex (along...

## Print All Paths in Dijkstra’s Shortest Path Algorithm

Objective:  Given a graph and a source vertex write an algorithm to find the shortest path from the source vertex to all the vertices and print the paths all well. Example: We strongly recommend reading...

## Check if Graph is Bipartite – Adjacency List using Depth-First Search(DFS)

Objective: Given a graph represented by the adjacency List, write a Depth-First Search(DFS) algorithm to check whether the graph is bipartite or not. Earlier we have solved the same problem using Adjacency Matrix (Check...

## Longest substring with at most K unique characters

Objective: Given a string, write an algorithm to find the longest substring with at most K characters. Example: Input: aabbaacdeeeeddded, K = 3 Output: Longest substring with 3 most unique characters is: cdeeeeddded with...

## Sort a given stack – Using Recursion

Objective: Given a stack of integers, write an algorithm to sort the stack using recursion.  Example: Original Stack: [14, 9, 67, 91, 101, 25] Sorted Stack: [9, 14, 25, 67, 91, 101] Original Stack:...

## Determine the given routing number belong to which bank

Objective: Given the banks and range of routing numbers for each bank. You have given a routing number, write a program to determine which bank it belongs to. Input: Given a list of routing...

## Check if interval is covered in given coordinates

Objective: Given 1-D list of coordinates, (x1, x2), (x3, x4), , , ,(xn-1, xn)and interval (a, b). Write an algorithm to determine if interval (a,b) is covered in the list of coordinates. Example: Coordinates...

## Evaluation of Prefix Expressions (Polish Notation) | Set 2

Earlier we had discussed how to evaluate prefix expression where operands are of single-digit. In this article, we will discuss how to evaluate prefix expression for any number ( not necessarily single digit.) Prefix...

## Minimum Boats Required to rescue people

Objective: Given N people need to be rescued by crossing the river by boat. Each boat can carry a maximum weight of given limit K. Each boat carries at most 2 people at the...

## Minimum No of operations required to convert a given number to 1 – Integer Replacement Problem.

Objective: Given a number N, write an algorithm to convert that number to 1. Below are the allowed operations. If N is even, do N = N/2. If N is odd, either do N...

## Convert Postfix to Prefix Expression

Objective: Given a Postfix expression, write an algorithm to convert it into prefix expression. Example: Input: Postfix expression:  A B +  Output: Prefix expression- + A B Input: Postfix expression:  ABC/-AK/L-* Output: Infix expression:...

## Convert Postfix to Infix Expression

Objective: Given a Postfix expression, write an algorithm to convert it into Infix expression. Example: Input: Postfix expression:  A B +  Output: Infix expression- (A + B) Input: Postfix expression:  ABC/-AK/L-* Output: Infix expression:...