# Category Archives: Java Programs

## Java Program for Cutting a Rod | DP-13

Given a rod of length n inches and an array of prices that contains prices of all pieces of size smaller than n. Determine the… Read More »

## Java Program for Longest Palindromic Subsequence | DP-12

Given a sequence, find the length of the longest palindromic subsequence in it. As another example, if the given sequence is “BBABCBCAB”, then the output… Read More »

## Java Program for Egg Dropping Puzzle | DP-11

The following is a description of the instance of this famous puzzle involving n=2 eggs and a building with k=36 floors. Suppose that we wish… Read More »

## Java Program to Detect Cycle in a Directed Graph

Given a directed graph, check whether the graph contains a cycle or not. Your function should return true if the given graph contains at least… Read More »

## Java Program for Activity Selection Problem | Greedy Algo-1

You are given n activities with their start and finish times. Select the maximum number of activities that can be performed by a single person,… Read More »

## Java Program 0-1 Knapsack Problem

Recursive Solution filter_none edit close play_arrow link brightness_4 code /* A Naive recursive implementation of 0-1 Knapsack problem */ class Knapsack {        // A… Read More »

## Java Program for Matrix Chain Multiplication | DP-8

Given a sequence of matrices, find the most efficient way to multiply these matrices together. The problem is not actually to perform the multiplications, but… Read More »

## Java Program for Coin Change

Given a value N, if we want to make change for N cents, and we have infinite supply of each of S = { S1,… Read More »

## Java Program for Minimum number of jumps to reach end

Given an array of integers where each element represents the max number of steps that can be made forward from that element. Write a function… Read More »

## Java Program for Min Cost Path

Given a cost matrix cost[][] and a position (m, n) in cost[][], write a function that returns cost of minimum cost path to reach (m,… Read More »

## Java Program for N Queen Problem | Backtracking-3

The N Queen is the problem of placing N chess queens on an N×N chessboard so that no two queens attack each other. For example,… Read More »

## Java Program for Rat in a Maze | Backtracking-2

We have discussed Backtracking and Knight’s tour problem in Set 1. Let us discuss Rat in a Maze as another example problem that can be… Read More »

## Java Program for Longest Common Subsequence

LCS Problem Statement: Given two sequences, find the length of longest subsequence present in both of them. A subsequence is a sequence that appears in… Read More »

## Java Program for Longest Increasing Subsequence

The Longest Increasing Subsequence (LIS) problem is to find the length of the longest subsequence of a given sequence such that all elements of the… Read More »

## Java Program for Rabin-Karp Algorithm for Pattern Searching

Given a text txt[0..n-1] and a pattern pat[0..m-1], write a function search(char pat[], char txt[]) that prints all occurrences of pat[] in txt[]. You may… Read More »