Sorting Damian Gordon.

Slides:



Advertisements
Similar presentations
Bubble Sort Example 9, 6, 2, 12, 11, 9, 3, 7 6, 9, 2, 12, 11, 9, 3, 7 Bubblesort compares the numbers in pairs from left to right exchanging.
Advertisements

Bubble Sort Algorithm 1.Initialize the size of the list to be sorted to be the actual size of the list. 2.Loop through the list until no element needs.
Decision Maths 1 Sorting Algorithms Bubble Sort A V Ali : 1.Start at the beginning of the data set. 2.Compare the first two elements,
Bubble Sort Algorithm It is so named because numbers (or letters) which are in the wrong place “bubble-up” to their correct positions (like fizzy lemonade)
Horstmann chapter 8 continued. Sorting arrays The telephone book is easy to use, because the entries are sorted Sorting is a common task, and many many.
Bubble Sort Notes David Beard CS181. Bubble Sort for Strings Double pass algorithm to sort a single dimensional array. Inner loop “bubbles” largest element.
Bubble Sort Merge Sort. Bubble Sort Sorting Sorting takes an unordered collection and makes it an ordered one
CS 106 Introduction to Computer Science I 02 / 28 / 2007 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 03 / 03 / 2008 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 03 / 08 / 2010 Instructor: Michael Eckmann.
Sorting and Searching Algorithms Week 11 DSA. Recap etc. Arrays are lists of data 1-D, 2-D etc. Lists associated with searching and sorting Other structures.
CS 106 Introduction to Computer Science I 10 / 15 / 2007 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 10 / 16 / 2006 Instructor: Michael Eckmann.
Lesson 2. Starter Look at the hand out you have been given. Can you sort the numbers into ascending order. What mental or physical methods did you use.
Searching Damian Gordon. Google PageRank Damian Gordon.
Bubble Sort Merge Sort. Bubble Sort Sorting Sorting takes an unordered collection and makes it an ordered one
Bubble Sort. Bubble Sort Example 9, 6, 2, 12, 11, 9, 3, 7 6, 9, 2, 12, 11, 9, 3, 7 6, 2, 9, 12, 11, 9, 3, 7 6, 2, 9, 11, 12, 9, 3, 7 6, 2, 9, 11, 9, 12,
Fundamentals of Algorithms MCS - 2 Lecture # 15. Bubble Sort.
Sorting: Optimising Bubblesort Damian Gordon. Sorting: Bubble Sort If we look at the bubble sort algorithm again:
Sorting Techniques Rizwan Rehman Centre for Computer Studies Dibrugarh University.
Python: Arrays Damian Gordon. Arrays In Python arrays are sometimes called “lists” or “tuple” but we’ll stick to the more commonly used term “array”.
The Bubble Sort by Mr. Dave Clausen La Cañada High School.
Searching & Sorting Programming 2. Searching Searching is the process of determining if a target item is present in a list of items, and locating it A.
Bubble Sort.
Python: Sorting - Bubblesort Damian Gordon. Sorting: Bubblesort The simplest algorithm for sort an array is called BUBBLE SORT. It works as follows for.
Sorting: Selection Sort Damian Gordon. Sorting: Selection Sort OK, so we’ve seen a way of sorting that easy for the computer, now let’s look at a ways.
Bubble Sort Example
SORTING ALGORITHMS King Saud University College of Applied studies and Community Service CSC 1101 By: Nada Alhirabi 1.
CS 106 Introduction to Computer Science I 03 / 02 / 2007 Instructor: Michael Eckmann.
Sorting Sorting takes an unordered array and makes it an ordered one
Bubble Sort Notes David Beard CIS220. Bubble Sort for Strings Double pass algorithm to sort a single dimensional array. Inner loop “bubbles” largest element.
Computer Science 1620 Sorting. cases exist where we would like our data to be in ascending (descending order) binary searching printing purposes selection.
Python: Iteration Damian Gordon. Python: Iteration We’ll consider four ways to do iteration: – The WHILE loop – The FOR loop – The DO loop – The LOOP.
Sort Algorithm.
The Bubble Sort Mr. Dave Clausen La Cañada High School
Chapter 9: Sorting and Searching Arrays
CS212: Data Structures and Algorithms
Introduction to Python
Lecture 5 of Computer Science II
Fundamentals of Java: AP Computer Science Essentials, 4th Edition
Pseudocode (Revision)
Recitation 13 Searching and Sorting.
Python: Advanced Sorting Algorithms
Simple Sorting Algorithms
Alg2_1c Extra Material for Alg2_1
Design and Analysis of Algorithms
Sorting Data are arranged according to their values.
Siti Nurbaya Ismail Senior Lecturer
Bubble Sort Bubble sort is one way to sort an array of numbers. Adjacent values are swapped until the array is completely sorted. This algorithm gets its.
Selection Sort Find the smallest value in the array. Put it in location zero. Find the second smallest value in the array and put it in location 1. Find.
Selection Sort Sorted Unsorted Swap
Analysis of Bubble Sort and Loop Invariant
Sorting Data are arranged according to their values.
Sorting … and Insertion Sort.
Discrete Mathematics CMP-101 Lecture 12 Sorting, Bubble Sort, Insertion Sort, Greedy Algorithms Abdul Hameed
Lecture 16 Bubble Sort Merge Sort.
Simple Statistics on Arrays
Simple Statistics on Arrays
Bubble Sort Example 9, 6, 2, 12, 11, 9, 3, 7 6, 9, 2, 12, 11, 9, 3, 7 Bubblesort compares the numbers in pairs from left to right exchanging.
Sorting "There's nothing in your head the sorting hat can't see. So try me on and I will tell you where you ought to be." -The Sorting Hat, Harry Potter.
Sorting Example Bubble Sort
Simple Sorting Algorithms
Decision Maths Unit 7 Sorting Algorithms 3. Shell Sort.
Python: Sorting – Selection Sort
Insertion Sort.
Simple Sorting Algorithms
EE 194/BIO 196: Modeling biological systems
Sorting.
CHAPTER 9 SORTING & SEARCHING.
Module 8 – Searching & Sorting Algorithms
Presentation transcript:

