Você está na página 1de 5

1. Write an iterative code for in order traversal of a tree and its optimizations.

2. Change a tail recursive code to iterative form.


3. Write the shortest way to divide a no by 7
4. o find the first repeated element in a string in ! "n#.
$. %ind the first node of difference from the root among two trees.
&. Code to count the no of leaf nodes in a tree.
7. 'everse a lin(ed list. ")n place#
*. Was supposed to find a bug in the code.
+. ,ome -ues on wor( done in )
............................................................................................
rilogy Written est
hese were the -uestions/
1. Write a program to print the no. of leaf nodes in a tree.
2. 0ssume that there is a 1seudo no. random generator already given to you2
which generates no. between 1 and 3. 4iven an array of size 3. 5ou have to
fill this array with random no6s between 1 and 3 "each no. should occur
only once# using this generator. Write a 1rogram.
3. 4iven a binary tree which is represented using an array2 each entry
in the array being the parent of that node. Write a program to find the
depth of the tree.
4. %ind errors in the program/
)t was for merging 2 lin(ed lists.
) don6t rem. the code.
...........................................................................................
Written est
4ive algorithms and write code for the following/
71. 4iven two strings s1 and s2 as parameters to your function2 find out the number of
occurences of each character of s2 in s1 and return a string which has the count "in s1# of each
character of s2 in the order that the characters occur in s2. eg. )f s189'enaissa3ce9 and
s289a'aans92 then your function should return 9a2'1n1s29. he function should be case
sensitive.
":int/ hin( in terms of a direct address table#
72. 5ou are given a binary tree description as a set of 2.tuples. ;ach 2.tuple consists of a string
describing the location and the value stored in that location. <erify if a given tree is correct= eg.
">'2 $#2 ">2 2#2 "2 &#2 "'2 1# describes a valid binary tree as shown below/
&
?@A
2 1
A
$
3ote that it does not have to be a complete?balanced binary tree nor a binary search tree "i.e.
inorder traversal gives elements in sorted order#. he location of the root is given by the empty
string. 0lso2 the elements are not given in any order.
":int/ Bse a hash table#
73. )mplement a -ueue using two stac(s.
74. Convert a binary tree into a circular doubly lin(ed list.
":int/ )norder traversal#
1st round of interview/
.......................
,ome of the test -uestions were discussed again.
71. 5ou are given a set of sets. Write a function which prints out all the tuples "one element
from each set#. 5ou can assume that the set of sets is given as a set of strings "each string
representing a set of characters#.
eg. )nput 8 9-we929fg9
!utput8 -f2-g2wf2wg2ef2eg
Write an iterative function to do the above. 3ote that neither the size nor the number of sets is
fiCed. 0lso if you were writing a class "say2 in CDD# for the above2 what functionality would you
provide the users of the class.
":int/ Bse an array of pointers to iterate over the different sets to generate the various tuples.
0lso2 for the types of functionality you can provide2 refer to the functionalities of ,> in CDD
li(e iterators etc.#
72. 5ou are given an array of 1E1 integers out of which $E numbers are repeated and 1 is
uni-ue. %ind out the uni-ue number in one traversal of the array.
":int/ Bse Cor#
2nd round of interview/
.......................
71. 4iven a dictionary of words2 find out the longest chain of 6ancestors6 in it. 0ncestors are
defined in the following way/ 0 word is said to be the parent of another word if
1# it is a valid word in the dictionary
2# it can be obtained by deleting one character of the word and permuting the remaining
characters.
eg. run is a parent of urns
0 possible chain of ancestors could be/
a
an
ban
nabs
bands
his chain is of length 4. What is the length of the longest chain in a given dictionary=
72. )mplement a stac( using two -ueues. What is the compleCity of the
push and pop operations=
3rd round of interview/
.......................
71. 4iven two binary trees2 give an algorithm to efficiently merge
them into one tree. he resultant tree should be more or less balanced.
5ou have access to unlimited eCtra memory.
":int/ Can be done in linear time by inorder traversals of the two trees and then merging the two
sorted lists obtained. he resultant sorted list can be converted bac( into a tree in linear time.#
72. here is a building with 1EE floors and you are given 2 glass balls. he property of the glass
balls is that if they brea( by dropping from one floor2 then they will brea( by dropping from all
the floors above that floor. 5ou have to find the lowest floor from which the glass balls start
brea(ing. Finimize the number of trials for the worst case.
":int/ he best answer ) got was 2Gs-rt"n# . 1 where n is the number of floors by dividing the
floors into s-rt"n# groups of size s-rt"n# each. #
73. 4iven preorder and postorder traversals of a binary tree2 give an
algorithm to reconstruct the tree. 0lso write code for the above. Can
you suggest an algorithm to reconstruct the tree given preorder and
postorder traversals. Why not=
74. he vector data structure in CDD is li(e an array eCcept that when it fills up2 more memory is
automatically allocated for it. wo strategies for memory allocation were given/
1# 0 constant amount of eCtra memory is allocated and the original vector is copied to the new
location.
2# he amount of memory allocated is double the size of the current vector and the original
vector is copied to the new location.
What is the order compleCity in inserting n elements in the vector in the above two cases= What
if we were using lin(ed lists instead of arrays internally= What benefits = What pitfalls=
............................................................................................
hese are the -ns we got in our written test"4?4?2EE3#.
1. 4iven a string construct a new string containing the occurrences of uni-ue
characters in it.5ou can assume that only a.z H 0.I appear in the string with
6a6 being different from 606.0lso the occurrences must be in the order of
occurrence in the string.%or eg. for the string 90ll!ccurrences9 you must
return the string 901l2!1c3u1r2e2n1s19.
2.5ou are given a Jinary tree as a se-uence of nodes where each node appears
as "value29KpathL9# where path is a string containing > H ' specifying the
route to ta(e from the root to reach the node.%or the root2 path is the
empty string.%or eg. for the Jinary ree/
3
? A
2 4
we will have the nodes as "3299#2"229>9# H "429'9#.
4iven such a se-uence of nodes determine whether it forms a valid Jinary ree.
3. )mplement a -ueue using 2 stac(s.Jasically write the 2 fns ;n-ueue H
Me-ueue.
4. 4iven a Jinary ree change the pointers such that it forms a circular
doubly lin(ed list containing the nodes in the se-uence obtained
by the in.order traversal of the tree.
hese are the -ns ) got in my 1st round of interview"$?4?2EE3#.
2 sessions"0mit 0rora D 'ashmi :ari#
0mit 0rora/
1# Mescribe your soln to -n1 of the written test and refine it.
2# ,ame as above for -n2.
3# 'ange -uery/,NO is an array of size m whose elements lie in the range
1 to (.0lso Nai2biO "1K8iK8n# are n closed intervals.5ou have to compute
the no. of elements of , lying in each of these intervals for/
a# ( bounded above
b# ( unbounded above
'ashmi :ari/
1# 'everse the words in a sentence.%or eg. if the given sentence is
9happy birthday to you9 you have to output 9you to birthday happy9.
2# 'otate an array by ( places without using any eCtra memory.
3# 5ou are given a dictionary of valid words.0n eCtended anagram of a valid
word w1 is obtained by adding a single character to w1 and permuting it to
get another valid word w2.w1 can be called w26s parent.4iven a word w you
have to figure out all possible parents.5ou can pre.process the dictionary
to store it in any convenient data.structure of your choice.
4# his was a design problem.5ou have to provide an abstraction for storing
a set of "any number of# sets li(e P Pa2bQ2 P-2w2e2tQ2 ...n sets sayQ.0n
additional re-uirement is to produce all n.tuples PC12C22...CnQ where
Ci belongs to the ith set.he n.tuples have to be produced as some sort
of enumeration and not all at once.also there might be restrictions on
the type of tuples re-uired.Jasically ) had to write a class in Rava
which contained all the re-uired data structures and had to provide methods
which accomplished the above and any other functionality that might be
re-uired.
";ach session was about an hour long . )6ll (eep sending the -uestions
provided of course that ) ma(e it to the 2nd roundSS#
. Mebo
............................................................................................
hese are the -ns as(ed to me during the 2nd round of interview for rilogy/
1# he 6<ector6 in Rava is a data structure whose size needs to be dynamically
increased. ,uppose it is increased in constant increments then what is the
order of inserting n elements into it= N!"n@2#O.
3ow suppose you revise your strategy to double the eCisting size.What is the
revised order= N!"n#O
2# 4iven the elements of a binary tree in pre.order and inorder2 construct
the tree from it. N) gave a recursive solnO
)s it possible to do the same for a# post.order and inorder N5esO
b# pre.order and post.order N3o2 tree constructed need not be uni-ueO
3# 4ive an algorithm to determine the second shortest path between
2 vertices. N ) gave the following soln. 4et the shortest path using
MTi(stra6s.3ow for each edge in the shortest path2 remove it and get the
revised shortest path. he answer is the minimum of all these revised
shortest paths.O
............................................................................................
a/ given an array with elements from 1 to n.1 and one repeated element2
find the repeated element=
b/ given an array with elements from 1 to n.1 and two repeated elements2
find the repeated elements=
)n both cases order n solution
c/give an algo to find the the second most shortest path between
two vertices=
d/a vector in Tava is an array that can grow dynamically. we were given
two strategies of growing the vector2 either increasing its size by a
fiCed amount every time more space was needed or by doubling the vector
size whenever space was needed. was as(ed to compute the compleCity of
inserting 3 elements into this vector in both the cases.
What if the array was maintained as a lin(ed list..
e/4iven two binary search trees2 was as(ed to combine them into one. an
order n solution was as(ed for
first round interview
f.efficient algo to find the second most smallest element in an array
g.algo to give the mirror image of a binary tree
h.given an array of 1E1 elements2 of which $E are repeated2 find the
unrepeated element
i.how would you best store a huge dictionary of words so that given a
particular word you can access all its parents in order 1 time. 1arents
of a particular word C have length one less than C 2 are in the dictionary
and have all the letters as C eCcept one.
T.given an array find the first two elements whose sum is C
written test/
(.convert a binary search tree into a sorted doubly lin(ed list
l.traverse a tree and for each node output its value and its path from the
root in terms of an >' string.
eg.
e"root#
f"># g"'#
h">># i">'# T"'># ("''#
m.implement a stac( using two -ueues
n.given a string say wwedfeetwtf(i(2 output should be
w3e3d1f2t2(2i1
ie. each letter followed by the number of times it occurs in the string
o. 4iven an incoming stream of sorted numbers construct a binary search
tree. 0t each stage2 you should have a nearly balanced tree.
............................................................................................
:ere is the paper"%ull paper# of trilogy ")) roor(ee. latest one / Tanuary 2EE4#

1.there is a string a2b$c23"d+ec7b2"e2d3c4$#3#$a4c$& li(e this so u have to ma(e a program that should
contain each letter only one time.!nly $ alphabets a2b2c2d2e will be there in the string and the integer
after the alphabet represent the power.
2.a highly recursive Tava program was there and they were as(ing of two logical error in that.
3a. a circular -ueue is implemented as lin(ed list.u r given the address of a node .
Melete the node"write the program#
3b. how will u delete the node in const. time "mean the list may be of any length and
u r Tust given the address of the node to be deleted#.
4.a table is given which contain the employee name and his manager name ma(e the tree"program#.
the table is something li(e this
employee manager

a b
b c
c d
d d

Você também pode gostar