Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard...
-
Upload
xzavier-wakeling -
Category
Documents
-
view
225 -
download
1
Transcript of Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard...
![Page 1: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/1.jpg)
Topic 7
Standard Algorithms
![Page 2: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/2.jpg)
Learning Objectives
Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level language Binary search
Describe and compare simple linear and binary search algorithms
Describe and compare sort algorithms for simple sort, bubble sort and selection sort in terms of number of comparisons and use of memory
Describe and exemplify user-defined module libraries
![Page 3: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/3.jpg)
Linear Search
![Page 4: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/4.jpg)
Linear Search
Simplest search method to implement Scanning takes place from left to right until the
search key is found
16 9 34 76 85 2 25 82 55 60
Search key is 76
![Page 5: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/5.jpg)
Linear Search Algorithm1. Set found to false2. Input search key3. Point to first element in list4. Do while (not end of list) and (not found)5. if array(value) = key then6. found=true7. output suitable message8. else9. look at next element in list10. end if11. loop12. If (not found) then13. key not in list14. End if
![Page 6: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/6.jpg)
Linear Search
Not a bad algorithm for short lists Easier to implement than other methods List does not need to be sorted Might be only method for large unordered
tables of data and files Inefficient since each array element has to be
compared with search key until a match is found
![Page 7: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/7.jpg)
Analysis
One comparison required to find target at start of list
Two comparisons for target in second position
etc Maximum comparisons is N for a list of N
items Therefore average number of comparisons is
N/2
![Page 8: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/8.jpg)
Exercise
Implement the Linear search algorithm given on page 145 in VB 2005
![Page 9: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/9.jpg)
Binary Search
![Page 10: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/10.jpg)
Binary Search
Faster method BUT list must be ordered Sometimes called a binary chop as it splits
the data list into two sublists and repeats the process until a search key is found
![Page 11: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/11.jpg)
Binary Search Example
16 29 34 48 57 59 72 82 90 91
![Page 12: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/12.jpg)
Binary Search Example
16 29 34 48 57 59 72 82 90 91
Search Key is 90
![Page 13: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/13.jpg)
Binary Search Example
16 29 34 48 57 59 72 82 90 91
Left List Right List
Mid Value
![Page 14: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/14.jpg)
Binary Search Example
16 29 34 48 57 59 72 82 90 91
Mid Value
Left List Right List
![Page 15: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/15.jpg)
Binary Search Example
16 29 34 48 57 59 72 82 90 91
Mid Value
Left ListRight List
Target Found
![Page 16: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/16.jpg)
Binary Search Algorithm - ascending1. Set found=false2. Set first_location to start of list3. Set last_location to end of list4. Input search target5. Repeat6. Set pointer to middle of list…. integer(first+last)/27. If array(middle)=target then8. found=true9. Output suitable message10. Else11. if array(middle)>target then12. last_location=middle-113. else14. first_location = middle+115. end if16. End if17. Until found = true or first>last
![Page 17: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/17.jpg)
![Page 18: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/18.jpg)
Exercise 1
With a partner, use the cards given to exemplify the binary search algorithm
Use cards for different search keys Make sure that you know how this algorithm
works
![Page 19: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/19.jpg)
Exercise 2
Implement the algorithm given on page 150 You cannot use code given on next pages as
version of VB is different!
![Page 20: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/20.jpg)
Summary of Searches
Linear Search Binary Search
Is simple to code and implement Is more complex to code
Quite efficient for short length data lists
Efficient for any length of data list
Very slow on large lists since each data element has to be compared
Fast on any length of data list since it only deals with half sub-lists. Hence the name is binary chop
Does not require data to be ordered Data has to be ordered
Average search length is N/2 where N is the number of data elements
Search length is log2N
Plays a part in other algorithms such as finding maximum, minimum and also in selection sort
Binary chop is used in fast searching routines
![Page 21: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/21.jpg)
Sorting
![Page 22: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/22.jpg)
Sorting
Important process in computing, especially in data processing Telephone directories Sports league tables Lottery numbers Etc.
![Page 23: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/23.jpg)
Sorting
Efficient sorting is important to optimizing the use of other algorithms (such as search and merge algorithms) that require sorted lists to work correctly; it is also often useful for canonicalizing data and for producing human-readable output.
![Page 24: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/24.jpg)
Sorting
Since the dawn of computing, the sorting problem has attracted a great deal of research, perhaps due to the complexity of solving it efficiently despite its simple, familiar statement.
![Page 25: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/25.jpg)
Sorting
External Sorts External storage devices used Large amounts of data
Internal Sorts Fairly small lists Uses internal memory (RAM)
![Page 26: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/26.jpg)
Sorting
Three algorithms described and compared
1. Simple sort
2. Bubble sort
3. Selection sort using two lists
![Page 27: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/27.jpg)
Simple Sort
In the first pass, each item in the list is compared with the first item in the list
If the first item in the list is bigger then the item being compared then they are swapped.
![Page 28: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/28.jpg)
Simple Sort
7 5 9 6 1 8 2 0 3 4
1st Comparison
Swap
![Page 29: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/29.jpg)
Simple Sort
5 7 9 6 1 8 2 0 3 4
![Page 30: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/30.jpg)
Simple Sort
5 7 9 6 1 8 2 0 3 4
2nd Comparison
![Page 31: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/31.jpg)
Simple Sort
5 7 9 6 1 8 2 0 3 4
3rd Comparison
![Page 32: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/32.jpg)
Simple Sort
5 7 9 6 1 8 2 0 3 4
4th Comparison
Swap
![Page 33: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/33.jpg)
Simple Sort
1 7 9 6 5 8 2 0 3 4
5th Comparison
![Page 34: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/34.jpg)
Simple Sort
1 7 9 6 5 8 2 0 3 4
6th Comparison
![Page 35: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/35.jpg)
Simple Sort
1 7 9 6 5 8 2 0 3 4
7th Comparison
Swap
![Page 36: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/36.jpg)
Simple Sort
0 7 9 6 5 8 2 1 3 4
![Page 37: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/37.jpg)
Simple Sort
0 7 9 6 5 8 2 1 3 4
8th Comparison
![Page 38: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/38.jpg)
Simple Sort
0 7 9 6 5 8 2 1 3 4
9th Comparison
![Page 39: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/39.jpg)
Simple Sort
0 7 9 6 5 8 2 1 3 4
1st Comparison
![Page 40: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/40.jpg)
Simple Sort
0 7 9 6 5 8 2 1 3 4
2nd Comparison
Swap
![Page 41: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/41.jpg)
Simple Sort
0 6 9 7 5 8 2 1 3 4
![Page 42: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/42.jpg)
Simple Sort
0 6 9 7 5 8 2 1 3 4
3rd Comparison
Swap
![Page 43: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/43.jpg)
Simple Sort
0 5 9 7 6 8 2 1 3 4
![Page 44: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/44.jpg)
Simple Sort
0 5 9 7 6 8 2 1 3 4
4th Comparison
![Page 45: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/45.jpg)
Simple Sort
0 5 9 7 6 8 2 1 3 4
5th Comparison
Swap
![Page 46: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/46.jpg)
Simple Sort
0 2 9 7 6 8 5 1 3 4
![Page 47: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/47.jpg)
Simple Sort
0 2 9 7 6 8 5 1 3 4
And so on…
![Page 48: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/48.jpg)
Simple Sortuntil…
0 1 2 3 4 5 6 7 8 9
![Page 49: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/49.jpg)
Simple Sort
1. Performs fewer exchanges on a randomly ordered list
2. Must make N-1 passes through list even when fully sorted or partially sorted
![Page 50: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/50.jpg)
Simple Sort Algorithm
1. for outer = 1 to n
2. for inner = outer + 1 to n
3. if List (outer) > List(inner) then
4. swap values
5. end if
6. next inner
7. next outer
![Page 51: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/51.jpg)
Simple Sort Task
Using the cards provided and With a partner Sort the cards into ascending order using the
simple sort methd
![Page 52: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/52.jpg)
Simple Sort Task
Using the cards provided and With a partner Sort the cards into ascending order using the
simple sort method
![Page 53: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/53.jpg)
Bubble sort
7 5 9 6 1 8 2 0 3 4
First Comparison
Swap
![Page 54: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/54.jpg)
Bubble sort
5 7 9 6 1 8 2 0 3 4
![Page 55: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/55.jpg)
Bubble sort
5 7 9 6 1 8 2 0 3 4
Second Comparison
![Page 56: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/56.jpg)
Bubble sort
5 7 9 6 1 8 2 0 3 4
Third Comparison
Swap
![Page 57: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/57.jpg)
Bubble sort
5 7 6 9 1 8 2 0 3 4
![Page 58: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/58.jpg)
Bubble sort
5 7 6 9 1 8 2 0 3 4
Fourth Comparison
Swap
![Page 59: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/59.jpg)
Bubble sort
5 7 6 1 9 8 2 0 3 4
![Page 60: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/60.jpg)
Bubble sort
5 7 6 1 9 8 2 0 3 4
Fifth Comparison
Swap
![Page 61: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/61.jpg)
Bubble sort
5 7 6 1 8 9 2 0 3 4
![Page 62: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/62.jpg)
Bubble sort
5 7 6 1 8 9 2 0 3 4
Sixth Comparison
Swap
![Page 63: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/63.jpg)
Bubble sort
5 7 6 1 8 2 9 0 3 4
![Page 64: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/64.jpg)
Bubble sort
5 7 6 1 8 2 9 0 3 4
Seventh Comparison
Swap
![Page 65: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/65.jpg)
Bubble sort
5 7 6 1 8 2 0 9 3 4
![Page 66: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/66.jpg)
Bubble sort
5 7 6 1 8 2 0 9 3 4
8th Comparison
Swap
![Page 67: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/67.jpg)
Bubble sort
5 7 6 1 8 2 0 3 9 4
![Page 68: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/68.jpg)
Bubble sort
5 7 6 1 8 2 0 3 9 4
9th Comparison
Swap
![Page 69: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/69.jpg)
Bubble sort
5 7 6 1 8 2 0 3 4 9
Notice… we are sorting list into an ascending list. The largest number is now at the end of the list…where it should be!
This completes the first pass through the list.
![Page 70: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/70.jpg)
Bubble sort
5 7 6 1 8 2 0 3 4 9
The process begins again.
1st Comparison Second Pass
![Page 71: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/71.jpg)
Bubble sort
5 7 6 1 8 2 0 3 4 9
2nd Comparison
Swap
Second Pass
![Page 72: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/72.jpg)
Bubble sort
5 6 7 1 8 2 0 3 4 9
Second Pass
![Page 73: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/73.jpg)
Bubble sort
5 6 7 1 8 2 0 3 4 9
3rd Comparison
Swap
Second Pass
![Page 74: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/74.jpg)
Bubble sort
5 6 1 7 8 2 0 3 4 9
Second Pass
![Page 75: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/75.jpg)
Bubble sort
5 6 1 7 8 2 0 3 4 9
4th Comparison Second Pass
![Page 76: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/76.jpg)
Bubble sort
5 6 1 7 8 2 0 3 4 9
5th Comparison
Swap
Second Pass
![Page 77: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/77.jpg)
Bubble Sort
1. for outer = 1 to n-1
2. for inner = 0 to N - 1
3. if list(inner) > list(inner + 1) then
4. swap values
5. end if
6. next inner
7. next outer
![Page 78: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/78.jpg)
Bubble Sort
1. Makes excessive exchanges (but less so in a partially ordered list).
2. Works best on a partially ordered list
3. Can detect when sorted as no swaps take place.
4. Most inefficient when list is randomly ordered
![Page 79: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/79.jpg)
Bubble Sort task
Using the cards provided and With a partner Sort the cards into ascending order using the
bubble sort method
![Page 80: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/80.jpg)
Selection Sort
This version uses two lists…
![Page 81: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/81.jpg)
Selection Sort
7 5 9 6 1 8 2 0 3 4
![Page 82: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/82.jpg)
Selection Sort
7 5 9 6 1 8 2 X 3 4
0 After 1st pass
![Page 83: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/83.jpg)
Selection Sort
7 5 9 6 X 8 2 X 3 4
0 1 After 2nd pass
![Page 84: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/84.jpg)
Selection Sort
7 5 9 6 X 8 X X 3 4
0 1 2 After 3rd pass
![Page 85: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/85.jpg)
Selection Sort
7 5 9 6 X 8 X X X 4
0 1 2 3 After 4th pass
![Page 86: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/86.jpg)
Selection Sort
7 5 9 6 X 8 X X X X
0 1 2 3 4 After 5th pass
![Page 87: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/87.jpg)
Selection Sort
7 X 9 6 X 8 X X X X
0 1 2 3 4 5 After 6th pass
![Page 88: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/88.jpg)
Selection Sort
7 X 9 X X 8 X X X X
0 1 2 3 4 5 6 After 7th pass
![Page 89: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/89.jpg)
Selection Sort
X X 9 X X 8 X X X X
0 1 2 3 4 5 6 7 After 8th pass
![Page 90: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/90.jpg)
Selection Sort
X X 9 X X X X X X X
0 1 2 3 4 5 6 7 8 After 9th pass
![Page 91: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/91.jpg)
Selection Sort
X X X X X X X X X X
0 1 2 3 4 5 6 7 8 9 After 10th pass
![Page 92: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/92.jpg)
Selection Sort
1. for outer = 1 to n-12. minimum = outer 3. for inner = 0 to N {line modified for two lists} 4. if list_A(inner) < list_A(minimum) then 5. minimum = inner 6. end if 7. next inner 8. list_B(outer) = list_A(minimum) 9. list_A(minimum) = dummy value 10. next outer
![Page 93: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/93.jpg)
Selection Sort
1. Makes excessive use of memory as two lists required.
![Page 94: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/94.jpg)
Selection Sort Task
Using the cards provided and With a partner Sort the cards into ascending order using the
selection sort method
![Page 95: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/95.jpg)
Summary of three sorting algorithms
The criteria for measuring algorithm performance are –
1.Behaviour with different size lists
2.Memory requirements
3.Stability
![Page 96: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/96.jpg)
Summary of three sorting algorithms
Simple sort Bubble sort Selection sort using two lists
Comparisons N(N-1)/2 N x N N x N
Passes N N Negligible
Memory Negligible Negligible Small
Uses Small Lists None Lists
stability Stable Stable Stable
![Page 97: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/97.jpg)
Summary of three sorting algorithms
Partially ordered list – use Bubble Sort Randomly ordered list – use Simple Sort Simplicity of implementation – use Selection
Sort
![Page 98: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/98.jpg)
User-defined Module Libraries
![Page 99: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/99.jpg)
Module Library
Depositaries of useful software procedures, functions, subroutines, programs, applications, OS routines Objects Classes Type declarations Etc.
![Page 100: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/100.jpg)
Module Library
If they are all packaged as a DLL file (dynamic link library) then they can be used within most programming environments simply by calling them up
Windows itself is composed of many DLL files
A DLL contains executable code and will link to a programming application at run time rather than at compile time.
![Page 101: Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.](https://reader035.fdocuments.us/reader035/viewer/2022062313/56649c975503460f949533fb/html5/thumbnails/101.jpg)
Exercise
Create a new folder and call it Module Library Work through the worked examples on page
169 onwards