Sorting Damian Gordon

Sorting Let’s remember our integer array from before:

Sorting 44 23 1 42 2 33 3 16 4 54 5 6 34 7 18 Age

Sorting 44 23 1 42 2 33 3 16 4 54 5 34 6 18 7 Age How do we sort the data, in other words, get it into this order:

Sorting 44 23 1 42 2 33 3 16 4 54 5 6 34 7 18 Age How do we sort the data, in other words, get it into this order: 16 18 1 23 2 33 3 34 4 42 5 6 44 7 54 Age

Sorting As humans, we can sort the array just by inspection (just be looking at it), but if the array was 100,000 elements long it would be more of a challenge for us.

Sorting: Bubble Sort The simplest algorithm for sort an array is called BUBBLE SORT.

Sorting: Bubble Sort The simplest algorithm for sort an array is called BUBBLE SORT. It works as follows:

Sorting: Bubble Sort The simplest algorithm for sort an array is called BUBBLE SORT. It works as follows for an array of size N: Look at the first and second element Are they in order? If so, do nothing If not, swap them around Look at the second and third element Do the same Keep doing this until you get to the end of the array Go back to the start again keep doing this whole process for N times.

Sorting: Bubble Sort Lets look at the swapping bit if I wanted to swap two values, the following won’t work: Age[0] <- Age[1]; Age[1] <- Age[0]; Why not?

Sorting: Bubble Sort Lets assume Age[0]=44, and Age[1]=23, if we do the following: Age[0] <- Age[1]; Age[1] <- Age[0]; What happens is:

Sorting: Bubble Sort Lets assume Age[0]=44, and Age[1]=23, if we do the following: Age[0] <- Age[1]; Age[1] <- Age[0]; What happens is: 23

Sorting: Bubble Sort Lets assume Age[0]=44, and Age[1]=23, if we do the following: Age[0] <- Age[1]; Age[1] <- Age[0]; What happens is: 23 23

Sorting: Bubble Sort Lets assume Age[0]=44, and Age[1]=23, if we do the following: Age[0] <- Age[1]; Age[1] <- Age[0]; What happens is: 23 23 23

