Mar 2, 2008

Find possible parenthesizing

Given an input n write a program to generate all possible parenthesizing.

For ex: if n=3, then following is the result

((()))
(())()
()()()
(()())
()(())

Number of such elements is represented as Catalan Number. For more details, see http://en.wikipedia.org/wiki/Catalan_number

A similar problem asks to find all possible permutations of given elements with following two variations:

1. There might be repetitions
2. All elements are unique

Mar 1, 2008

Stack with findMin() in O(1) worst case

Implement a data structure which provides all stack operations in O(1)(e.g. push(), pop()) and also provides findMin() in O(1) in worst case.

Feb 26, 2008

Difference b/w Collection and Collections

Collections provide you views (annoymous class instances) for read-only

Feb 25, 2008

Implementation of an efficient MRU Cache in Java

LinkedHashMap with doubly linked list to keep the most recently accessed element at the head/tail of the list. Every bucket's list keeps its own elements in the singly linked list and the same elements are doubly linked as well

Difference between Comparable and Comparator

Comparator implementations can be used to define custom sorting even for Objects which already implement Comparable interface in TreeSet, HashSet

Feb 23, 2008

Find modulo (1 << k) division without using division

m = n & (d - 1); where d= (1 << k)

Find if the given integer is even or odd

Use of division is not permissible.