Motorola Interview Question for Software Engineer / Developers






Comment hidden because of low score. Click to expand.
0
of 0 vote

say the data is 1->2->3->4->5->6.

the BST corresponding to this is also 1->2->3->4->5->6 all left pointers being NULL. Thus for a general case of n sorted data elements BST acts as a DS whose selection time is O(n). so overall complexity is O(n^2)

- Anonymous July 27, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

If I understand the question correctly, I think what is asking is basically to demonstrate why a Selection Sort Algorithm has a time complexity of O(n^2) even in the worst case. The question is then making things a bit more complicated by pointing out a Binary Search Tree, but as the commenter above has said, the tree could be made into a regular linear linked list by making all left pointers equal to NULL. So, based on that assumption, a Selection Sort algorithm is O(n^2) because it must loop through the list at least twice, for each item it must find out whether is the largest element in the entire list before placing it at the end with a swap operation. This must be done using two for loops.

- Anonymous January 26, 2013 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More