Lesson 2. Starter Look at the hand out you have been given. Can you sort the numbers into ascending...
-
Upload
beatrice-harrell -
Category
Documents
-
view
212 -
download
0
Transcript of Lesson 2. Starter Look at the hand out you have been given. Can you sort the numbers into ascending...
![Page 1: 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.](https://reader036.fdocuments.in/reader036/viewer/2022070408/56649e665503460f94b6041d/html5/thumbnails/1.jpg)
Lesson 2
GCSE Computing
![Page 2: 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.](https://reader036.fdocuments.in/reader036/viewer/2022070408/56649e665503460f94b6041d/html5/thumbnails/2.jpg)
StarterLook at the hand out you have been given.
Can you sort the numbers into ascending order.
What mental or physical methods did you use to sort them?
![Page 3: 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.](https://reader036.fdocuments.in/reader036/viewer/2022070408/56649e665503460f94b6041d/html5/thumbnails/3.jpg)
Algorithms - Sorting Sorting algorithms are very frequently used in programming. There are many situations in which data needs to be sorted. There are many different sorting algorithms out there that have
different level of efficiencies.
Some example of sorts: Bubble Selection Insertion Quick
VIDEO – Sorting.mp4
![Page 4: 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.](https://reader036.fdocuments.in/reader036/viewer/2022070408/56649e665503460f94b6041d/html5/thumbnails/4.jpg)
Algorithms - Sorting
Bubble SortAlgorithm for bubble sort
count1 = length of listcount2 = length of list -1FOR 1 to count1
FOR 1 to count2IF list[count2] > list[count2+1] THEN
temp = list[count2]list[count2] = list[count2+1]list[count2+1] = temp
ENDIFENDFOR
ENDFOR
![Page 5: 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.](https://reader036.fdocuments.in/reader036/viewer/2022070408/56649e665503460f94b6041d/html5/thumbnails/5.jpg)
Algorithms - Sorting
Bubble Sort6 2 1 3 2 1 4 0 1 3
2 6 1 3 2 1 4 0 1 3
2 1 6 3 2 1 4 0 1 3
2 1 3 6 2 1 4 0 1 3
2 1 3 2 6 1 4 0 1 3
2 1 3 2 1 6 4 0 1 3
2 1 3 2 1 4 6 0 1 3
2 1 3 2 1 4 0 6 1 3
2 1 3 2 1 4 0 1 6 3
2 1 3 2 1 4 0 1 3 6
Key
Sorted list
Items being swapped
![Page 6: 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.](https://reader036.fdocuments.in/reader036/viewer/2022070408/56649e665503460f94b6041d/html5/thumbnails/6.jpg)
Algorithms - Sorting
Bubble Sort
1 2 3 2 1 4 0 1 3 6 Key
Sorted list
Items being swapped
1 2 2 3 1 4 0 1 3 6
1 2 2 1 3 4 0 1 3 6
1 2 2 1 3 0 4 1 3 6
1 2 2 1 3 0 1 4 3 6
1 2 2 1 3 0 1 3 4 6
1 2 2 1 3 0 1 3 4 6
Etc.......
Using your numbers – use the bubble sort method to sort your numbers
![Page 7: 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.](https://reader036.fdocuments.in/reader036/viewer/2022070408/56649e665503460f94b6041d/html5/thumbnails/7.jpg)
Algorithms - Sorting
Selection sortAlgorithm for selection sort
minimum = 99999999count1 = length of listcount2 = length of listpositionofminimum = 1
FOR 1 to count1FOR 1 to count2
IF list(count2) < minimum THENminimum = list(count2)positionofminimum = count2
ENDIFENDFOR
temp = list(count1)list(count1) = list(positionofminimum)list(positionofminimum) = temp
END FOR
![Page 8: 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.](https://reader036.fdocuments.in/reader036/viewer/2022070408/56649e665503460f94b6041d/html5/thumbnails/8.jpg)
6 2 1 3 2 1 4 0 1 3Key
Sorted list
Items being swapped
0 2 1 3 2 1 4 6 1 3
0 1 2 3 2 1 4 6 1 3
0 1 1 3 2 2 4 6 1 3
0 1 1 1 2 2 4 6 3 3
0 1 1 1 2 2 4 6 3 3
0 1 1 1 2 2 4 6 3 3
0 1 1 1 2 2 3 6 4 3
0 1 1 1 2 2 3 3 4 6
0 1 1 1 2 2 3 3 4 6
Algorithms – SortingSelection
Using your numbers – use the selection sort method to sort your numbers
![Page 9: 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.](https://reader036.fdocuments.in/reader036/viewer/2022070408/56649e665503460f94b6041d/html5/thumbnails/9.jpg)
Algorithms – Sorting
Insertion Sort
Algorithm for insertion sort
FOR every item in listSort into new list by inserting it into correct place, one item at a time.
END FOR
![Page 10: 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.](https://reader036.fdocuments.in/reader036/viewer/2022070408/56649e665503460f94b6041d/html5/thumbnails/10.jpg)
Algorithms – Sorting
Insertion Sort
6 2 1 3 2 1 4 0 1 3
2 6 1 3 2 1 4 0 1 3
1 2 6 3 2 1 4 0 1 3
1 2 3 6 2 1 4 0 1 3
1 2 2 3 6 1 4 0 1 3
1 1 2 2 3 6 4 0 1 3
1 1 2 2 3 4 6 0 1 3
0 1 1 2 2 3 4 6 1 3
0 1 1 1 2 2 3 4 6 3
0 1 1 1 2 2 3 3 4 6
Key
Sorted list
Using your numbers – use the insertion sort method to sort your numbers
![Page 11: 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.](https://reader036.fdocuments.in/reader036/viewer/2022070408/56649e665503460f94b6041d/html5/thumbnails/11.jpg)
Algorithms - Sorting Look at these examples of how different algorithms can change
the speed of the sorting
Link 1 – CLICK HERE
http://www.sorting-algorithms.com/
Link 2 – CLICK HERE
http://www.cs.ubc.ca/~harrison/Java/sorting-demo.html
![Page 12: 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.](https://reader036.fdocuments.in/reader036/viewer/2022070408/56649e665503460f94b6041d/html5/thumbnails/12.jpg)
Algorithms - Sorting Task
With a bit of research – compare and contrast the bubble sort, insertion sort, selection sort and Quick sort.
Ask yourself the following questions
1) Can you describe how each one works?2) What is difference between them?3) Which one is the most efficient?4) Why do you think one is more efficient than another – what
makes is more efficient?