Finding all possible combinations - BFS
https://www.linkedin.com/pulse/finding-all-possible-combinations-bfs-kunal-saxena/
import java.util.*;
/**
* Finding all combinations from array of Numbers say {1,2,3,4} We want to make
* combination of r numbers, So if r=3 then combinations will be {1,2,3},
* {1,3,2}, {2,3,1}..etc
*
* @author Kunal.Saxena
*
*/
public class AllCombinationsFromNumbers {
private final static List
- > combList = new ArrayList<>(); //list of list as result
public static void findAllCombinations(int[] arr, int r) {
// Queue for storing all paths
Queue
- > paths = new LinkedList<>(); //store partial path
// Initialize queue with array elements
//e.g [1,2,3], starts with [1], [2], [3]
for (int i : arr) {
List