Microsoft Interview Question for Software Engineer / Developers






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

Heapsort shall be used if you dont have any extra space. Quicksort requires extra log(n) space whereas MergeSort requires extra 'n' space.
Apart from this, worst case scenario of quick sort is O(n*n), when array is sorted in reverse order...whereas Heap sort works well in all the cases. I prefer Heap sort because it is inplace sorting and performs well in worst case. However depending on iput type once can choose any sorting algo.

- Sukku April 17, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

* Quicksort is in place sorting
* Mergesort requires O(n/2) additional space, while merging just make a copy of the left (1st) array: no need to make a complete copy
* Heapsort does not offer any advantages I think over the above 2 if the sorted elements are static but if they can change then maintaining the heap property takes O(lg N) time.

- Andy May 02, 2007 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Andy, you should apply for NOBEL PRIZE if you can give an in place Quick Sort algo.

Us commoners only know recursive algo which needs
O(log n) stack space

- TheGreatOne September 07, 2007 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Quick sort doesnt take extra space. You can pass pointer to array since all the partitions are disjoint

- Noname March 19, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

That is not true. Storing the memory addresses still requires memory

- J May 04, 2008 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

http://en.wikipedia.org/wiki/Quicksort

Quick sort, inplace

- Give Wikipedia a Nobel Prize October 21, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

partition is inplace ..the entire sorting requires log n additional space

- aryan May 16, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

For linked list, Merge sort is the best option.

- Rusho February 17, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Stabilty is one more point :
> In-place quick sort in not stable you can code stable quick-sort ,but Merge-sort is stable sort > heap sort have all case running time o(n*log n) same as quick sort but constant factor of heap-sort is big
> Merge sort is better for external sort if your data does not fit in memory

- Ganesh January 09, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

heap sort best case is O(n) not O(n*logn)

- ram January 09, 2014 | Flag


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