Monday, May 27, 2013

Stack and Queue Algorithm Questions


  1. Use single array to implement 3 stack.
  2. Implement stack class. Write push , pop and peek function. Write a function MIN which return minimum value in O(1).
  3. Implement queue using 2 stacks.


Sorting and Searching Algorithm Questions


  1. Given two sorted array A and B. A is large enough to hold B. Merge the arrays in sorted order.
  2. Write a function which sort the array of string such that 2 anagram are together.
  3. A array is sorted in increasing order and rotated many times. Find a number N in given array.
  4. You have 10 GB of file with each line having 1 string.Sort the file.
  5. Given sorted array of string. The empty string is inserted between each string. Find a given string in array.
  6. Given a matrix MxN which is sorted by row and column in increasing order. Find given element .

Tree and Graph Algorithm Questions


  1. Implement a function to check if binary tree is balanced. A balanced tree is whose left and right sub-tree height do not differ more than 1.
  2. Given a directed graph. Write algo to find route between 2 nodes.
  3. Given a sorted increasing order arrray. Create binary search tree with minimum height.
  4. Given a binary tree. Create a link list of all nodes at each depth.
  5. Write function which checks whether given binary tree is binary search tree.
  6. Write algo for next node "in order successor" of a given node in binary search tree.
  7. Write function of find common ancestor of 2 nodes. This may not be BST and avoid using other data structure.
  8. Given 2 very large binay tree. Find one tree is sub-tree of another at node N. So that if we cut tree at node N then both the tree are identical.
  9. Given the binary tree. Print all the paths whose sum is equal to gicen value. Path can start and end anywhere.

Algorithms learning resorces

MIT lectures
http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-046j-introduction-to-algorithms-sma-5503-fall-2005/video-lectures/