This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
import java.util.HashMap; | |
public class KNFAlgorithm { | |
private static int[] getTable(String s) { | |
char[] chars = s.toCharArray(); | |
int n = chars.length; | |
HashMap<Character, Integer> map = new HashMap<>(); | |
int[] table = new int[n]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class StringMatching { | |
private static boolean contains(String a, String b) { | |
int i = 0; | |
int n1 = a.length(); | |
int n2 = b.length(); | |
char[] ch1 = a.toCharArray(); | |
char[] ch2 = b.toCharArray(); | |
while (i < n1) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
public class SumOfSubsets { | |
private static int required; | |
private static int[] arr; | |
private static int n; | |
private static void fun(int i, int[] sol, int sum, int remaining) { | |
if (remaining >= 0 && sum <= required) { | |
if (sum == required && remaining == 0) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class NQueensProblem { | |
private static int n; | |
private static char[][] arr; | |
private static LinkedHashSet<String> finalSolution; | |
static { | |
finalSolution = new LinkedHashSet<>(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mport java.util.*; | |
public class LongestCommonSubsequenceWithDynamicProgramming { | |
public static void main(String[] args) { | |
char[] A = "bd".toCharArray(); | |
char[] B = "abcd".toCharArray(); | |
int[][] arr = new int[A.length + 1][B.length + 1]; | |
for (int i = 1; i <= A.length; i++) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
public class LongestCommonSubsequenceWithMemorization { | |
private static char[] A; | |
private static char[] B; | |
private static int[][] arr; | |
private static int longestCommonSubsequent(int i, int j) { | |
if (i == A.length || j == B.length) { | |
return 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LongestCommonSubsequenceWithoutMemorization { | |
private static char[] A; | |
private static char[] B; | |
private static int longestCommonSubsequent(int i, int j) { | |
if (i == A.length || j == B.length) { | |
return 0; | |
} else if (A[i] == B[j]) { | |
return 1 + longestCommonSubsequent(i + 1, j + 1); | |
} else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.Collections; | |
import java.util.List; | |
import java.util.stream.Collectors; | |
import java.util.stream.IntStream; | |
public class TravellingSalesmanProblem { | |
private static final int startingIndex; | |
private static final int[][] arr = {{0, 10, 15, 20}, {5, 0, 9, 10}, {6, 13, 0, 12}, {8, 8, 9, 0}}; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.text.DecimalFormat; | |
/* | |
1 2 3 4 5 6 7 | |
10 5 15 7 6 18 3 | |
2 3 5 7 1 4 1 | |
5 1.6 3 0 6 4.5 3 | |
5 1 14 1 X 6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
import java.util.Collections; | |
public class JobSquencingWithDeadlines { | |
public static void main(String[] args) { | |
int maxDeadline = 7; | |
Integer[] profits = {35, 30, 25, 20, 15, 12, 5}; | |
Integer[] deadlines = {3, 4, 4, 2, 3, 1, 2}; | |
System.out.println(getMaxProfit(profits, deadlines, maxDeadline)); |