Sorting Comparisons

¡Supera tus tareas y exámenes ahora con Quizwiz!

Given a binary search tree T , what is the path from a node x to its successor y, assuming that both x and y exist in T ?

This question is more tricky than hard. One thing is to remember that all leftward descendants of x's right child r have keys between x and r; finding the least of these gives the successor of x. The other trick is that x might not have a right child. In that case, x is the rightmost descendant of some ancestor z, which is the left child of a node y (or z is the root, in which case x has no successor in T ). The thing to remember here is similar to the thing to remember in the paragraph above. Specifically, all rightward descendants of y's left child z, including x, have keys between z and y. So y is the successor to x.

Why is quicksort is significantly faster in practice than other O(nlogn) algorithms

because its inner loop can be efficiently implemented on most architectures, and in most real-world data, it is possible to make design choices that minimize the probability of requiring quadratic time. Additionally, quicksort tends to make excellent usage of the memory hierarchy, taking perfect advantage of virtual memory and available caches. Coupled with the fact that quicksort is an in-place sort and uses no temporary memory, it is very well suited to modern computer architectures.

When do u use intro sort

intro sort or introspective begins with quicksort and switches to heapsort when the recursion depth exceeds a level based on (the logarithm of) the number of elements being sorted. It is the best of both worlds, with a worst-case O(n log n) runtime and practical performance comparable to quicksort on typical data sets

Merge sort vs Quick sort Quick sort 39% more comparisons than merge sort.but faster than mergesort in practice because of lower cost of other high-frequency operations.

For Merge sort worst case is O(n*log(n)), for Quick sort: O(n2). For other cases (avg, best) both have O(n*log(n)). However Quick sort is space constant where Merge sort depends on the structure you're sorting.

Quicksort vs heap sort Space complex worst QS log n n2 HS 1 nlogn MS n nlogn

Heapsort builds a heap and then repeatedly extracts the maximum item. Its worst case is O(n log n).But if you would see the worst case of quick sort, which is O(n2), you would realized that quick sort would be a not-so-good choice for large data.' in this case use introsort

Why might quick sort be preferred over insertion sort and merge sort?

In situations where little temporary space is available, merge sort cannot be used, and in such cases, the average-case asymptotic algorithmic complexity of quick sort is superior to that of insertion sort.

highest worst-case asymptotic algorithmic complexity?

Insertion, Quick, Selection sorts

1>Which of the sorting algorithms has the lowest best-case asymptotic algorithmic complexity(INSERTION) 2>Which sort algorithm works best on mostly sorted data?(Not quick sort)

sort

Counting compares and exchanges in simple sorts

So if exchanges cost nothing and only comparisons count, then insertion sort edges out the others. If exchanges count but comparisons cost nothing, then selection sort beats the others asymptotically.


Conjuntos de estudio relacionados

EMT Chapter 20: Allergic Reaction

View Set

PrepU questions for Maternal Health

View Set

learning, memory & consciousness

View Set

Unit 9.3 Persons Subject to State Registration (Series 65)

View Set

Chapter 1: The Nurse's Role in Health Assessment

View Set