Sorting: Bubble Sort Lets assume Age[0]=44, and Age[1]=23, if we do the following: Age[0] <- Age[1]; Age[1] <- Age[0]; What happens is: 23 23 23 23

NOT a Successful swap Sorting: Bubble Sort Lets assume Age[0]=44, and Age[1]=23, if we do the following: Age[0] <- Age[1]; Age[1] <- Age[0]; What happens is: NOT a Successful swap 23 23 23 23

NOT a Successful swap Age[0]=23 Age[1]=23 Sorting: Bubble Sort Lets assume Age[0]=44, and Age[1]=23, if we do the following: Age[0] <- Age[1]; Age[1] <- Age[0]; What happens is: NOT a Successful swap Age[0]=23 Age[1]=23 23 23 23 23

Sorting: Bubble Sort We need an extra variable to make this work:

Sorting: Bubble Sort We need an extra variable to make this work: Lets call it Temp_Value.

Sorting: Bubble Sort We need an extra variable to make this work: Lets call it Temp_Value. Temp_Value <- Age[1];

Sorting: Bubble Sort We need an extra variable to make this work: Lets call it Temp_Value. Temp_Value <- Age[1]; Age[1] <- Age[0];

Sorting: Bubble Sort We need an extra variable to make this work: Lets call it Temp_Value. Temp_Value <- Age[1]; Age[1] <- Age[0]; Age[0] <- Temp_Value;

Sorting: Bubble Sort We need an extra variable to make this work: Lets call it Temp_Value. Temp_Value <- Age[1]; Age[1] <- Age[0]; Age[0] <- Temp_Value; 23

Sorting: Bubble Sort We need an extra variable to make this work: Lets call it Temp_Value. Temp_Value <- Age[1]; Age[1] <- Age[0]; Age[0] <- Temp_Value; 23 23

Sorting: Bubble Sort We need an extra variable to make this work: Lets call it Temp_Value. Temp_Value <- Age[1]; Age[1] <- Age[0]; Age[0] <- Temp_Value; 23 23 44

Sorting: Bubble Sort We need an extra variable to make this work: Lets call it Temp_Value. Temp_Value <- Age[1]; Age[1] <- Age[0]; Age[0] <- Temp_Value; 23 23 44 44

Sorting: Bubble Sort We need an extra variable to make this work: Lets call it Temp_Value. Temp_Value <- Age[1]; Age[1] <- Age[0]; Age[0] <- Temp_Value; 23 23 44 44 23

Sorting: Bubble Sort We need an extra variable to make this work: Lets call it Temp_Value. Temp_Value <- Age[1]; Age[1] <- Age[0]; Age[0] <- Temp_Value; 23 23 44 44 23 23

Successful swap Sorting: Bubble Sort We need an extra variable to make this work: Lets call it Temp_Value. Temp_Value <- Age[1]; Age[1] <- Age[0]; Age[0] <- Temp_Value; 23 23 Successful swap 44 44 23 23

Age[0]=23 Age[1]=44 Successful swap Sorting: Bubble Sort We need an extra variable to make this work: Lets call it Temp_Value. Temp_Value <- Age[1]; Age[1] <- Age[0]; Age[0] <- Temp_Value; 23 23 Age[0]=23 Age[1]=44 Successful swap 44 44 23 23

Sorting: Bubble Sort Let’s wrap an IF statement around this: IF (Age[1] < Age[0]) THEN Temp_Value <- Age[1]; Age[1] <- Age[0]; Age[0] <- Temp_Value; ENDIF;

Sorting: Bubble Sort And in general: IF (Age[N+1] < Age[N]) THEN Temp_Value <- Age[N+1]; Age[N+1] <- Age[N]; Age[N] <- Temp_Value; ENDIF;

Sorting: Bubble Sort Let’s replace “N” with “Index” IF (Age[Index+1] < Age[Index]) THEN Temp_Value <- Age[Index+1]; Age[Index+1] <- Age[Index]; Age[Index] <- Temp_Value; ENDIF;

Sorting: Bubble Sort To get from one end of the array to another: 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;

Sorting: Bubble Sort Does this mean we have the array sorted?

Sorting: Bubble Sort Does this mean we have the array sorted? No

