Qualcomm Interview Question for Software Engineer / Developers






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

Insertion sort works in linear time....because in the worst case if the 50 unsorted numbers are at the end of the array..then array would have to be shifted approx 50n times..and if 50<<<n..it can be neglected..hence linear time///

- Anonymous January 15, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

a form of merge sort is better.
it can be done in O(n+m*log(m)), which is significantly better then O(n*m) or O(n*log(n)):

1. run over the array, O(n)
1.1. every time encountering unsorted element, move it to array2 (array size will be m).
1.2. since you get gaps, move each sorted element k cells back (where k is the number of dislocated elements), which will leave m empty cells in the end of the array.
2. sort array2 in O(m*log(m))
3. merge sort the two sorted arrays from end to start (for each element choose the better and put it in the end of array1). O(m+n)

- aviad February 03, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

any idea how to solve this question

- cunomad September 08, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

i think insertion sort will work here..as insertion sort works really well on partially sorted arrays

- idea September 08, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

In my opinion insertion sort is the best way to get this done. any thoughts?

- googler September 08, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

yes insertion sort is the best

- cunomadq September 09, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

My first thought was indeed Insertion sort...
But for every displaced number you insert, you'd have to 'shift' the entire sub-array that is larger than the displaced number.
Obviously smells like O(m.n) solution at 'best', n being total numbers (100000), m being displaced numbers (50).
Can't we do better than that, like O(n)?

--- I guess NOT LOL...

- Nix September 10, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I agree, Insertion sort should be the expected answer~

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

For 1000 elements, quick sort is also considered because it might reduce swapping elements overhead in selection sort, but it takes more space.

- Anonymous October 08, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Bubble sort can also work here... It will almost be similar to insertion sort efficiency..

- Bond October 13, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Merge sort scales well to very large lists. Its complexity for sorting the data is o(nlogn) whereas in case of insertion sort the worst case complexity is o(n^2)...

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

insertion sort is the answer, the order is O(n+d), d number of inversions, in this case 50, so it's order O(n).

- Anonymous October 21, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Can you elaborate on how it is O(n+d)?

- Anonymous October 26, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

# of inversions ranges from 50 to 50*n, since we could have a list like [11,12...100, 10,9,...1] where the final 10 elements are the unsorted part and the first 90 elements are the sorted part. In this case all the final 10 elements are inversions for the first 90 elements. Depending on the actual number of inversions/merge sort constants, it might actually be better to merge sort.
merge sort worst case => n log n = 1,000,000
insertion sort worst case => 50*n = 5,000,000

- Anonymous August 05, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think merge sort is the right answer.

- sujit October 29, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Insertion sort is the correct ans.it will require very small number of swap operation (which will be equal to number of inversion) that we can neglect. We will achieve Time complexity almost O(n).
and space O(1)..

- uttam tiwari December 26, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I don't think insertion sort is a good idea. for example, if the array is ascending, and we have several big displaced number at the beginning of the array, how to handle it?
I think the heap sort would be fast, because the heap is almost built.

- Bigmountain January 11, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Why do you even have to use one of the 'standard' sorting algoirthms?

- Anonymous January 11, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

no to insertion sort since O(n^2) is the time complexity.

no to merge sort since given elements of array , it takes space comp. of O(n)

i feel... heap sort O(nlogn)is the best choice with the input arrays itself is used to store data.

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

cook-kim algorithm?

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

Quikcksort is the best. This is also called partition exchange sort. The objective of partition is to allow a specific element to find its proper position with respect to others in the sub array.
Quicksort is fastest with low overhead and its average O(n log n) behavior.

- vv July 01, 2012 | 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