The document describes various sorting algorithms, including insertion sort, selection sort, and shell sort. It provides pseudocode examples and explanations of how each algorithm works to sort a list of numbers in ascending order. Insertion sort works by taking each element and inserting it into the sorted position within the growing sorted sublist. Shell sort improves on insertion sort by sorting elements spaced further apart before sorting adjacent elements.
This presentation was made for CSE student to understand easily quick sort algorithm to implement quick algorithm. So if u want to learn quick sort than watch it.
This presentation was made for CSE student to understand easily quick sort algorithm to implement quick algorithm. So if u want to learn quick sort than watch it.
The process of sorting has been one of those problems in computer science that have been around almost from the beginning of time. For example, the tabulating machine (IBM, 1890’s Census) was the first early data processing
unit able to sort data cards for people in the USA. After all the first census took around 7 years to be finished, making all the stored data obsolete. Therefore, the need for sorting. It is more, studying the different techniques of sorting
allows for a more precise introduction of the algorithm concept. Some corrections were done to a bound for the max-heapfy... My deepest excuses for the mistakes!!!
Merge sort: illustrated step-by-step walk throughYoshi Watanabe
A step-by-step illustration of Merge sort to help you walk through a series of operations. Illustration is accompanied by actual code with bold line indicating the current operation.
Introduction to sorting algorithms with a broad overview (in Ruby pseudocode) of each sort's main features, beginning with Insertion Sort. *gifs do not show properly
Evaluating Teaching: SECTIONS.
Check out:
Bates, A. W., & Poole, G. (2003). Effective Teaching with Technology in Higher Education: Foundations for Success. Jossey-Bass, An Imprint of Wiley. 10475 Crosspoint Blvd, Indianapolis, IN 46256.
Evaluating Teaching: Anstey and Watson Rubric
Check out:
Lauren M. Anstey & Gavan P.L. Watson. (2018), Rubric for eLearning Tool Evaluation. Centre for Teaching and Learning, Western University,
http://creativecommons.org/licenses/by-n c-sa/4.0/
Designing Teaching: ASSURE
Check out:
Heinich, R., Molenda, M., & Russell, J. D., (1993). Instructional Media and The New
Technologies of Instruction. New York: Macmillan
Designing Teaching: Laurilliard's Learning TypesDamian T. Gordon
Designing Teaching: Laurilliard's Learning Types
Check out:
Laurillard, D., 2013. Teaching as a design science: Building pedagogical patterns for learning and technology. Routledge.
Designing Teaching: Elaboration Theory
Check out:
Reigeluth, C. & Stein, F. (1983). The elaboration theory of instruction. In C. Reigeluth (ed.), Instructional Design Theories and Models. Hillsdale, NJ: Erlbaum Associates.
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...Levi Shapiro
Letter from the Congress of the United States regarding Anti-Semitism sent June 3rd to MIT President Sally Kornbluth, MIT Corp Chair, Mark Gorenberg
Dear Dr. Kornbluth and Mr. Gorenberg,
The US House of Representatives is deeply concerned by ongoing and pervasive acts of antisemitic
harassment and intimidation at the Massachusetts Institute of Technology (MIT). Failing to act decisively to ensure a safe learning environment for all students would be a grave dereliction of your responsibilities as President of MIT and Chair of the MIT Corporation.
This Congress will not stand idly by and allow an environment hostile to Jewish students to persist. The House believes that your institution is in violation of Title VI of the Civil Rights Act, and the inability or
unwillingness to rectify this violation through action requires accountability.
Postsecondary education is a unique opportunity for students to learn and have their ideas and beliefs challenged. However, universities receiving hundreds of millions of federal funds annually have denied
students that opportunity and have been hijacked to become venues for the promotion of terrorism, antisemitic harassment and intimidation, unlawful encampments, and in some cases, assaults and riots.
The House of Representatives will not countenance the use of federal funds to indoctrinate students into hateful, antisemitic, anti-American supporters of terrorism. Investigations into campus antisemitism by the Committee on Education and the Workforce and the Committee on Ways and Means have been expanded into a Congress-wide probe across all relevant jurisdictions to address this national crisis. The undersigned Committees will conduct oversight into the use of federal funds at MIT and its learning environment under authorities granted to each Committee.
• The Committee on Education and the Workforce has been investigating your institution since December 7, 2023. The Committee has broad jurisdiction over postsecondary education, including its compliance with Title VI of the Civil Rights Act, campus safety concerns over disruptions to the learning environment, and the awarding of federal student aid under the Higher Education Act.
• The Committee on Oversight and Accountability is investigating the sources of funding and other support flowing to groups espousing pro-Hamas propaganda and engaged in antisemitic harassment and intimidation of students. The Committee on Oversight and Accountability is the principal oversight committee of the US House of Representatives and has broad authority to investigate “any matter” at “any time” under House Rule X.
• The Committee on Ways and Means has been investigating several universities since November 15, 2023, when the Committee held a hearing entitled From Ivory Towers to Dark Corners: Investigating the Nexus Between Antisemitism, Tax-Exempt Universities, and Terror Financing. The Committee followed the hearing with letters to those institutions on January 10, 202
A workshop hosted by the South African Journal of Science aimed at postgraduate students and early career researchers with little or no experience in writing and publishing journal articles.
The simplified electron and muon model, Oscillating Spacetime: The Foundation...RitikBhardwaj56
Discover the Simplified Electron and Muon Model: A New Wave-Based Approach to Understanding Particles delves into a groundbreaking theory that presents electrons and muons as rotating soliton waves within oscillating spacetime. Geared towards students, researchers, and science buffs, this book breaks down complex ideas into simple explanations. It covers topics such as electron waves, temporal dynamics, and the implications of this model on particle physics. With clear illustrations and easy-to-follow explanations, readers will gain a new outlook on the universe's fundamental nature.
it describes the bony anatomy including the femoral head , acetabulum, labrum . also discusses the capsule , ligaments . muscle that act on the hip joint and the range of motion are outlined. factors affecting hip joint stability and weight transmission through the joint are summarized.
Normal Labour/ Stages of Labour/ Mechanism of LabourWasim Ak
Normal labor is also termed spontaneous labor, defined as the natural physiological process through which the fetus, placenta, and membranes are expelled from the uterus through the birth canal at term (37 to 42 weeks
This presentation was provided by Steph Pollock of The American Psychological Association’s Journals Program, and Damita Snow, of The American Society of Civil Engineers (ASCE), for the initial session of NISO's 2024 Training Series "DEIA in the Scholarly Landscape." Session One: 'Setting Expectations: a DEIA Primer,' was held June 6, 2024.
Delivering Micro-Credentials in Technical and Vocational Education and TrainingAG2 Design
Explore how micro-credentials are transforming Technical and Vocational Education and Training (TVET) with this comprehensive slide deck. Discover what micro-credentials are, their importance in TVET, the advantages they offer, and the insights from industry experts. Additionally, learn about the top software applications available for creating and managing micro-credentials. This presentation also includes valuable resources and a discussion on the future of these specialised certifications.
For more detailed information on delivering micro-credentials in TVET, visit this https://tvettrainer.com/delivering-micro-credentials-in-tvet/
বাংলাদেশের অর্থনৈতিক সমীক্ষা ২০২৪ [Bangladesh Economic Review 2024 Bangla.pdf] কম্পিউটার , ট্যাব ও স্মার্ট ফোন ভার্সন সহ সম্পূর্ণ বাংলা ই-বুক বা pdf বই " সুচিপত্র ...বুকমার্ক মেনু 🔖 ও হাইপার লিংক মেনু 📝👆 যুক্ত ..
আমাদের সবার জন্য খুব খুব গুরুত্বপূর্ণ একটি বই ..বিসিএস, ব্যাংক, ইউনিভার্সিটি ভর্তি ও যে কোন প্রতিযোগিতা মূলক পরীক্ষার জন্য এর খুব ইম্পরট্যান্ট একটি বিষয় ...তাছাড়া বাংলাদেশের সাম্প্রতিক যে কোন ডাটা বা তথ্য এই বইতে পাবেন ...
তাই একজন নাগরিক হিসাবে এই তথ্য গুলো আপনার জানা প্রয়োজন ...।
বিসিএস ও ব্যাংক এর লিখিত পরীক্ষা ...+এছাড়া মাধ্যমিক ও উচ্চমাধ্যমিকের স্টুডেন্টদের জন্য অনেক কাজে আসবে ...
Executive Directors Chat Leveraging AI for Diversity, Equity, and InclusionTechSoup
Let’s explore the intersection of technology and equity in the final session of our DEI series. Discover how AI tools, like ChatGPT, can be used to support and enhance your nonprofit's DEI initiatives. Participants will gain insights into practical AI applications and get tips for leveraging technology to advance their DEI goals.
How to Build a Module in Odoo 17 Using the Scaffold MethodCeline George
Odoo provides an option for creating a module by using a single line command. By using this command the user can make a whole structure of a module. It is very easy for a beginner to make a module. There is no need to make each file manually. This slide will show how to create a module using the scaffold method.
Safalta Digital marketing institute in Noida, provide complete applications that encompass a huge range of virtual advertising and marketing additives, which includes search engine optimization, virtual communication advertising, pay-per-click on marketing, content material advertising, internet analytics, and greater. These university courses are designed for students who possess a comprehensive understanding of virtual marketing strategies and attributes.Safalta Digital Marketing Institute in Noida is a first choice for young individuals or students who are looking to start their careers in the field of digital advertising. The institute gives specialized courses designed and certification.
for beginners, providing thorough training in areas such as SEO, digital communication marketing, and PPC training in Noida. After finishing the program, students receive the certifications recognised by top different universitie, setting a strong foundation for a successful career in digital marketing.
4. PROGRAM BubbleSort:
Integer Age[8] <- {44,23,42,33,16,54,34,18};
FOR Outer-Index IN 0 TO N-1
DO FOR Index IN 0 TO N-2
DO IF (Age[Index+1] < Age[Index])
THEN Temp_Value <- Age[Index+1];
Age[Index+1] <- Age[Index];
Age[Index] <- Temp_Value;
ENDIF;
ENDFOR;
ENDFOR;
END.
Sorting: Bubble Sort
5. PROGRAM SelectionSort:
Integer Age[8] <- {44,23,42,33,16,54,34,18};
FOR Outer-Index IN 0 TO N-1
MinValueLocation <- Outer-Index;
FOR Index IN Outer-Index+1 TO N-1
DO IF (Age[Index] < Age[MinValueLocation])
THEN MinValueLocation <- Index;
ENDIF;
ENDFOR;
IF (MinValueLocation != Outer-Index)
THEN Swap(Age[Outer-Index], Age[MinValueLocation]);
ENDIF;
ENDFOR;
END.
Sorting: Selection Sort
7. Insertion Sort
• Insertion Sort works by taking the first two elements of the list,
sorting them, then taking the third one, and sorting that into
the first two, then taking the fourth element and sorting that
into the first three, etc.
38. Insertion Sort
• And then we move CURRENT into the correct position.
16 23 33 42 42 44 54 18
0 1 2 3 4 5 6 7
Current: 34
39. Insertion Sort
• And then we move CURRENT into the correct position.
16 23 33 42 42 44 54 18
0 1 2 3 4 5 6 7
Current: 34
40. Insertion Sort
• And then we move CURRENT into the correct position.
16 23 33 34 42 44 54 18
0 1 2 3 4 5 6 7
41. Insertion Sort
• The element being added in each time is just to the left of the
sorted list.
• So, if the next element is called CURRENT, the largest element
in the sorted list is CURRENT – 1.
• So we’ll know if the next element is largest if it is bigger than
CURRENT – 1.
Sorted sub-list
Next
element
CURRENT
42. Insertion Sort
• Structured English:
FOR each element from the second TO the end of the list
DO Remember the current position and value
WHILE the previous element is bigger than current
DO Move the previous element into current’s position
END WHILE
We’ve reached the position in the list that current should be
Put it in
END FOR
NOTE: The Previous
Element is the end of
the sorted sub-list
43. PROGRAM InsertionSort:
Integer Array[8] <- {44,23,42,33,16,54,34,18};
FOR Index IN 1 TO N
DO current = Array[index];
pos = index;
WHILE (pos > 0 and Array[pos – 1] > current)
DO Array[pos] <- Array[pos - 1];
pos = pos - 1;
ENDWHILE;
Array[pos] = current;
ENDFOR;
END.
Insertion Sort
NOTE: If you have
reached the start of
the list, STOP!
46. Shell Sort
• ShellSort is an extension of InsertionSort that was developed
by Donald Shell.
• Shell observed that the process of doing the Insertion Sort
move, particularly if that have to be moved from one side of
the array to other, is computationally expensive.
47. Shell Sort
• Instead of sorting the whole list, ShellSort first picks ever Nth
element, sorts those elements (0, N, 2N, 3N,…), then sorts (1,
N+1, 2N+1, 3N+1,…), then (2, N+2, 2N+2, 3N+2,…), and so on.
• Once that’s done, let’s sort every Mth element (where M is N
DIV 2), so we’ll sort (0, M, 2M, 3M,…), then sorts (1, M+1,
2M+1, 3M+1,…), then (2, M+2, 2M+2, 3M+2,…), and so on.
• And keep doing this until we get to 1.
48. Donald L. Shell
• Born: March 1, 1924
• Died: November 2, 2015
• Shell, D.L. (1959) "A High-
Speed Sorting Procedure“,
Communications of the ACM,
2(7), pp. 30–32.
49. Shell Sort
• So, for example. Age = [44, 23, 42, 33, 18, 54, 34, 16].
50. Shell Sort
• So, for example. Age = [44, 23, 42, 33, 18, 54, 34, 16].
• Let’s pick every 4th element:
51. Shell Sort
• So, for example. Age = [44, 23, 42, 33, 18, 54, 34, 16].
• Let’s pick every 4th element:
52. Shell Sort
• So, for example. Age = [44, 23, 42, 33, 18, 54, 34, 16].
• Let’s pick every 4th element:
– First group: 44, 18
53. Shell Sort
• So, for example. Age = [44, 23, 42, 33, 18, 54, 34, 16].
• Let’s pick every 4th element:
– First group: 44, 18
54. Shell Sort
• So, for example. Age = [44, 23, 42, 33, 18, 54, 34, 16].
• Let’s pick every 4th element:
– First group: 44, 18
– Second group: 23, 54
55. Shell Sort
• So, for example. Age = [44, 23, 42, 33, 18, 54, 34, 16].
• Let’s pick every 4th element:
– First group: 44, 18
– Second group: 23, 54
56. Shell Sort
• So, for example. Age = [44, 23, 42, 33, 18, 54, 34, 16].
• Let’s pick every 4th element:
– First group: 44, 18
– Second group: 23, 54
– Third group: 42, 34
57. Shell Sort
• So, for example. Age = [44, 23, 42, 33, 18, 54, 34, 16].
• Let’s pick every 4th element:
– First group: 44, 18
– Second group: 23, 54
– Third group: 42, 34
58. Shell Sort
• So, for example. Age = [44, 23, 42, 33, 18, 54, 34, 16].
• Let’s pick every 4th element:
– First group: 44, 18
– Second group: 23, 54
– Third group: 42, 34
– Fourth group: 33, 16
59. Shell Sort
• So, for example. Age = [44, 23, 42, 33, 18, 54, 34, 16].
• Let’s pick every 4th element:
– First group: 44, 18
– Second group: 23, 54
– Third group: 42, 34
– Fourth group: 33, 16
Sort these using
Insertion Sort
60. Shell Sort
• So, for example. Age = [44, 23, 42, 33, 18, 54, 34, 16].
• Let’s pick every 4th element:
– First group: 44, 18 18, 44
– Second group: 23, 54 23, 54
– Third group: 42, 34 34, 42
– Fourth group: 33, 16 16, 33
Sort these using
Insertion Sort
61. Shell Sort
• So, for example. Age = [44, 23, 42, 33, 18, 54, 34, 16].
• Let’s pick every 4th element:
– First group: 44, 18 18, 44
– Second group: 23, 54 23, 54
– Third group: 42, 34 34, 42
– Fourth group: 33, 16 16, 33
Sort these using
Insertion Sort
62. Shell Sort
• So, for example. Age = [18, 23, 34, 16, 44, 54, 42, 33].
• Let’s pick every 4th element:
– First group: 44, 18 18, 44
– Second group: 23, 54 23, 54
– Third group: 42, 34 34, 42
– Fourth group: 33, 16 16, 33
Sort these using
Insertion Sort
63. Shell Sort
• So, for example. Age = [18, 23, 34, 16, 44, 54, 42, 33].
• Let’s pick every 4th element:
– First group: 44, 18 18, 44
– Second group: 23, 54 23, 54
– Third group: 42, 34 34, 42
– Fourth group: 33, 16 16, 33
Sort these using
Insertion Sort
The data is not sorted, but a lot of the big numbers have been moved to the end of
the list, and a lot of the smaller numbers have been moved to the start.
64. Shell Sort
• So, for example. Age = [18, 23, 34, 16, 44, 54, 42, 33].
• Now let’s do every 2nd element:
65. Shell Sort
• So, for example. Age = [18, 23, 34, 16, 44, 54, 42, 33].
• Now let’s do every 2nd element:
66. Shell Sort
• So, for example. Age = [18, 23, 34, 16, 44, 54, 42, 33].
• Now let’s do every 2nd element:
– First Group: 18, 34, 44, 42
67. Shell Sort
• So, for example. Age = [18, 23, 34, 16, 44, 54, 42, 33].
• Now let’s do every 2nd element:
– First Group: 18, 34, 44, 42
68. Shell Sort
• So, for example. Age = [18, 23, 34, 16, 44, 54, 42, 33].
• Now let’s do every 2nd element:
– First Group: 18, 34, 44, 42
– Second Group: 23, 16, 54, 33
69. Shell Sort
• So, for example. Age = [18, 23, 34, 16, 44, 54, 42, 33].
• Now let’s do every 2nd element:
– First Group: 18, 34, 44, 42
– Second Group: 23, 16, 54, 33
Sort these using
Insertion Sort
70. Shell Sort
• So, for example. Age = [18, 23, 34, 16, 44, 54, 42, 33].
• Now let’s do every 2nd element:
– First Group: 18, 34, 44, 42 18, 34, 42, 44
– Second Group: 23, 16, 54, 33 16, 23, 33, 54
Sort these using
Insertion Sort
71. Shell Sort
• So, for example. Age = [18, 23, 34, 16, 44, 54, 42, 33].
• Now let’s do every 2nd element:
– First Group: 18, 34, 44, 42 18, 34, 42, 44
– Second Group: 23, 16, 54, 33 16, 23, 33, 54
Sort these using
Insertion Sort
72. Shell Sort
• So, for example. Age = [18, 16, 34, 23, 42, 33, 44, 54].
• Now let’s do every 2nd element:
– First Group: 18, 34, 44, 42 18, 34, 42, 44
– Second Group: 23, 16, 54, 33 16, 23, 33, 54
Sort these using
Insertion Sort
73. Shell Sort
• So, for example. Age = [18, 16, 34, 23, 42, 33, 44, 54].
• Now let’s do every 2nd element:
– First Group: 18, 34, 44, 42 18, 34, 42, 44
– Second Group: 23, 16, 54, 33 16, 23, 33, 54
Sort these using
Insertion Sort
The data is almost completely sorted now.
74. Shell Sort
• So, for example. Age = [18, 16, 34, 23, 42, 33, 44, 54].
• Finally do one more Insertion Sort with all elements
75. Shell Sort
• So, for example. Age = [18, 16, 34, 23, 42, 33, 44, 54].
• Finally do one more Insertion Sort with all elements
• This will be very fast since the data is almost sorted
76. Shell Sort
• So, for example. Age = [18, 16, 34, 23, 42, 33, 44, 54].
• Finally do one more Insertion Sort with all elements
• This will be very fast since the data is almost sorted
• Age = [16, 18, 23, 33, 34, 42, 44, 54].
77. Shell Sort
• Let’s look at the PseudoCode in two parts:
– 1) The Insertion Sort code as before, but modified not to sort all of
the elements, but rather every Nth element
– 2) The Shell Sort that calls the Insertion Sort code for each Nth
elements, and then N/2, and N/4, and so on until 1.
78. MODULE GapInsertionSort(Array, StartPos, Gap):
FOR Index IN StartPos TO N INCREMENT BY Gap
DO current = Array[index];
pos = index;
WHILE (pos > Gap and Array[pos – Gap] > current)
DO Array[pos] <- Array[pos - Gap];
pos = pos - Gap;
ENDWHILE;
Array[pos] = current;
ENDFOR;
END.
Shell Sort
79. MODULE GapInsertionSort(Array, StartPos, Gap):
FOR Index IN StartPos TO N INCREMENT BY Gap
DO current = Array[index];
pos = index;
WHILE (pos > Gap and Array[pos – Gap] > current)
DO Array[pos] <- Array[pos - Gap];
pos = pos - Gap;
ENDWHILE;
Array[pos] = current;
ENDFOR;
END.
Shell Sort
80. MODULE ShellSort(Array):
GapSize <- Length(Array) DIV 2;
WHILE (GapSize > 0)
DO
FOR StartPos IN 0 TO GapSize
DO GapInsertionSort(Array, StartPos, GapSize);
ENDFOR;
GapSize <- GapSize DIV 2;
ENDWHILE;
END.
Shell Sort
We are reducing the
Gap in half each time
For each of the Nth
Element, each N+1th
Element, N+2th, etc.
The main loop will
keep going until the
Gap is 1.
84. John von Neumann
• Born: December 28, 1903
• Died: February 8, 1957
• Born in Budapest, Austria-Hungary
• A mathematician who made major
contributions to set theory,
functional analysis, quantum
mechanics, ergodic theory,
continuous geometry, economics
and game theory, computer
science, numerical analysis,
hydrodynamics and statistics.
85. Merge Sort
• Merge Sort used a “divide-and-conquer” strategy.
• It’s a two-step process:
– 1. Keep splitting the array in half until you end up with sub-arrays of
one item (which are sorted by definition).
– 2. Successively merge each sub-array together, and sort with each
merge.
108. PROGRAM MergeSort(Array):
IF (length(Array) > 1)
THEN MidPoint = len(Age)//2
LeftHalf = Age[:MidPoint]
RightHalf = Age[MidPoint:]
Merge Sort
Keep recursively
splitting the array
until you get down
sub-arrays of one
element.
Continued
109. MergeSort(LeftHalf)
MergeSort(RightHalf)
LCounter = 0
RCounter = 0
MainCounter = 0
Merge Sort
Recursively call
MergeSort for each half
of the array. After the
splitting gets down to
one element the
recursive calls will pop
off the stack to merge
the sub-arrays together.
Continued
Continued
110. WHILE (LCounter < len(LeftHalf) AND
RCounter < len(RightHalf))
DO IF LeftHalf[LCounter] < RightHalf[RCounter]
THEN Age[MainCounter] = LeftHalf[LCounter];
LCounter = LCounter + 1;
ELSE Age[MainCounter] = RightHalf[RCounter];
RCounter = RCounter + 1;
ENDIF;
MainCounter = MainCounter + 1;
ENDWHILE;
Merge Sort
Continued
Continued
Keep comparing each
element of the left and
right sub-array, writing
the smaller element
into the main array
111. WHILE LCounter < len(LeftHalf)
DO Age[MainCounter] = LeftHalf[LCounter];
LCounter = LCounter + 1;
MainCounter = MainCounter + 1;
ENDWHILE;
WHILE Rcounter < len(RightHalf)
DO Age[MainCounter] = RightHalf[RCounter]
RCounter = RCounter + 1
MainCounter = MainCounter + 1
ENDWHILE;
ENDIF;
Merge Sort
Continued
After the comparisons
are done, write either
the rest of the left array
or the right array into
the main array that
114. QuickSort
• Quicksort was developed by Tony Hoare in 1959 and is still a
commonly used algorithm for sorting.
115. Charles Antony Richard Hoare
• Born: January 11, 1934
• Hoare's most significant work
includes: his sorting and selection
algorithm (Quicksort and
Quickselect), Hoare logic, the
formal language Communicating
Sequential Processes (CSP) used to
specify the interactions between
concurrent processes, structuring
computer operating systems using
the monitor concept.
116. QuickSort
• The key idea behind Quicksort is to pick a random value from
the array, and starting from either side of the array, swap
elements that are lower than the value in the right of the array
with elements of the left of the array that are larger than the
value, until we reach the point where the random value should
be, then we put the random value in its place.
• We recursively do this process with the sub-arrays on either
side of the random value ( called the “pivot”).
174. PROGRAM QuickSort(Array, First, Last):
IF (First < Last)
THEN Pivot = Partition(Array, First, Last);
QuickSort(Array, First, Pivot - 1):
QuickSort(Array, Pivot + 1, Last):
ENDIF;
END.
QuickSort
175. PROGRAM Partition(Array, First, Last):
PivotVal = Array[First];
Finished = False;
LeftPointer = First + 1;
RightPointer = Last;
QuickSort
We randomly select
the pivot, in this case
we select the first
element. Since the
array isn’t sorted yet,
the value of the first
element could have
any value
Continued
176. WHILE NOT(Finished)
DO
WHILE (LeftPointer <= RightPointer) AND
(Age[LeftPointer] <= PivotVal)
DO LeftPointer = LeftPointer + 1
ENDWHILE;
WHILE (Age[RightPointer] >= PivotVal) AND
(RightPointer >= LeftPointer)
DO RightPointer = RightPointer - 1
ENDWHILE;
QuickSort
Continued
Continued
Keep moving left
until we find a
value that is less
than the pivot, or
we reach the Right
Pointer.
Keep moving right
until we find a
value that is
greater than the
pivot, or we reach
the left Pointer.
177. IF (LeftPointer < RightPointer)
THEN Finished = False;
ELSE SWAP(Age[LeftPointer], Age[RightPointer]);
ENDIF;
SWAP(Age[First], Age[RightPointer]);
RETURN RightPointer;
END Partition.
QuickSort
Continued
We’ve a value
greater than the
pivot to the left,
and one less to the
right, swap them
Put the pivot in its
correct position