ALGORITHMS

Hash map (Hash table) is a data structure that maps keys to values with constant time. It is a very useful and commonly used data structure by programmers either for development or competitive programming. C++ programmer often use STL map container class as a hash map and Java programmers use Has...

Continue reading...

Given a list of elements Segment Tree can find out any information of a segment/part of the list. As an example, given an array [8, 7, 3, 9, 5, 1, 10] you are asked to find sum of elements between between 2nd and 5th element (index starts from 0, including boundary). Answer is 18.

Operations
...

Continue reading...

Bitwise GCD:

Bitwise GCD is applicable only for unsigned int. It's 60% faster than normal numeric gcd algorithm. The quick short implementation of bitwise GCD is:

public int gcd(int a, int b) {
    while(b) b ^= a ^= b ^= a % b;
    return a;
}

Ref: https://en.wikipedia.org/wiki/Binary_GCD_a...

Continue reading...

Solving graph problems for newbies was never been easy. In this series of blog, I am going to delineate solutions of graph problems precisely taken from several online judges which will help newbies to solve graph problem from easy to hard categories. Although It's good to have a theoritical backgro...

Continue reading...

Problem Source: UVA Online Judge - 10067

Brief Analysis: It could be easily identified this is a BFS problem. Only one optimization here is to build graph first time before running any test case. Building graph for each test case could get TLE verdict.

Continue reading...