450 likes | 469 Views
Document that explains the chosen concept to the animator. 1. Quick Sort. Course Name: Design and Analysis of Algorithm Level: UG. Authors :-Praveen Pal Mentor :- Aruna Adil. 2. Learning Objectives. After interacting with this Learning Object, the learner will be able
E N D
Quick Sort Course Name: Design and Analysis of Algorithm Level: UG. Authors :-Praveen Pal Mentor :- Aruna Adil 2
Learning Objectives After interacting with this Learning Object, the learner will be able • to: Sort an array using Quick sort. • How Quick sort works. • Advantages of quick sort over other sorting algorithm 3
Definitions of the components/Keywords: 1 • Quick sort is a randomized sorting algorithm based on the divide & conquer paradigm. • Divide:- If the given sequence of values (array)has two or more element then pick an element x (Called pivot) randomly from sequence and partition the array into sub-array. L(low): sub-array contains elements less than x. E(Equal): sub-array contains element equal to x. G(Greater): sub-array contains elements greater than x. • Recursively sort L and G (ie. apply the same process written above for L & G) Conquer: Finally join L, E & G. • This algorithm is capable to sort large number of input very quickly that’s why this algorithm is called quick sort . • This sorting technique is also called the “in-place sorting” because it does not require extra space for sorting . 2 3 4 5 4
INSTRUCTIONS SLIDE Master layout or diagram 1 • Make a schematic diagram of the concept • Explain to the animator about the beginning and ending of the process. • Draw image big enough for explaining. • In above image, identify and label different components of the process/phenomenon. (These are like characters in a fi lm) • Illustrate the basic flow of action by using arrows. Use BOLD lines in the diagram, (minimum 2pts.) • In the slide after that, provide the definitions of ALL the labels used in the diagram 2 3 4 5 5
IMPORTANT NOTE TO THE ANIMATOR: • All the instructions/labels or anything WRITTEN in blue are CONTENT NOT TO BE DISPLAYED! • All the instructions WRITTEN in black are CONTENT TO BE DISPLAYED! • This is not applicable for images as there can be overlapping of these colours there. This should be followed for all the instructions, labels,etc… Kindly keep a note of this while displaying text in the animation. 6
INSTRUCTIONS SLIDE Components 1 Index 2 0 1 2 3 4 5 6 7 8 9 3 Array or list 4 Note: 1:blue color represent the array All digit written in white letter in the array are “element” or “value at index n “(n refers to index number ex. value at index 4 = 5). . 5 7
Master Layout Quick Sort Status:- All steps will display here Put the Start, Pause, Stop, Step, reset ,Think button to control animation. Put a slidebar to control the speed of animation. Put a “let me try” button. 0 1 2 3 4 5 6 7 8 9 When “Think” is pressed, the applet will run with a time delay so that user can think about the next step. When “Step” button is pressed, the applet will start, but will stop after every step until the step button is pressed. When “let me try ” button is pressed then array will display(slide 34,35) and user will select pivot by click and to swap value user click on both value which he/she want to swap. The status bar will be removed in “let me try” mode. 8 Note : Animators are free to change the color and graphics to make animation more effective. Project OSCAR IDD Template 4.7
Step 2: Selecting and placing pivot 1 0 1 2 3 4 5 6 7 8 9 2 3 Array elements to be sorted. Pivot element. Selected Index value Swapped Index value 4 5
Step 2: Selecting and placing pivot 1 i j 0 1 2 3 4 5 6 7 8 9 2 3 Array elements to be sorted. Pivot element. Selected Index value Swapped Index value 4 5
Step 3: Selecting and placing pivot 1 i j 0 1 2 3 4 5 6 7 8 9 2 3 Array elements to be sorted. Pivot element. Selected Index value Swapped Index value 4 5
Step 4: Selecting and placing pivot 1 i j 0 1 2 3 4 5 6 7 8 9 2 3 Array elements to be sorted. Pivot element. Selected Index value Swapped Index value 4 5
Step 5: Selecting and placing pivot 1 i j 0 1 2 3 4 5 6 7 8 9 2 3 Array elements to be sorted. Pivot element. Selected Index value Swapped Index value 4 5
Note:- this and Next slide shows the comparison and swap. i j 0 1 2 3 4 5 6 7 8 9 i j 2< 6 increment i by 1 0 1 2 3 4 5 6 7 8 9 j 5< 6 increment i by 1 i 0 1 2 3 4 5 6 7 8 9 14
j 7 > 6 stop and move to right pointer . i 0 1 2 3 4 5 6 7 8 9 i j 6 = 6 (j = pivot) swap I & j; 0 1 2 3 4 5 6 7 8 9 6 reaches to it’s final position 0 1 2 3 4 5 6 7 8 9 15
Step 6: Selecting and placing pivot 1 i j 0 1 2 3 4 5 6 7 8 9 2 3 Array elements to be sorted. Pivot element. Selected Index value Swapped Index value 4 5
Step 7: Selecting and placing pivot 1 i j 0 1 2 3 4 5 6 7 8 9 2 3 Array elements to be sorted. Pivot element. Selected Index value Swapped Index value 4 5
Step 7: Selecting and placing pivot 1 0 1 2 3 4 5 6 7 8 9 2 3 Array elements to be sorted. Pivot element. Selected Index value Swapped Index value 4 5
Step 7: Selecting and placing pivot 1 i j 0 1 2 3 4 5 6 7 8 9 2 3 Array elements to be sorted. Pivot element. Selected Index value Swapped Index value 4 5
Step 7: Selecting and placing pivot 1 i j 0 1 2 3 4 5 6 7 8 9 2 3 Array elements to be sorted. Pivot element. Selected Index value Swapped Index value 4 5
Step 7: Selecting and placing pivot 1 i j 0 1 2 3 4 5 6 7 8 9 2 3 Array elements to be sorted. Pivot element. Selected Index value Swapped Index value 4 5
Step 7: Selecting and placing pivot 1 i j 0 1 2 3 4 5 6 7 8 9 2 3 Array elements to be sorted. Pivot element. Selected Index value Swapped Index value 4 5
Step 7: Selecting and placing pivot 1 0 1 2 3 4 5 6 7 8 9 2 3 Array elements to be sorted. Pivot element. Selected Index value Swapped Index value 4 5
Step 7: Selecting and placing pivot 1 i j 0 1 2 3 4 5 6 7 8 9 2 3 Array elements to be sorted. Pivot element. Selected Index value Swapped Index value 4 5
Step 7: Selecting and placing pivot 1 i j 0 1 2 3 4 5 6 7 8 9 2 3 Array elements to be sorted. Pivot element. Selected Index value Swapped Index value 4 5
Step 7: Selecting and placing pivot 1 i j 0 1 2 3 4 5 6 7 8 9 2 3 Array elements to be sorted. Pivot element. Selected Index value Swapped Index value 4 5
Step 7: Selecting and placing pivot 1 i j 0 1 2 3 4 5 6 7 8 9 2 3 Array elements to be sorted. Pivot element. Selected Index value Swapped Index value 4 5
Step 7: Selecting and placing pivot 1 0 1 2 3 4 5 6 7 8 9 2 3 Array elements to be sorted. Pivot element. Selected Index value Swapped Index value 4 5
Step 7: Selecting and placing pivot (right sub array) 1 0 1 2 3 4 5 6 7 8 9 2 3 Array elements to be sorted. Pivot element. Selected Index value Swapped Index value 4 5
Step 7: Selecting and placing pivot (right sub array) 1 i j 0 1 2 3 4 5 6 7 8 9 2 3 Array elements to be sorted. Pivot element. Selected Index value Swapped Index value 4 5
Step 7: Selecting and placing pivot (right sub array) 1 i j 0 1 2 3 4 5 6 7 8 9 2 3 Array elements to be sorted. Pivot element. Selected Index value Swapped Index value 4 5
Step 7: Selecting and placing pivot (right sub array) 1 0 1 2 3 4 5 6 7 8 9 2 3 Array elements to be sorted. Pivot element. Selected Index value Swapped Index value 4 5
Step 7: Selecting and placing pivot (right sub array) 1 i j 0 1 2 3 4 5 6 7 8 9 2 3 Array elements to be sorted. Pivot element. Selected Index value Swapped Index value 4 5
Step 7: Selecting and placing pivot (right sub array) 1 0 1 2 3 4 5 6 7 8 9 2 3 Array elements to be sorted. Pivot element. Selected Index value Swapped Index value 4 5
1 Interactivity and Boundary limits • In this section, you will add the ‘Interactivity’ options to the animation. • Use the template in the next slide to give the details. • Insert the image of the step/s (explained earlier in the Section 3) in the box, and provide the details in the table below. • The details of Interactivitycould be: • Types: Drop down, Slider bar, Data inputs etc. • Options: Select one, Multiple selections etc • Boundary Limits: Values of the parameters, which won’t show results after a particular point • Results: Explain the effect of the interaction in this column • Add more slides if necessary 2 3 4 5 35
Electrical Engineering Slide 4 Slide 4 Slide 37 - 40 Slide 41 Introduction Definitions Analogy Test your understanding (questionnaire) Lets Sum up (summary) Want to know more… (Further Reading) Interactivity: Array Size : Values : : Try it yourself • Place an input box to enter the size of array not more than 15. • Place an another input box to enter values to be sorted of size specified in above input box. • Place an enter button to enter the value. . • After entering the selected values, master layout1 procedure is to be done In the input box the user will input all the numerical values that he/she wants to sort. Display array of size entered above as input , with it’s index and values . Allow values to be entered one by one. 36 Credits
Let me try (allow user to select and sort) 1 0 1 2 3 4 5 6 2 3 4 5
Let me try (allow user to select and sort) 1 0 1 2 3 4 5 6 2 3 4 5
INSTRUCTIONS SLIDE Self- Assessment Questionnaire for Learners • Please provide a set of questions that a user can answer based on the LO. They can be of the following types: • These questions should be 5 in number and can be of objective type (like MCQ, Match the columns, Yes or No, Sequencing, Odd One Out). • The questions can also be open-ended. The user would be asked to think about the question. The author is requested to provide hints if possible, but a full answer is not necessary. • One can include questions, for which the user will need to interact with the LO (with certain parameters) in order to answer it. 39
INSTRUCTIONS SLIDE Questionnaire for users to test their understanding • Please make sure that the questions can be answered by interacting with the LO. It is better to avoid questions based purely on recall. 40
Question 1: Which one is the fastest algorithm. Answers: • Selection sort 2. Insertion sort 3. Quick sort 4. all Correct answer: Quick sort Feedback/Justification to be displayed: • If user clicks correct answer then display ____ Correct ____ • If user clicks incorrect answer then display ____Incorrect 3 is correct answer, go to the animation again_______. Project OSCAR IDD Template 4.7 41
Question 2: In selecting pivot for quick-sort which one is the best choice for optimal partition. Answers: • The first element of the array. 2. The last element of the array. • The middle element of array. • The median of array. Correct answer: The median of array. Feedback/Justification to be displayed: • If user clicks correct answer then display ____ Correct ____ • If user clicks incorrect answer then display ____Incorrect. 4 is correct answer because median guarantees even partition of array_______. Project OSCAR IDD Template 4.7 42
Question 3: What will be the impact on running time if every time largest element or smallest element is selected as a pivot. Answers: • Worst case running time . 2. Best case running time. • Average case running time. • no effect. Correct answer: worst case running time. Feedback/Justification to be displayed: • If user clicks correct answer then display ____ Correct ____ • If user clicks incorrect answer then display ____Incorrect. 1 is correct answer because largest or smallest element always give the quadratic run time_______. Project OSCAR IDD Template 4.7 43
Question 4:-quick sort is fast for? Answers: • For large size list. • For small size list . • works for both large and small size list. • none Correct answer: works for both large and small size list. Feedback/Justification to be displayed: • If user clicks correct answer then display ____ Correct ____ • If user clicks incorrect answer then display ____Incorrect 3 is correct answer _______. Project OSCAR IDD Template 4.7 44
References Website links for further reading: http://en.wikipedia.org/wiki/Quicksort http://algs4.cs.princeton.edu/23quicksort/ Books: • “Introduction to Algorithm”Thomas H. Coremen Project OSCAR IDD Template 4.7 45