You are not allowed to use loop constructs like while, for..etc, and you can only use the following ADT functions on Stack S:


The idea of the solution is to hold all values in Function Call Stack until the stack becomes empty. When the stack becomes empty, insert all held items one by one at the Read More →

In computer science, a B-tree is a tree data structure that keeps data sorted and allows searches, sequential access, insertions, and deletions in logarithmic time.
The B-tree is a generalization of a binary search tree in that a node can have more than two children. Unlike self-balancing binary search trees, the B-tree is Read More →

Implement a function that checks whether a positive number is a palindrome or not. For example, 121 is a palindrome, but 123 is not.
It is easy to check whether a string is a palindrome or not - we can check whether the first character and the last one are identical, and then compare the second Read More →

Tris volumineux
Les algorithmes de tri doivent aussi être adaptés en fonction des configurations informatiques sur lesquels ils sont utilisés.On suppose que toutes les données sont présentes en mémoire centrale (ou accessibles en mémoire virtuelle). La situation se complexifie si l'on veut trier des volumes de données supérieurs à la mémoire centrale disponible (ou Read More →

Dynamic Programming – Cutting Rods
This problems is presented in Introduction to Algorithms as an intro to Dynamic Programming.
Given a rod of length n inches and a table of prices pi for rod lengths: i = 1, 2, ... n, determine the maximum revenue rn obtainable by cutting up the rod to pieces and selling them.
The Read More →

In mathematics, the sieve of Eratosthenes, is a simple, ancient algorithm for finding all prime numbers up to any given limit. It does so by iteratively marking as composite (i.e. not prime) the multiples of each prime, starting with the multiples of 2.

Algorithm description
A prime number is a natural number which has exactly Read More →

RSA is a cryptosystem, which is known as one of the first practicable public-key cryptosystems and is widely used for secure data transmission. In such a cryptosystem, the encryption key is public and differs from the decryption key which is kept secret.
In RSA, this asymmetry is based on the practical difficulty of factoring the product Read More →

A permutation, also called an “arrangement number” or “order,” is a rearrangement of the elements of an ordered list S into a one-to-one correspondence with S itself. A string of length n has n! permutation.
Source: Mathword(
Below are the permutations of string ABC.
Here is a solution using backtracking.

These permute2 values themselves Read More →

Someone posed an interesting probelm over at sitepoint the other day.
Given an array of words how can you work out each possible combination?
There are a few methods but here's the PHP code for the cleanest:

$words = array('red', 'blue', 'green');
$num = count($words);

//The total number of possible combinations
$total = pow(2, $num);

//Loop through Read More →

Heapsort is one of the general sorting algorithms that performs in O(n.log(n)) in the worst-case, just like merge sort and quicksort, but sorts in place – as quicksort. Although quicksort’s worst-case sorting time is O(n2) it’s often considered that it beats other sorting algorithms in practice. Thus in practice quicksort is “faster” than heapsort. In Read More →