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
// Dinning Philosopher problem | |
#include<stdio.h> | |
#define n 4 | |
int compltedPhilo = 0, i; | |
struct fork{ | |
int taken; |
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
from random import randint | |
from time import sleep | |
def replay(ans): | |
if ans == "y": | |
battleship(aBoard) | |
else: | |
exit() |
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.stream.Collectors; | |
import java.util.stream.IntStream; | |
public class ZeroOneKnapsackProblem { | |
public static void main(String[] args) { | |
int max = 8; | |
int n = 4; | |
int[] p = {1, 2, 5, 6}; | |
int[] w = {2, 3, 4, 5}; |
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.ArrayDeque; | |
import java.util.List; | |
import java.util.Queue; | |
import java.util.Stack; | |
import java.util.stream.Collectors; | |
import java.util.stream.Stream; | |
class Node { | |
int data; | |
List<Node> neighbours; |
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 BellmanFordAlgorithm { | |
public static void main(String[] args) { | |
int inf = Short.MAX_VALUE; | |
int[][] weights = new int[][] { | |
{0, 6, 5, 5, inf, inf, inf}, | |
{inf, 0, inf, inf, -1, inf, inf}, | |
{inf, -2, 0, inf, 1, inf, inf}, | |
{inf, inf, -2, 0, inf, -1, inf}, |
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.stream.IntStream; | |
public class MatrixChainMultiplication { | |
public static void main(String[] args) { | |
int n = 4; | |
int[] d = {5, 4, 6, 2, 7}; | |
int[][] m = new int[n][n]; | |
int[][] c = new int[n][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
import java.util.Arrays; | |
import java.util.Collections; | |
import java.util.stream.Collectors; | |
import java.util.stream.IntStream; | |
import java.util.stream.Stream; | |
public class FloydWarshallAlgorithm { | |
public static void main(String[] args) { | |
int[][] arr = new int[4][4]; | |
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 FibonacciWithDynamicProgramming { | |
public static void main(String[] args) { | |
int n = 30; | |
long starTime = System.nanoTime(); | |
System.out.println("Fibonacci without dynamic: " + fibonacci(n)); | |
long endTime = System.nanoTime(); | |
System.out.println("Time taken: " + (endTime - starTime)); |
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 OptimalMergePattern { | |
public static void main(String[] args) { | |
System.out.println(getLeastMergingCost(new int[]{20, 30, 10, 5, 30})); | |
} | |
private static int getLeastMergingCost(int[] list) { | |
Arrays.sort(list); | |
int maxCost = list[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.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)); |
OlderNewer