Sorting: Bubble Sort 44 23 1 42 2 33 3 16 4 54 5 6 34 7 18 Age

Sorting: Bubble Sort 23 44 1 42 2 33 3 16 4 54 5 6 34 7 18 Age

Sorting: Bubble Sort 23 44 1 42 2 33 3 16 4 54 5 6 34 7 18 Age

Sorting: Bubble Sort 23 42 1 44 2 33 3 16 4 54 5 6 34 7 18 Age

Sorting: Bubble Sort 23 42 1 44 2 33 3 16 4 54 5 6 34 7 18 Age

Sorting: Bubble Sort 23 42 1 33 2 44 3 16 4 54 5 6 34 7 18 Age

Sorting: Bubble Sort 23 42 1 33 2 44 3 16 4 54 5 6 34 7 18 Age

Sorting: Bubble Sort 23 42 1 33 2 16 3 44 4 54 5 6 34 7 18 Age

Sorting: Bubble Sort 23 42 1 33 2 16 3 44 4 54 5 6 34 7 18 Age

Sorting: Bubble Sort 23 42 1 33 2 16 3 44 4 54 5 6 34 7 18 Age

Sorting: Bubble Sort 23 42 1 33 2 16 3 44 4 54 5 6 34 7 18 Age

Sorting: Bubble Sort 23 42 1 33 2 16 3 44 4 34 5 6 54 7 18 Age

Sorting: Bubble Sort 23 42 1 33 2 16 3 44 4 34 5 6 54 7 18 Age

Sorting: Bubble Sort 23 42 1 33 2 16 3 44 4 34 5 6 18 7 54 Age

Sorting: Bubble Sort 23 42 1 33 2 16 3 44 4 34 5 6 18 7 54 Age

Sorting: Bubble Sort Age 23 42 1 33 2 16 3 44 4 34 5 18 6 54 7 23 42 1 33 2 16 3 44 4 34 5 18 6 54 7 Age So what happened?

Sorting: Bubble Sort Age 23 42 1 33 2 16 3 44 4 34 5 18 6 54 7 23 42 1 33 2 16 3 44 4 34 5 18 6 54 7 Age So what happened? We have moved the largest value (54) into the correct position.

Sorting: Bubble Sort Let’s do it again:

Sorting: Bubble Sort 23 42 1 33 2 16 3 44 4 34 5 6 18 7 54 Age

Sorting: Bubble Sort 23 42 1 33 2 16 3 44 4 34 5 6 18 7 54 Age

Sorting: Bubble Sort 23 42 1 33 2 16 3 44 4 34 5 6 18 7 54 Age

Sorting: Bubble Sort 23 33 1 42 2 16 3 44 4 34 5 6 18 7 54 Age

Sorting: Bubble Sort 23 33 1 42 2 16 3 44 4 34 5 6 18 7 54 Age

Sorting: Bubble Sort 23 33 1 16 2 42 3 44 4 34 5 6 18 7 54 Age

Sorting: Bubble Sort 23 33 1 16 2 42 3 44 4 34 5 6 18 7 54 Age

Sorting: Bubble Sort 23 33 1 16 2 42 3 44 4 34 5 6 18 7 54 Age

Sorting: Bubble Sort 23 33 1 16 2 42 3 44 4 34 5 6 18 7 54 Age

Sorting: Bubble Sort 23 33 1 16 2 42 3 34 4 44 5 6 18 7 54 Age

Sorting: Bubble Sort 23 33 1 16 2 42 3 34 4 44 5 6 18 7 54 Age

Sorting: Bubble Sort 23 33 1 16 2 42 3 34 4 18 5 6 44 7 54 Age

Sorting: Bubble Sort 23 33 1 16 2 42 3 34 4 18 5 6 44 7 54 Age

Sorting: Bubble Sort Age 23 1 33 2 16 3 42 4 34 5 18 6 44 7 54 23 1 33 2 16 3 42 4 34 5 18 6 44 7 54 Age So what happened?

Sorting: Bubble Sort Age 23 1 33 2 16 3 42 4 34 5 18 6 44 7 54 23 1 33 2 16 3 42 4 34 5 18 6 44 7 54 Age So what happened? We have moved the second largest value (44) into the correct position.

