## Motorola Interview Question for Software Engineer / Developers

• 0

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)

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.

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.

### 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.