0 views

Uploaded by Yohanes Suyanto

Tes

Tes

© All Rights Reserved

- Sorting and Searching Algorithms
- Bubble Sort
- Algorithms Tutorials
- Programming Pearls
- Quick Sort
- Java Sorting
- Basic Introduction into Algorithms and Data Structures
- Algorithms
- Lecture 8 Quicksort
- Sec 5.4 ppt.ppt
- Sorting Algos
- Assignment 7: Where Am I?
- daa tutorail.doc
- Abstarct - Information Maximization Approach for Communication Signal Separation
- Questionaire
- 23DemoPartitioning.pdf
- Ble93
- vK_q-C-kXhs
- Quicksort for Lists
- Daniel

You are on page 1of 2

Mei 2017

Advanced Sorting

Writing programs that solve the Programming Projects helps to solidify your under-

standing of the material and demonstrates how the chapter?s concepts are applied.

(As noted in the Introduction, qualified instructors may obtain completed solutions

to the Programming Projects on the publisher?s Web site.)

7.1 Modify the partition.java program (Listing 7.2) so that the partitionIt() method

always uses the highest-index (right) element as the pivot, rather than an

arbitrary number. (This is similar to what happens in the quickSort1.java

program in Listing 7.3.) Make sure your routine will work for arrays of three

or fewer elements. To do so, you may need a few extra statements.

7.2 Modify the quickSort2.java program (Listing 7.4) to count the number of copies

and comparisons it makes during a sort and then display the totals. This pro-

gram should duplicate the performance of the QuickSort2 Workshop applet, so

the copies and comparisons for inversely sorted data should agree. (Remember

that a swap is three copies.)

7.3 In Exercise 3.2 in Chapter 3, we suggested that you could find the median of

a set of data by sorting the data and picking the middle element. You might

think using quicksort and picking the middle element would be the fastest way

to find the median, but there?s an even faster way. It uses the partition algo-

rithm to find the median without completely sorting the data. To see how

this works, imagine that you partition the data, and, by chance, the pivot

happens to end up at the middle element. You?re done! All the items to

the right of the pivot are larger (or equal), and all the items to the left are

smaller (or equal), so if the pivot falls in the exact center of the array, then

it?s the median. The pivot won?t end up in the center very often, but we

can fix that by repartitioning the partition that contains the middle element.

Suppose your array has seven elements numbered from 0 to 6. The middle is

element 3. If you partition this array and the pivot ends up at 4, then you

need to partition again from 0 to 4 (the partition that contains 3), not 5 to 6.

If the pivot ends up at 2, you need to partition from 2 to 6, not 0 to 1. You

continue partitioning the appropriate partitions recursively, always checking

if the pivot falls on the middle element. Eventually, it will, and you?re done.

1

Because you need fewer partitions than in quicksort, this algorithm is faster.

Extend Programming Project 7.1 to find the median of an array. You?ll make

recursive calls somewhat like those in quicksort, but they will only partition

each subarray, not completely sort it. The process stops when the median is

found, not when the array is sorted.

7.4 Selection means finding the kth largest or kth smallest element from an array.

For example, you might want to select the 7 th largest element. Finding the

median (as in Programming Project 7.2) is a special case of selection. The

same partitioning process can be used, but you look for an element with a

specified index number rather than the middle element. Modify the program

from Programming Project 7.2 to allow the selection of an arbitrary element.

How small an array can your program handle?

7.5 Implement a radix sort as described in the last section of this chapter. It should

handle variable amounts of data and variable numbers of digits in the key. You

could make the number-base variable as well (so it can be something other than

10), but it will be hard to see what?s happening unless you develop a routine

to print values in different bases.

- Sorting and Searching AlgorithmsUploaded bySubathra Devi Mourougane
- Bubble SortUploaded byZarnigar Altaf
- Algorithms TutorialsUploaded byanubhavjain28dec
- Programming PearlsUploaded bydasoundofreason1065
- Quick SortUploaded bySnehal
- Java SortingUploaded bytvt61
- Basic Introduction into Algorithms and Data StructuresUploaded byHiếu Nguyễn
- AlgorithmsUploaded bykhey
- Lecture 8 QuicksortUploaded byCraig M
- Sec 5.4 ppt.pptUploaded byTrey Cross
- Sorting AlgosUploaded byapi-19983041
- Assignment 7: Where Am I?Uploaded byJeff Pratt
- daa tutorail.docUploaded byAbirami Satheesh Kumar
- Abstarct - Information Maximization Approach for Communication Signal SeparationUploaded byNikhil Dixit
- QuestionaireUploaded byMaqdoom Mohiuddin
- 23DemoPartitioning.pdfUploaded bybui ton
- Ble93Uploaded byPushkar Pande
- vK_q-C-kXhsUploaded byminh
- Quicksort for ListsUploaded byAakash Nagar
- DanielUploaded bydapeebbstudios
- Lec2cUploaded byPrei Cyy
- chap4Uploaded bykamar
- Backhouse ProblemsUploaded byJason Smith
- BacktrackingUploaded byfarha19
- DSA_MK_Lect2.pdfUploaded byAnkit Priyarup
- Course Design DocumentUploaded byDuong Tong
- ps2solUploaded bydjoseph_1
- Doc1Uploaded byShibin Sbn
- Problem 3Uploaded byKausika Raajan
- LPinMatlab2012Uploaded byPreksha Pandey

- Bda Important QuestionsUploaded byVenkatesh Patnala Soni
- Unit Commitment(1).pdfUploaded bydubstepo
- Parrot Mki9200 User Guide UkUploaded byAbass Gurua
- m-5_docxUploaded byDaniela Vanessa Vilches Perez
- Computer Applications [ICSE] Sample Paper 3Uploaded byGuide For School
- CSU-financial dataUploaded byMJ Galope Elegino
- Enabling LDR Algorithms to Reduce the CE Congestion CaseUploaded byErastus Ndakize
- 2012-11-28 Solving More Trig Equations and Graphing Sine and CosineUploaded bysamjshah
- tpm15.1e_la_312278519781_150612Uploaded byMaya Tes
- Chromaster 400+600Uploaded byMerck Millipore Brasil - Lab Supply Brasil
- Bibnet IntroductionUploaded byMalcolm Garbutt
- Powerschool RTTT IIS1 RFP April 2012Uploaded byA.P. Dillon
- Aspx User ManualUploaded bySmail Amaz
- [Recovery] Cwm Recovery 6.0.3Uploaded byDragos Drg
- isolator 1pdfUploaded bynetsavy71
- Firewall ChecklistUploaded byumeshgurav12
- Evotouch ProtocolUploaded byRoger Schobben
- Use of Sensors and Microcontroller in Time Dependent Physics ExperimentUploaded byAnonymous mMc1M4g5BH
- What if AnalysisUploaded byAbhijeet119
- CodingUploaded byJayaprabhu Prabhu
- Distributed App RemotingUploaded bycantoniol
- osi modelUploaded byriteshrishabh
- CO-3Uploaded bychaitanya
- TX Rx Sequencerv2Uploaded byZulu Bravo Mike
- e tenderUploaded byVatsal Shrivastava
- Rf Dynam ProUploaded byRomoex R Rock
- Posting Payroll Costs to General LedgerUploaded bya_berawi
- Brand ManagementUploaded byAnubhov Jobair
- InfoUploaded byapophis719
- ZPL Code ProgrammingUploaded byNeo Naval