1 / 16

Quick Sort And Merge Sort Technique

Quick Sort And Merge Sort Technique. Sorting. The Process of rearranging the elements so that they are in ascending order or descending order is called sorting. Example: arranging of numbers, student records. very essential for searching the

lamar
Télécharger la présentation

Quick Sort And Merge Sort Technique

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Quick Sort AndMerge SortTechnique

  2. Sorting • The Process of rearranging the elements so that they are in ascending order or descending order is called sorting. • Example: arranging of numbers, student records. very essential for searching the dictionaries, telephone directories.

  3. Properties The two Main properties of sorting techniques are: • Stable: If the sorting algorithm preserves the relative order of any two equal elements,then the sorting algorithm is stable. • In Place: If an algorithm does not require an extra memory space except for few memory units,then the algorithm is said to be in place.

  4. Sorting Algorithms Various sorting algorithms are Quick Sort Merge Sort Bubble Sort Selection Sort Insertion Sort

  5. Quick sort In quick sort, partition the array into two parts such that elements towards left of key element are less than key element and elements towards right of key element are greater than key element. Sort the left part of the array recursively. Sort the right part of the array recursively.

  6. Execution Example • Quick

  7. Time Complexity(Quick sort) T(n) = O(n log n) T(n) = θ(nlog2n) T(n) = O(n log n) • The time complexity of Quick sort is: Worst case: Average case: Best case:

  8. Advantage In place algorithm Applied to files of any size Since I/O is largely sequential tape can be used It used for all type of sorting

  9. Disadvantage Time complexity is greater than merge sort It gives different time complexity in all cases.

  10. Merge sort In merge sort, a given array of elements is divided into two parts. The left part of the array as well as the right part of the array is sorted recursively. Later, the sorted left part and the sorted right part are finally merged into a single sorted vector. The process of merging of two sorted vectors into a single sorted vector is called simple merge.

  11. Execution Example • Merge 7 2 9 4  3 8 6 11 2 3 4 6 7 8 9 7 2  9 42 4 7 9 3 8 6 1  1 3 6 8 7  22 7 9 4  4 9 3 8 3 8 6 1  1 6 77 22 9 9 4 4 33 88 66 11 Merge Sort

  12. Time complexity(Merge sort) T(n) = θ(nlog2n) • The time complexity of Merge sort in all three cases (best,average&worst) is:

  13. Advantage Stable Algorithm Applied to files of any size Used for internal sorting of arrays in main memory Most popular algorithm for all type of sorting

  14. Disadvantage It uses more memory on the stack because of the recursion Use extra space proportional to N. so the algorithm is not in place

  15. Conclusion By comparing all the sorting techniques Merge sort time complexity is less in all three cases (time consuming is less). So, Merge sort is the most efficient technique when compare to all other sorting techniques.

  16. Bibliography Anany LevitinIntroduction to The Design & Analysis of Algorithms, Second Edition,Pearson education Website:- www.academics.smcvt.edu www. wikipedia.org/sorting

More Related