#
Algorithm Archive

I have been posting data structure and algorithms programs on various topics such as Array,Queue, Stack ,Binary tree, LinkedList , String, Number, ArrayList, etc. So I am consolidating list of programs to create an index …

In this tutorial, we will see how to rotate an array be K positions. Problem: N=6 and k=2 If Arr = {1, 2, 3, 4, 5, 6} and k=2 then rotated array will be {5, …

In this tutorial, we will see how to check if number is power of two. There are many approaches to check if number is power of two or not. Approach 1: It is very easy and …

In this post, we will see how to find smallest and largest element in an array. Problem: You are given an array of numbers. You need to find smallest and largest numbers in the array. …

In this post, we will see about trie data structure in java. What is Trie : Trie is data structure which stores data in such a way that it can be retrieved faster and improve …

Problem: From Wikipedia : In computer science, the Largest sum contiguous subarray is the task of finding the contiguous subarray within a one-dimensional array of numbers which has the largest sum. For example, for the …

Kadane algorithm is a famous algorithm to solve maximum subarray problem. Maximum subArray problem: From Wikipedia : In computer science, the maximum subarray problem is the task of finding the contiguous subarray within a one-dimensional …

Selection sort is an in place comparison sorting algorithm. It is very simple to implement but it does not go well with large number of inputs. Selection sort algorithm : Find the minimum element in …

Shell sort is in place comparison based sorting algorithm. It is generalization of insertion sort. It was invented by Donald shell. It allows to sort elements which are far apart. In case of insertion sort, comparison happens …

If you want to practice data structure and algorithm programs, you can go through data structure and algorithm interview questions. In this post , we will see how to implement Queue using Linked List in java. …

Quicksort or partition-exchange sort, is a sorting algorithm, which is using divide and conquer algorithm. In quick sort, we first choose a pivot and divide into two sublists,one will contain elements lower than pivot and …