## Weighted Graph Implementation – JAVA

We have already discussed about Graph basics. We recommend reading this before you continue to read this article. What is Weighted Graph? A Graph is called weighted graph when it has weighted edges which...

We have already discussed about Graph basics. We recommend reading this before you continue to read this article. What is Weighted Graph? A Graph is called weighted graph when it has weighted edges which...

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

Earlier we had discussed in Graph Representation – Adjacency Matrix and Adjacency List about Graph and its different representations and we read Graph Implementation – Adjacency List .In this article we will implement graph...

Class Pair<Key, Value> – A convenience class to represent name-value pairs. pair stores a key-pair value. Two Pair objects are considered equal if key and value of one pair is matching with second key....

Earlier we had discussed in Graph Representation – Adjacency Matrix and Adjacency List about Graph and its different representations. In this article we will see the better (use inbuilt class of LinkedList) way to...

Java Deque Interface – It’s a linear collection. The Deque interface is a subtype of the util.Queue interface. Deque is acronym of “Double Ended Queue” means it supports insertion and removal of data from both...

Objective: Given ‘n’ Nuts and ‘n’ Bolts of different sizes. There is one-to-one mapping between nuts and bolts. Write an algorithm to find all matches between nuts and bolts Note: This problem can also be...

Objective: Given two numbers x and y. write an algorithm to find the number of bits which are to be flipped to convert number x to y. Example x = 10, Y = 20 x...

Objective: Given an array which contains even and odd integers. Write an algorithm to separate even and odd numbers. Example int [] arrA = {1,2,3,4,6,8,7,12}; Output: [12, 2, 8, 4, 6, 3, 7, 1] Approach:...

Objective: Given an array of integer write an algorithm to find 3 elements that sum to a zero. In short a+b+c = 0. Example int a [] = { 3,-1,-7,-4,-5,9,10}; Elements are -4 9 -5...

Objective: Given an array which contains only 0’s and 1’s. write an algorithm to separate 0’s and 1’s. Example int [] arrA = {1,0,1,0,1,1,0,0,0,0,1}; Output: [0, 0, 0, 0, 0, 0, 1, 1, 1, 1,...

Objective: Given an array of integer write an algorithm to find 3 elements that sum to a given number k. In short a+b+c = k. Example: int a [] = { 3,1,7,4,5,9,10} , k =...

Objective: Given an array of integer write an algorithm to find the majority element in it (if exist). Majority Element: If an element appears more than n/2 times in array where n is the size...

Objective: Given an integer check whether it is a perfect square. Example: number = 37 Output: false number = 49 Output: true This is fun puzzle which is asked in the interview. Approach: Say number...

Objective: Given an array of integer write a recursive solution to check if array is sorted. Example: int [] a = {1,2,3,4}; Output: true int [] a = {1,2,3,4,2}; Output: false Approach: This problem can...