Yahoo Interview Question for Software Engineer / Developers






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

Merge sort is often the best choice for sorting a linked list.

- warlock May 15, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

how do u sort a linked list using merge sort

- z99 June 17, 2008 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

merge sort is not stable sort, .i.e, it needs external storage O(n) to do the merge.
quick sort is stable sort. So if memory is limited, use quicksort.

- tom jerry April 22, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Merge sort IS stable (which means: always N log N, no matter what the input looks like).

At the same time yes indeed it takes some extra storage/memory.

So: if stability is essential (cannot tolerate worst-case scenario for qsort) and some storage is available, consider merge.

- 8x July 23, 2008 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Umm, "stable" means identical values preserve their relative order, which can be useful if the values you're sorting are keys to other data that already have some ordering. Merge sort is stable and real-world quicksort is not.

- Meyer February 07, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Quick sort sorts in place while merge sort requires extra storage of O(n). For Quick sort worst case performance is theta(n^2) while in case of merge sort it is always O(n).
1. If inplace sorting is required quick sort is best option.
2. If input data is baised and follows a particular pattern then Quick sort may not give you O(nlon(n)) performance. In that case merge sort or randomized quick sort can be used.

- teki June 25, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Merge sort worst case performance is theta(nlog(n))

- teki June 25, 2008 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

merge sort is usually a stable sorting algorithm.

- dandy June 25, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

quick sort is in place sort
merge sort is not

- asuran October 14, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

complexity: merge sort: average and worst case o(nlogn); quick sort: average O(nlogn), worst case O(n^2);
Space: merge sort: extra space; quick sort: in place
Stability: merge sort: stable; quick sort: not stable

Best fit: merge sort: slow seqential media; quick sort: general purpose.

- John March 11, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

1. MergeSort Complexity O(nlong) but merging process is very expensive thats why T(n) <= cnlog constant c is much bigger.
2. Quick Sort on an average works nlogn but partition process is very simple so constant is very small.

- MaYanK November 27, 2009 | 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