hari@hbiz.in
BAN USER
- 4of 4 votes
AnswersWhat is the data structure you will use to model Tennis tournament of size number of players n=8. Splitted into 2 groups? What is the complexity of finding the winner and the runner.
- hari@hbiz.in in India| Report Duplicate | Flag | PURGE
Synopsys R&D Software Engineer / Developer Data Structures
Not sufficient in this case. Amazon expects us to check for subtrees.
- hari@hbiz.in August 29, 2012Very good point. But preorder testing is required only if you are given the tree in form of list or array. If the tree itself is given, then any one traversal is sufficient with node by node comparison.
- hari@hbiz.in August 27, 2012What is the logic behind checking preorder too?
- hari@hbiz.in August 26, 2012Sorry. It is a binary tree but not a BST
- hari@hbiz.in August 26, 2012typedef struct TNode
{
int value;
TNode *left;
TNode *right;
} TNode;
bool ifExist(const TNode* treeA, const TNode* treeB);
bool isSubtree(const TNode* treeA, const TNode* treeB)
{
if (treeB == NULL)
{
// if treeB is null no point in searching.
return true;
}
bool a_has_b = ifExist(treeA,treeB);
bool b_has_a = false;
// Check only if treeB is not found in treeA.
if (!a_has_b)
b_has_a= ifExist(treeB,treeA);
return a_has_b || b_has_a;
}
bool ifExist(const TNode* treeA, const TNode* treeB)
{
if ( treeA == NULL && treeB != NULL)
{
// We reached the end of path. No subtree found.
return false;
}
if ( treeA == treeB)
{
return CompareTheSubtree(treeA,treeB);
}
return ifExist(treeA->left,treeB)|| ifExist(treeA->right,treeB);
}
Note : I have not written CompareTheSubtree() method as it is trivial.
- hari@hbiz.in August 26, 2012Travel through tree A, and search for node B if not found, travel through Tree B and search for node A. If you found in either case, compare the elements.
- hari@hbiz.in August 26, 2012Why recursion when the following code can do the same.
K=A;
for ( i=1;i<n;i++)
{
k= K*A;
}
Can somebody throw some explanation here.
- hari@hbiz.in August 16, 2012This is what it doing
Input
4
2 5
1 7
After completing swapping at 2
4
2 5
1 7
Swapping at 4
4
5 2
7 1
Swapping at 2
4
5 2
7 1
This is mirror image of structure but not data.
Say the set N =3 { 1,2,3}
Combinations are {1,2} {2,3} {1,3}
Say the set N= 4 {1,2,3,4}
Combinations are {1,2,3 }, {1,2,4}, {1,3,4}, {2,3,4}
Slightly modified
void verticalSum( TNode* node, int *arr, int Level)
{
if (node==NULL) return;
verticalSum(node->Left,arr, Level-1);
arr[Level]=arr[Level]+node->value;
verticalSum(node->Right,arr,Level+1);
}
Solution using a queue and stack. No hack. o(n2)
Convert2DLL(Queue queue,int level, list** head)
{
Queue nextqueue;
Stack stack;
if (queue.empty())
return;
while ( !queue.emtpy() )
{
TNode *node= queue.pop();
if (level%2 == 1)
{
stack.push(node->left);
stack.push(node->right);
}
else
{
nextqueue.push(node->left);
nextqueue.push(node->right);
}
*head->right=node;
node->left=*head;
*head=node;
*head->right=null;
}
if ( level%2 == 1)
{
while ( !stack.empty)
{
node *temp = stack.pop();
nextqueue.push(temp);
}
}
queue = nextqueue;
Convert2DLL(queue,level++, head);
}
No need of 2 digits if we can XOR the a[num] with 1 (assume all the a[elements] initialized with 0) . If at all an XOR with 1 returns a 0, we can assume it is a duplicate and return it. Only thing is we don't know whether a number occurred or not, which is not required in the current case.
- hari@hbiz.in August 12, 2012Can you please help me to understand why do we require 2 bits? A 1 bit array of size 4294967295 is sufficient right?
- hari@hbiz.in August 12, 2012I believe your algorithm won't work or I misunderstood it, can you prove how your algorithm will generate a value 15?
- hari@hbiz.in August 11, 2012Good approach. But when large number of elements checked out, a BST, would give a better performance than linked list.
- hari@hbiz.in August 11, 2012For min-heap, we can use a BST.
- hari@hbiz.in August 11, 2012No. Complexity is O(n+m+ (n-m) ). Worst case is o(3n.)
- hari@hbiz.in August 10, 2012
Repannadwilliams31, Applications Developer at National Instruments
I am Anthony, Human Resources specialist with a decade of successful experience in hiring and employee management.I am a ...
Replisafergusona, Consultant at Myntra
I am Lisa from Chicago,I am working as a Show host in the New World. I also work Performs ...
Repnoradweisser, Backend Developer at ASU
I am Nora, I am a writer, I write many types blogs and articles. I collected many types and astrology ...
Repjoyceeallard, Associate at Adap.tv
Hi, i am working as a training manager as a business professional who assesses the growth and development needs of ...
Repaanyagill, café manager at The Best Cafe
Unshakable dedication to bringing out the best in a restaurant and its employees, while taking exemplary care of guests and ...
Repcharlieesandobal, Security Analyst at ADP
I am Charliee , a dedicated security professional at Monsource for the last 6 years managing security teams and corporate environments ...
RepJennyReimer, Dev Lead at Adobe
Badminton lover, coffee addict, guitarist, International Swiss style practitioner and TDC honorary member. Acting at the nexus of simplicity and ...
Repvaleriecfranks, Computer Scientist at ASAPInfosystemsPvtLtd
A strong writer with a passion for story-telling who has extensive experience of writing literary compositions, articles, reports, books and ...
RepShastri Ji is well known hindi and tamil vashikaran specialist. He will give you effective and simple totke to control ...
Repalicesreedg, Accountant at ADP
Hi my name is Alice and i am working in an IT company. I am working here from last 5 ...
Repcharlesndouglass, Employee at VANS
I am Michael from Nantucket USA. I am working as a Power plant dispatcher in Matrix Design company. I am ...
RepSpent 2001-2006 licensing the elderly in Jacksonville, FL. Spent 2001-2004 consulting about Break Up Spell. Spent two years deploying crickets ...
Repshanamkyler38, AT&T Customer service email at ABC TECH SUPPORT
Hi, I am Shana and I live in Chicago USA .I am working as a Tax preparer in an Adaptabiz ...
Repsuejnagel, Virus Researcher at Email Customer Service
Hello, I am Sue . I am a chief information officer at Vernon. I am responsible for providing the global communications ...
Reprchierusel, Applications Developer at Allegient
I am a Real-time captioner in the USA . Real-time captioning can be used for programs that do not have written ...
Reptaniajclover, Analyst at Amdocs
Hi, I am Tania from Tuckahoe USA, I am working as a Public relations representative in Gamble-Skogmo company. I like ...
Rephallieriddic, HR Executive Trainee at Barclays Capital
I am Hallie, Dedicated and experienced administrative secretary who excels at prioritizing , completing multiple tasks simultaneously and following through to ...
Repbarrietrosado, abc at ABC TECH SUPPORT
Hi, I am Barrie, from Ualapue USA. I believe that every challenge has a solution - and I take great satisfaction ...
Repbradybally973, Computer Scientist at AMD
I am a network administrator. I live in Washington USA .My responsibility includes maintaining computer infrastructures with emphasis on local ...
RepWilliamDGiles, Cloud Support Associate at ADP
Spent 2001-2006 creating marketing channels for tar worldwide. Was quite successful at building tobacco for farmers. Won several awards for ...
Repkarmacknha, Accountant at Groupon
I am a forensic nurse . who has received specific education and training. I provide specialized care for patients who are ...
RepLizzieGibson, Cloud Support Associate at Aspire Systems
I'm an engineering student from Huntsville, AL USA. Have more interest in management and stuff related to business. Promptly ...
RepSoccer lover, coffee addict, guitarist, International Swiss style practitioner and TDC honorary member. Acting at the nexus of simplicity and ...
Repcherylthurber, Developer Advocate at Absolute Softech Ltd
Hi,I am from Taxes, USA. Passionate multilingual translator with 2.5 years experience in Spanish-English translations.Looking to further ...
Repbrittneykestro, Personnel at Absolute Softech Ltd
I’m Brittney , an experienced professional working as a Recreation leader provides social services to disadvantaged Children, Families, Schools, and ...
Repaaronmdunlap6, Area Sales Manager at Achieve Internet
Hi, I am an HR Analyst with extensive experience delivering innovative solutions at the corporate level. Expertise in employee relations ...
Repbrandysolsen, Area Sales Manager at AMD
I am a Social butterflies who enjoy travel.Have fun doing this job and project an atmosphere that reflects Amazon ...
Repmerrittmonique9, Android Engineer at AMD
I am Monique and working in high court from last 20 years.Handel many cases in my career.Build and ...
Repmelissamewingm, abc at ABC TECH SUPPORT
I am Melissa from Springdale. I function as an Auditing assistant in Bountiful Harvest Health Food Store. My solid interest ...
Repceciliajbaker24, Area Sales Manager at ABC TECH SUPPORT
I work as an Aide at the Alhambra Maker-space, consulting ASU students who come into the space with their projects ...
Repsusiejcrider, Member Technical Staff at Accolite software
I was a Communications Consultant with experience in working across various clients .technology, consumer, hospitality, financial services and corporate social ...
Repmarywwaldrop7, Computer Scientist at Chelsio Communications
I am Mary ,working in the field of training and development coordinator for three years, focusing on teaching English as ...
RepRichardWParks, Accountant at ADP
knock outs
- hari@hbiz.in September 26, 2012