DOC PREVIEW
UCF COT 4810 - Heaps And Merges

This preview shows page 1-2-3-4-5 out of 16 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 16 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 16 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 16 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 16 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 16 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 16 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Sorting Algorithms Heaps and MergesSorting AlgorithmSlide 3Heap SortSlide 5Slide 6Slide 7Slide 8Merge SortSlide 10Slide 11Slide 12Slide 13Slide 14HomeworkWork SitedSorting Sorting AlgorithmsAlgorithmsHeaps and MergesHeaps and MergesCOT 4810COT 4810Topics in Computer ScienceTopics in Computer ScienceAlbert ParkAlbert ParkFebruaryFebruary 55, 2008, 2008Sorting AlgorithmSorting AlgorithmList and elements(or records)List and elements(or records)Algorithm that puts elements of a list in a Algorithm that puts elements of a list in a specific orderspecific orderIncreasing or decreasingIncreasing or decreasingNumerical orderNumerical orderEfficient and optimizeEfficient and optimizeSorting AlgorithmSorting AlgorithmThe fastestThe fastestHeap and Merge sortHeap and Merge sortTime complexityTime complexityO(n log n)O(n log n)Stable (Heap) vs. Unstable (Merge)Stable (Heap) vs. Unstable (Merge)Heap SortHeap SortDef: A sort algorithm that builds a heap, Def: A sort algorithm that builds a heap, then repeatedly extracts the maximum then repeatedly extracts the maximum item. item. Complete tree Complete tree Proposed by J.W.J. Williams in 1964.Proposed by J.W.J. Williams in 1964.Implementation by Robert W. Floyd in Implementation by Robert W. Floyd in 1964.1964.Heap SortHeap SortPseudocodePseudocodeStart at the beginning root nodeStart at the beginning root nodeSet Set nn = length of the list = length of the listwhile while nn > 0 { > 0 {swap (list[0], list[swap (list[0], list[n-n-1])1])while start > while start > n {n { for node list[start] // usually start is the root nodefor node list[start] // usually start is the root node mm = min(ChildA, ChildB) // find the minimum = min(ChildA, ChildB) // find the minimum value of its value of its childchild if list[start] > if list[start] > mm then swap(list[start], list[ then swap(list[start], list[mm]) ]) and start = and start = mm otherwise break out of while loop otherwise break out of while loop }}nn = = nn-1 }-1 }Heap SortHeap SortExampleExampleFirst construct a First construct a heap.heap.Then sort the heap Then sort the heap tree.tree.101022449911Heap SortHeap SortExample cont.Example cont.102914Heap SortHeap SortExample cont.Example cont.149102Merge SortMerge SortDef: A sort algorithm that splits the Def: A sort algorithm that splits the items to be sorted into two groups, items to be sorted into two groups, recursively sorts each group, and recursively sorts each group, and merges them into a final, sorted merges them into a final, sorted sequence.sequence.Divide and ConquerDivide and ConquerMemoryMemoryMerge SortMerge SortPseudocodePseudocodesort(sort(ii, , jj): if ): if ii = = jj then return then returnelseelsekk = ( = (ii++jj)/2)/2sort(sort(ii, , kk)) sort(sort(kk+1, +1, jj))merge A(merge A(ii, , kk) and A() and A(kk+1, +1, jj))sort(1, sort(1, nn))Merge SortMerge SortPseudocodePseudocodemerge: merge: jj= = kk = 1 = 1for for ii = 1 to = 1 to nn if B( if B(jj) > C() > C(kk) then A() then A(ii) = B() = B(jj) ) and and jj = = jj+1+1 else A( else A(ii) = C() = C(kk) and ) and kk = = kk+1+1Merge SortMerge SortExampleExampleDivideDivideConquerConquer101022449911Merge SortMerge SortExample cont.Example cont.10102244991110102244991110102244111010991199224422101044Merge SortMerge SortExample cont.Example cont.224410101199112244991010HomeworkHomeworkList 1 [3, 6, 4, 1, 5, 9, 2, 8]List 1 [3, 6, 4, 1, 5, 9, 2, 8]1. Sort the list above by using heapsort.1. Sort the list above by using heapsort.2. Sort the list above by using 2. Sort the list above by using mergesort.mergesort.3. What is the time complexity for both 3. What is the time complexity for both heap and merge sorts?heap and merge sorts?Work SitedWork SitedDewdney, A.K. Dewdney, A.K. The New Turing Omnibus.The New Turing Omnibus. New York: Computer Science Press, 1989.New York: Computer Science Press, 1989.Belzer, Jack Belzer, Jack Encyclopedia of Computer Encyclopedia of Computer Science and Technology.Science and Technology. New York: New York: Marcel Dekker, INC., 1994.Marcel Dekker, INC., 1994.Black, Black, Paul E. "heapsort", in Paul E. "heapsort", in Dictionary of Algorithms and Data StructuDictionary of Algorithms and Data Structuresres [online], Paul E. Black, ed., [online], Paul E. Black, ed., U.S. National Institute of Standards and U.S. National Institute of Standards and TechnologyTechnology. 14 May 2007. . 14 May


View Full Document

UCF COT 4810 - Heaps And Merges

Documents in this Course
Spoofing

Spoofing

25 pages

CAPTCHA

CAPTCHA

18 pages

Load more
Download Heaps And Merges
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Heaps And Merges and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Heaps And Merges 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?