Sorting: Bubble Sort Let’s do it again:

Sorting: Bubble Sort 23 33 1 16 2 42 3 34 4 18 5 6 44 7 54 Age

Sorting: Bubble Sort 23 33 1 16 2 42 3 34 4 18 5 6 44 7 54 Age

Sorting: Bubble Sort 23 33 1 16 2 42 3 34 4 18 5 6 44 7 54 Age

Sorting: Bubble Sort 23 16 1 33 2 42 3 34 4 18 5 6 44 7 54 Age

Sorting: Bubble Sort 23 16 1 33 2 42 3 34 4 18 5 6 44 7 54 Age

Sorting: Bubble Sort 23 16 1 33 2 42 3 34 4 18 5 6 44 7 54 Age

Sorting: Bubble Sort 23 16 1 33 2 42 3 34 4 18 5 6 44 7 54 Age

Sorting: Bubble Sort 23 16 1 33 2 42 3 34 4 18 5 6 44 7 54 Age

Sorting: Bubble Sort 23 16 1 33 2 34 3 42 4 18 5 6 44 7 54 Age

Sorting: Bubble Sort 23 16 1 33 2 34 3 42 4 18 5 6 44 7 54 Age

Sorting: Bubble Sort 23 16 1 33 2 34 3 18 4 42 5 6 44 7 54 Age

Sorting: Bubble Sort 23 16 1 33 2 34 3 18 4 42 5 6 44 7 54 Age

Sorting: Bubble Sort 23 16 1 33 2 34 3 18 4 42 5 6 44 7 54 Age

Sorting: Bubble Sort 23 16 1 33 2 34 3 18 4 42 5 6 44 7 54 Age

Sorting: Bubble Sort Age 23 16 1 33 2 34 3 18 4 42 5 44 6 54 7 23 16 1 33 2 34 3 18 4 42 5 44 6 54 7 Age So what happened? We have moved the third largest value (42) into the correct position.

Sorting: Bubble Sort Let’s do it again:

Sorting: Bubble Sort 23 16 1 33 2 34 3 18 4 42 5 6 44 7 54 Age

Sorting: Bubble Sort 16 23 1 33 2 34 3 18 4 42 5 6 44 7 54 Age

Sorting: Bubble Sort 16 23 1 33 2 34 3 18 4 42 5 6 44 7 54 Age

Sorting: Bubble Sort 16 23 1 33 2 34 3 18 4 42 5 6 44 7 54 Age

Sorting: Bubble Sort 16 23 1 33 2 34 3 18 4 42 5 6 44 7 54 Age

Sorting: Bubble Sort 16 23 1 33 2 34 3 18 4 42 5 6 44 7 54 Age

Sorting: Bubble Sort 16 23 1 33 2 34 3 18 4 42 5 6 44 7 54 Age

Sorting: Bubble Sort 16 23 1 33 2 18 3 34 4 42 5 6 44 7 54 Age

Sorting: Bubble Sort 16 23 1 33 2 18 3 34 4 42 5 6 44 7 54 Age

Sorting: Bubble Sort 16 23 1 33 2 18 3 34 4 42 5 6 44 7 54 Age

Sorting: Bubble Sort 16 23 1 33 2 18 3 34 4 42 5 6 44 7 54 Age

Sorting: Bubble Sort 16 23 1 33 2 18 3 34 4 42 5 6 44 7 54 Age

Sorting: Bubble Sort 16 23 1 33 2 18 3 34 4 42 5 6 44 7 54 Age

Sorting: Bubble Sort Age 16 23 1 33 2 18 3 34 4 42 5 44 6 54 7 16 23 1 33 2 18 3 34 4 42 5 44 6 54 7 Age So what happened?

Sorting: Bubble Sort Age 16 23 1 33 2 18 3 34 4 42 5 44 6 54 7 16 23 1 33 2 18 3 34 4 42 5 44 6 54 7 Age So what happened? We have moved the fourth largest value (34) into the correct position.

Sorting: Bubble Sort Let’s do it again:

Sorting: Bubble Sort 16 23 1 33 2 18 3 34 4 42 5 6 44 7 54 Age

