Friday, May 9, 2014

Here are some previous coding interview questions:
Write the method that gives the predecessor of a node in a binary search tree.
Write the method that builds a tree given the in order and post order traversal of a tree.
Write the method that removes duplicates from an integer array.
Write the method that detects if two arrays are rotations of the same sequence.
Write the method that reverses a string
Write the method that inserts a node at the tail of a circular linked list in constant time.
Write the method that sorts entries into a phonebook.
Write the method that finds the common ancestor to two nodes in a binary search tree.
Write the method that searches for a word in a given string. This could be with Knuth Morris Pratt algorithm:
KMP algorithm evaluates states based on the following
m position within a string which is a prospective match
and i index in the pattern denoting the character under consideration.
First we pre-process to build the automata of distinct characters in a table T
Next, we do the match as follows:
while (m + i < length (S))
   if W[i] = S[m +i]
            if i == length(W) - 1
                  return m;
            i = i + 1
   else
          if T[i] > -1
             i = T[i], m = m + i - T[i]
          else
             i = 0, m = m + 1
return the length of s
The table building algorithm is as follows:
   T[0] = -1;
    while (i < patternLength) {
T[i + 1] = T[i] + 1;
while ( T[i+1] > 0 &&
pattern[i] != pattern[T[i + 1] - 1])
T[i + 1] = T[T[i + 1] - 1] + 1;
i++;
}



No comments:

Post a Comment