9 views

Uploaded by Thu Vu

- 7 - 1 - Quicksort (1933)
- Interview Experience
- cs1927 15s2 - Week05 Tut
- Sorting Algorithms
- ada
- L10 - Sorting.pdf
- Data structures project
- Goodrich_6e_Ch12_RadixSort-handouts.pdf
- Advanced Sorts
- pxc3905155(1)
- Types of Sorting
- Sorting
- Dsa 06 t Shankar
- Assignments BSCS Programming Fundamental
- Analysis of Insertion and Merge Sort
- 03 Fusion
- C Questions and Answer
- CS101_PrelimReviewer
- STL Mutating Generic Algorithms
- Fast Sorting on a Distributed-Memory Architecture, MIT

You are on page 1of 3

Tutorial 6 Questions SORTING ALGORITHMS

Required Questions Question 1. Many operations can be performed faster on sorted than on unsorted data. For which of the following operations is this the case? a. checking whether one word is an anagram of another word, e.g., plum and lump b. findin the minimum value. c. computing an average of values d. finding the middle value (the median) e. finding the value that appears most frequently in the data Question 2. In which case, the following sorting algorithm is fastest/slowest and what is the complexity in that case? Explain. a. insertion sort b. selection sort c. bubble sort d. quick sort

Question 3. Consider the sequence of integers S = {5, 8, 2, 4, 3, 6, 1, 7} For each of the following sorting algorithms, indicate the sequence S after executing each step of the algorithm as it sorts this sequence: a. insertion sort b. selection sort c. heap sort d. bubble sort e. merge sort

Faculty of Computer Science and Engineering Department of Computer Science Question 4. Consider the sequence of integers T = {1, 9, 2, 6, 4, 8, 0, 7} Indicate the sequence T after executing each step of the Cocktail sort algorithm (see Appendix) as it sorts this sequence. Advanced Questions Question 5. A variant of the bubble sorting algorithm is the so-called odd-even transposition sort . Like bubble sort, this algorithm a total of n-1 passes through the array. Each pass consists of two phases: The first phase compares array[i] with array[i+1] and swaps them if necessary for all the odd values of of i. The second phase does the same for the even values of i. a. Show that the array is guaranteed to be sorted after n-1 passes. b. What is the running time of this algorithm?

Appendix Cocktail sort Cocktail sort, also known as bidirectional bubble sort, cocktail shaker sort, shaker sort (which can also refer to a variant of selection sort), ripple sort, shuffle sort, shuttle sort or happy hour sort, is a variation of bubble sort that is both a stable sorting algorithm and a comparison sort. The algorithm differs from bubble sort in that it sorts in both directions on each pass through the list. This sorting algorithm is only marginally more difficult to implement than bubble sort, and solves the problem with so-called turtles in bubble sort. (Wikipedia) Pseudocode

procedure cocktailSort( A : list of sortable items ) defined as: do swapped := false for each i in 0 to length( A ) - 2 do: if A[ i ] > A[ i + 1 ] then // test whether the two elements are in the wrong order swap( A[ i ], A[ i + 1 ] ) // let the two elements change places swapped := true end if end for if swapped = false then // we can exit the outer loop here if no swaps occurred. break do-while loop end if swapped := false for each i in length( A ) - 2 to 0 do:

if A[ i ] > A[ i + 1 ] then swap( A[ i ], A[ i + 1 ] ) swapped := true end if end for while swapped // if no elements have been swapped, then the list is sorted end procedure

-- End --

- 7 - 1 - Quicksort (1933)Uploaded byeshwaar1
- Interview ExperienceUploaded byNitin Nilesh
- cs1927 15s2 - Week05 TutUploaded byVictor
- Sorting AlgorithmsUploaded byHarsh Wadia
- adaUploaded byrh1234567
- L10 - Sorting.pdfUploaded byDAWIT SEGED
- Data structures projectUploaded bysarath
- Goodrich_6e_Ch12_RadixSort-handouts.pdfUploaded byDAWIT SEGED
- Advanced SortsUploaded bykumaransaha
- pxc3905155(1)Uploaded bysubin
- Types of SortingUploaded byScott Kramer
- SortingUploaded bykaustubhrsingh
- Dsa 06 t ShankarUploaded byapi-3737469
- Assignments BSCS Programming FundamentalUploaded byMuhammad Ajmal Malik
- Analysis of Insertion and Merge SortUploaded byRohit Chaudhary
- 03 FusionUploaded byWalter Cabrera
- C Questions and AnswerUploaded byusama32
- CS101_PrelimReviewerUploaded byMicah Encarnacion
- STL Mutating Generic AlgorithmsUploaded byMichael
- Fast Sorting on a Distributed-Memory Architecture, MITUploaded byAndrew Alexander
- Data Structures and Algorithms - Linked ListsUploaded byaadatti
- Daa Bits Manual-1Uploaded byIAm DEnZiL
- Odd Even Vector SorterUploaded byAnthony Sazon Tolentino
- PDC95Uploaded byAmmar Haj Hamad
- Problem Solving and Python Programming - 2 MarksUploaded byvignesh
- msortUploaded byariyan_eghbal
- MSC_Final_Syllabus_2007_09Uploaded byKoushal Gadekar
- dsa ch1 introductionUploaded byapi-394738731
- NEW DSUploaded byNarendra Rajput
- Data Structures Project1Uploaded byMatthew

