4.2Givenadirectedgraph,designanalgorithmtofindoutwhetherthereisaroutebetweentwonodes.Node
{
List<Node>neighbours;
}
booleanisConnected(Nodefrom,Nodeto)
{
Stack<Node>toVisit=initStack();
Set<Node>seen=initSet();
toVisit.push(from);
while..
分类:
其他好文 时间:
2014-11-27 08:05:32
阅读次数:
147
4.3Givenasorted(increasingorder)array,writeanalgorithmtocreateabinarytreewithminimalheight.[1,2,4,5,6]CreateaBTwithminheight.=>balancedtree.Nodebuild(intarray)
{
returnbuild(array,0,array.length-1,null);
}
O(logn)
privateNodebuild(int[]array,intfrom,int..
分类:
其他好文 时间:
2014-11-27 08:04:10
阅读次数:
189
4.1Implementafunctiontocheckifatreeisbalanced.Forthepurposesofthisquestion,abalancedtreeisdefinedtobeatreesuchthatnotwoleafnodesdifferindistancefromtherootbymorethanone.Abalancedtree?http://en.wikipedia.org/wiki/Self-balancing_binary_search_treeIteratethetr..
分类:
其他好文 时间:
2014-11-27 08:03:52
阅读次数:
190
4.4Givenabinarysearchtree,designanalgorithmwhichcreatesalinkedlistofallthenodesateachdepth(i.e.,ifyouhaveatreewithdepthD,you’llhaveDlinkedlists).List<List<Node>>build(Noderoot)
{
List<List<Node>>toReturn=initList();
build(root,0,toR..
分类:
其他好文 时间:
2014-11-27 08:02:53
阅读次数:
189
4.6Designanalgorithmandwritecodetofindthefirstcommonancestoroftwonodesinabinarytree.Avoidstoringadditionalnodesinadatastructure.NOTE:Thisisnotnecessarilyabinarysearchtree.BTNodefind(Noden,Nodea,Nodeb)
{
if(n==a||n==b)
{
returnn;
}
intnodeMatch=nodeMatch(a...
分类:
其他好文 时间:
2014-11-27 08:02:42
阅读次数:
180
4.5Writeanalgorithmtofindthe‘next’node(i.e.,in-ordersuccessor)ofagivennodeinabinarysearchtreewhereeachnodehasalinktoitsparent.//BST.
classNode
{
Nodeparent;
Nodeleft;
Noderight;
}
Nodemin(Nodenode)
{
if(node==null)
returnnull;
while(node.left!=null)
nod..
分类:
其他好文 时间:
2014-11-27 08:01:56
阅读次数:
218
Oracle Interview Questions
分类:
数据库 时间:
2014-11-25 14:19:56
阅读次数:
261
Oracle Interview Questions
分类:
数据库 时间:
2014-11-25 14:18:51
阅读次数:
306
Oracle Interview Questions
分类:
数据库 时间:
2014-11-25 14:18:50
阅读次数:
393
Oracle interview - General Questions
分类:
数据库 时间:
2014-11-25 14:14:58
阅读次数:
191