Skip to content

Category Archives: Java Programs

Counting sort is a sorting technique based on keys between a specific range. It works by counting the number of objects having distinct key values… Read More
Heap sort is a comparison-based sorting technique based on the Binary Heap data structure. It is similar to the selection sort where first find the… Read More
Merge Sort is a Divide and Conquer algorithm. It divides input array in two halves, calls itself for the two halves and then merges the… Read More
Insertion sort is a simple sorting algorithm that works the way we sort playing cards in our hands. Java   Java // Java program for… Read More
Given an unsorted array, sort the given array. You are allowed to do only following operation on array. flip(arr, i): Reverse array from 0 to… Read More
Given a 2D array, find the maximum sum subarray in it. For example, in the following 2D array, the maximum sum subarray is highlighted with… Read More
Given a number n, write an efficient function to print all prime factors of n. For example, if the input number is 12, then output… Read More
Given a set of non-negative integers, and a value sum, determine if there is a subset of the given set with sum equal to given… Read More
Given a graph and a source vertex in the graph, find shortest paths from source to all vertices in the given graph. Dijkstra’s algorithm is… Read More
Java // Java implementation of iterative quick sort import*; public class IterativeQuickSort {  void swap(int arr[], int i, int j)  {   int t =… Read More
Given a number n, print all primes smaller than or equal to n. It is also given that n is a small number. For example, if… Read More
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
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
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
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