## Reverse Bits of a given Integer

Given an integer, reverse its bits using binary operators.     The idea is to initialize the result by 0 (all bits 0) and process the given number starting from its least significant bit. If the current bit is 1, then we set the corresponding most significant bit in the result and finally move on …

## Find all odd occurring elements in an array having limited range of elements

Given an array having elements between 0 to 31, find elements which occurs odd number of times without using the extra space.

## Huffman Coding Compression Algorithm

Huffman Coding (also known as Huffman Encoding) is a algorithm for doing data compression and it forms the basic idea behind file compression. This post talks about fixed length and variable length encoding, uniquely decodable codes, prefix rules and construction of Huffman Tree.

## Find two duplicate elements in an limited range array (using XOR)

Given an array of integers with all its elements between 1 to n with the exception of two elements which occur twice. Find two duplicate elements without using any extra memory.

## Generate Binary Numbers Between 1 to N using Queue

Given a positive number N, efficiently generate binary numbers between 1 to N using queue data structure and in linear time.

## Find missing number and duplicate elements in an array

Given an limited range array of integers of size n with all its elements between 1 to n with the exception of one element which occur twice and one number which is missing from the list. Find missing number and the duplicate element in linear time and without using any extra memory.   For example, …

## Swap individual bits at given position in an integer

Given an integer, swap consecutive b bits starting from given positions in binary representation of the integer. The bits to be swapped should not overlap with each other.

## Round up to the previous power of 2

Given a number n, find previous power of 2. If n itself is a power of 2, return n.

## Round up to the next highest power of 2

Given a number n, find next highest power of 2. If n itself is a power of 2, return n.

## Multiply 16-bit integers using 8-bit multiplier

Given two 16-bit positive values stored in 32-bit integer variables, find the product using the 8-bit multiply operator that that takes two 8-bit numbers and returns a 16-bit value.

## Find the minimum or maximum of two integers without using branching

Given two integers, find their minimum and maximum without using branching.

## Count Set Bits using Lookup Table

Given an integer, count set bits in it.