- ExercisesUploaded byThu Vu
- Kinh Nghiem Sat Hach CNTTUploaded byBố Đéo
- Tut 7_SolUploaded byThu Vu
- Tut 2Uploaded byThu Vu
- dsachdot1Uploaded byThu Vu
- vq-ubmUploaded byThu Vu
- ClippingUploaded byThu Vu
- Report 1Uploaded byThu Vu
- ExercisesUploaded byThu Vu
- Assignment Web ProgrammingUploaded byThu Vu
- nhan dang nguoi noiUploaded byThu Vu
- thicuoikyUploaded byThu Vu
- Gmmubm Vqubm ComparisonUploaded byThu Vu
- ExercisesUploaded byThu Vu
- ExercisesUploaded byThu Vu
- Tut1 SolutionUploaded bybuiductaianh
- dsachdot1Uploaded byThu Vu
- Tut+6 Sol ReleaseUploaded byThu Vu
- Final2011 SolUploaded byThu Vu
- Final 2010Uploaded byThu Vu
- Final 2010Uploaded byThu Vu
- LayoutUploaded byThu Vu
- Exercise1_w2_vn_v1.1Uploaded byThu Vu
- Tut 4Uploaded byĐừngh
- Tut5_SolUploaded byThu Vu
- Tut2 SolutionUploaded byThu Vu
- Tut2_200213Uploaded byThu Vu
- Tut2_200213Uploaded byThu Vu
- Tut5Uploaded byThu Vu

- Construction & Project Management for Highway TunnelsUploaded byShreedhar
- Copy of KPI bow (3)Uploaded bymustika05
- ResearchUploaded byRicka Mhaey
- CDP modelUploaded byOualid Boukerrou
- 6ED10522MD080BA0 Datasheet EnUploaded byMiroslav Simeunovic
- CPU Scheduling AlgorithmUploaded byFrancisEmmanuelGonzaga
- CAV GATE ProspectusUploaded byMalay H Kenia
- 19.2 First Order Differential EquationsUploaded bySalma Sherbaz
- DS_Fax Appliance A102 A104Uploaded byJohnson Lukose
- Iso- Procedure IndexUploaded bydyahousen
- Codd's 12 Rules for an RDBMS - 7 pagesUploaded byPrez Eric Frimpong
- Cable Tie Type Classifications 2015-12-04Uploaded byGloria Hamilton
- Boyle's Law22 Lesson PlanUploaded byMontesa Allana Ea
- LCR-93-InstallationManualUploaded byPrabhat Gubrani
- samajUploaded byAnand Swarnkar
- Vintage Airplane - Aug 1983Uploaded byAviation/Space History Library
- ANFISUploaded byEzequiel Pezo
- Microwave Antennas and PropagationUploaded byslysoft.20009951
- Gfx 3.3 Clik User GuideUploaded byMts Jln
- P2P DocumentUploaded byPreethi Kishore
- Water Distribution System Monitoring and Decision Support Using a Wireless Sensor NetworkUploaded byJairo Velasquez
- RR Kamawa A3_0908_tcm92-8662Uploaded bychmatias
- Marine Analytical ChemistryUploaded byAlimjan Abla
- Bulk Receiving ProceduresUploaded byemongclooney11
- MTPQSM072916Uploaded bypfalencar
- Derivation of the Boltzmann DistributionUploaded byyuyiip
- Potential TransformerUploaded byVijay Pandit
- basic encoding.pdfUploaded byGreg Terrones Mueco
- Professional Issues For EngineersUploaded byMalith De Silva
- 02 BridgeUploaded byMoussa Rili