Sorting: Bubble Sort 16 23 1 33 2 18 3 34 4 42 5 6 44 7 54 Age

Sorting: Bubble Sort 16 23 1 33 2 18 3 34 4 42 5 6 44 7 54 Age

Sorting: Bubble Sort 16 23 1 33 2 18 3 34 4 42 5 6 44 7 54 Age

Sorting: Bubble Sort 16 23 1 33 2 18 3 34 4 42 5 6 44 7 54 Age

Sorting: Bubble Sort 16 23 1 18 2 33 3 34 4 42 5 6 44 7 54 Age

Sorting: Bubble Sort 16 23 1 18 2 33 3 34 4 42 5 6 44 7 54 Age

Sorting: Bubble Sort 16 23 1 18 2 33 3 34 4 42 5 6 44 7 54 Age

Sorting: Bubble Sort 16 23 1 18 2 33 3 34 4 42 5 6 44 7 54 Age

Sorting: Bubble Sort 16 23 1 18 2 33 3 34 4 42 5 6 44 7 54 Age

Sorting: Bubble Sort 16 23 1 18 2 33 3 34 4 42 5 6 44 7 54 Age

Sorting: Bubble Sort 16 23 1 18 2 33 3 34 4 42 5 6 44 7 54 Age

Sorting: Bubble Sort 16 23 1 18 2 33 3 34 4 42 5 6 44 7 54 Age

Sorting: Bubble Sort Age 16 23 1 18 2 33 3 34 4 42 5 44 6 54 7 16 23 1 18 2 33 3 34 4 42 5 44 6 54 7 Age So what happened? We have moved the fifth largest value (33) into the correct position.

Sorting: Bubble Sort Let’s do it again:

Sorting: Bubble Sort 16 23 1 18 2 33 3 34 4 42 5 6 44 7 54 Age

Sorting: Bubble Sort 16 23 1 18 2 33 3 34 4 42 5 6 44 7 54 Age

Sorting: Bubble Sort 16 23 1 18 2 33 3 34 4 42 5 6 44 7 54 Age

Sorting: Bubble Sort 16 18 1 23 2 33 3 34 4 42 5 6 44 7 54 Age

Sorting: Bubble Sort 16 18 1 23 2 33 3 34 4 42 5 6 44 7 54 Age

Sorting: Bubble Sort 16 18 1 23 2 33 3 34 4 42 5 6 44 7 54 Age

Sorting: Bubble Sort 16 18 1 23 2 33 3 34 4 42 5 6 44 7 54 Age

Sorting: Bubble Sort 16 18 1 23 2 33 3 34 4 42 5 6 44 7 54 Age

Sorting: Bubble Sort 16 18 1 23 2 33 3 34 4 42 5 6 44 7 54 Age

Sorting: Bubble Sort 16 18 1 23 2 33 3 34 4 42 5 6 44 7 54 Age

Sorting: Bubble Sort 16 18 1 23 2 33 3 34 4 42 5 6 44 7 54 Age

Sorting: Bubble Sort 16 18 1 23 2 33 3 34 4 42 5 6 44 7 54 Age

Sorting: Bubble Sort 16 18 1 23 2 33 3 34 4 42 5 6 44 7 54 Age

Sorting: Bubble Sort Age 16 18 1 23 2 33 3 34 4 42 5 44 6 54 7 16 18 1 23 2 33 3 34 4 42 5 44 6 54 7 Age So what happened?

Sorting: Bubble Sort Age 16 18 1 23 2 33 3 34 4 42 5 44 6 54 7 16 18 1 23 2 33 3 34 4 42 5 44 6 54 7 Age So what happened? We have moved the sixth largest value (23) into the correct position.

Sorting: Bubble Sort Let’s do it again:

Sorting: Bubble Sort Let’s do it again: Let’s not bother!

Sorting: Bubble Sort Let’s do it again: Let’s not bother! It’s sorted!

Sorting: Bubble Sort 16 18 1 23 2 33 3 34 4 42 5 6 44 7 54 Age

Sorting: Bubble Sort So we need two loops:

Sorting: Bubble Sort So we need two loops: 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;

Sorting: Bubble Sort 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; END.

Sorting: Bubble Sort

etc.