Quicksort & Quickselect

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Is Quicksort slower than Mergesort?

No, it's absolutely faster.

What is the best case for quick sort?

Number of compares is ~N lg N.

What is the worst case for quick sort?

Number of compares is ~½ N^2.

One of the big advantages of Quicksort over Mergesort is ...

One of the big advantages of Quicksort over Mergesort is that it doesn't take any extra space.

Proposition. Quicksort is an in-place sorting. Prove it.

Partitioning:constant extra space. Depth of recursion: logarithmic extra space (with high probability).

Why does Arrays.sort() in Java use quicksort instead of mergesort when sorting primitive types ?

Quicksort is in-place and is typically the fastest general-purpose sorting algorithm in practice.

Is Quicksort stable?

Quicksort is not stable cuz partitioning does one of those long range exchanges that might put a, a key with equal value over a key another key with the same value.

Running time depends on ...

Running time depends on random shuffle

Why quick sort is faster than marge sort in practise'

Because of less data movement.

What is average case for quick sort?

Expected number of compares is ~ 1.39 N lg N. 39% more compares than merge sort. Faster than merge sort in practice because of less data movement.

the system sort would be completely solid with all this resource with all these research and all of the development that's going into it?

In fact there's a file out there in your book site and get it that will actually break the Java system sort. There was a killer input that will make the thing run in quadratic time. Actually it usually crashes because it's recursive and it crashes the system stack. And it can cause all sorts of problems. There's a killer input for the system sort and, and it can be disastrous in various systems and the reason is, they didn't do the random shuffling.

What are the steps of Quicksort?

Step 1. Shuffle the array Step 2.Partition the array so that, for some j *Entry a[j]is in place. *No larger entry to the left of j. *No smaller entry to the right of j. Step 3. Sort each subarray recursively.

Why does Arrays.sort() in Java use mergesort instead of quicksort when sorting reference types ?

The Java API for \verb#Arrays.sort()#Arrays.sort() for reference types requires that it is stable and guarantees n \log n performance. Neither of these are properties of standard quicksort.

What is the expected running time of randomized quicksort to sort an array of nn distinct keys when the array is already sorted?

The expected number of compares is ∼2n ln n. linearithmic.

Quickselect method takes linear time on the average. True or False.

True.

Is Quicksort a recursive method?

Yes, it's also a recursive method, but the basic idea behind Quicksort is that it does the recursion after it does the work, whereas Mergesort did it before it did the work.

Quick sort is guaranteed to be correct. Is it True?

Yes, true.

What is the expected running time to find the median of an array of nn distinct keys using randomized quickselect?

linear. This is the main advantage of quickselect over quicksort—the expected number of compares is linear instead of linearithmic.

How many compares to partition an array of length N?

~N lg N


Kaugnay na mga set ng pag-aaral

BIO 354 Human Anatomy (Exam 6: Digestive, Urinary, Endocrine, and Reproductive Systems)

View Set

Sling Load Inspector Certification Course

View Set

Theology chapter 5 Judges & Kings

View Set

Basic Vehicle Technologies 2: Engines

View Set

The Carolingian Achievement and Legacy

View Set

Direct Participation Programs (DPPs)

View Set