Bubble Sort Key Revision Points.

Slides:



Advertisements
Similar presentations
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,
Advertisements

Chapter 2.9 Sorting Arrays. Sort Algorithms A set of records is given Each record is identified by a certain key One wants to sort the records according.
Sorting CMSC 201. Sorting In computer science, there is often more than one way to do something. Sorting is a good example of this!
Sorting A fundamental operation in computer science (many programs need to sort as an intermediate step). Many sorting algorithms have been developed Choose.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 9A Sorting (Concepts)
1 CSE1301 Computer Programming: Lecture 28 List Sorting.
1 Sorting II: Bubble Sort and Selection Sort CSC326 Information Structure Spring 2009.
Sorting and Searching. Searching List of numbers (5, 9, 2, 6, 3, 4, 8) Find 3 and tell me where it was.
Wednesday, 11/25/02, Slide #1 CS 106 Intro to CS 1 Wednesday, 11/25/02  QUESTIONS??  Today:  More on sorting. Advanced sorting algorithms.  Complexity:
Searches & Sorts V Deena Engel’s class Adapted from W. Savitch’s text An Introduction to Computers & Programming.
Discrete Math CSC151 Analysis of Algorithms. Complexity of Algorithms  In CS it's important to be able to predict how many resources an algorithm will.
Advance Data Structure 1 College Of Mathematic & Computer Sciences 1 Computer Sciences Department م. م علي عبد الكريم حبيب.
Examples using Arrays. Summing Squares Problem: To compute the sum of the squares of N numbers N is given N values are also given These should be read.
Lecture 4: Sorting Algorithms Prof Branestawm’s Sorting Challenge.
Decision Maths 1 Sorting Algorithm Shuttle Sort A V Ali : 1.Compare items 1 and 2; swap them if necessary 2.Compare 2 and 3; swap.
Fundamentals of Algorithms MCS - 2 Lecture # 15. Bubble Sort.
3.3 Complexity of Algorithms
Bubble Sort.
CS 162 Intro to Programming II Bubble Sort 1. Compare adjacent elements. If the first is greater than the second, swap them. Do this for each pair of.
3 – SIMPLE SORTING ALGORITHMS
1 Sorting (Bubble Sort, Insertion Sort, Selection Sort)
Elementary Sorting 30 January Simple Sort // List is an array of size == n for (i = 1; i < n; i++) for (j = i+1; j List[j])
1 UNIT-I BRUTE FORCE ANALYSIS AND DESIGN OF ALGORITHMS CHAPTER 3:
Searching Topics Sequential Search Binary Search.
Computer Science 1620 Sorting. cases exist where we would like our data to be in ascending (descending order) binary searching printing purposes selection.
Experimental Study on the Five Sort Algorithms You Yang, Ping Yu, Yan Gan School of Computer and Information Science Chongqing Normal University Chongqing,
Sorting & Searching Geletaw S (MSC, MCITP). Objectives At the end of this session the students should be able to: – Design and implement the following.
Aims: To learn about some simple sorting algorithms. To develop understanding of the importance of efficient algorithms. Objectives: All:Understand how.
SORTING Sorting is storage of data in some order, it can be in ascending or descending order. The term Sorting comes along-with the term Searching. There.
Sort Algorithm.
UNIT - IV SORTING By B.Venkateswarlu Dept of CSE.
The Bubble Sort Mr. Dave Clausen La Cañada High School
Searching and Sorting Algorithms
Sorting With Priority Queue In-place Extra O(N) space
Tips and tools for creating and presenting wide format slides
Week 13: Searching and Sorting
May 17th – Comparison Sorts
COMP108 Algorithmic Foundations Polynomial & Exponential Algorithms
Lecture 14 Searching and Sorting Richard Gesick.
Sorting Algorithms.
Lesson Objectives Aims Understand the following “standard algorithms”:
Searching & Sorting "There's nothing hidden 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.
Data Structures and Analysis (COMP 410)
Bubble Sort The basics of a popular sorting algorithm.
Bubble, Selection & Insertion sort
Selection Sort – an array sorting algorithm
Welcome to CIS 068 ! Lesson 9: Sorting CIS 068.
And now for something completely different . . .
“Human Sorting” It’s a “Problem Solving” game:
Sorting Algorithms Ellysa N. Kosinaya.
Lecture 11 Searching and Sorting Richard Gesick.
IT 4043 Data Structures and Algorithms
Search,Sort,Recursion.
Simple Sorting Methods: Bubble, Selection, Insertion, Shell
Principles of Computing – UFCFA3-30-1
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.
Visit for More Learning Resources
Quadratic Sorts & Breaking the O(n2) Barrier
Search,Sort,Recursion.
Parallel sorting.
Intro to Computer Science CS1510 Dr. Sarah Diesburg
CPS120: Introduction to Computer Science
Loops.
CPS120: Introduction to Computer Science
Principles of Computing – UFCFA3-30-1
CSE 373 Sorting 2: Selection, Insertion, Shell Sort
“Human Sorting” It’s a “Problem Solving” game:
Sorting.
Module 8 – Searching & Sorting Algorithms
Visit for more Learning Resources
Presentation transcript:

Bubble Sort Key Revision Points

Big Picture When do you need to sort things in your daily activities? Sort your room? Sort DVDs, books or computer games so they are in order? Sort out old clothes that you don’t want anymore? How do you think a computer sorts items?

Learning Objectives Understand the principles of a bubble sort. Be able to perform a bubble sort on a set of data. Understand how the number of comparisons increases in a bubble sort.

Key Words Bubble sort – moving through a list repeatedly, swapping elements that are in the wrong order.

Bubble Sort Repeat: Move along the list to the next pair Take the first element and second element from the list Compare them IF element 1 > element 2 THEN Swap then ELSE Do nothing Repeat: Move along the list to the next pair IF no more elements: Goto 1 ELSE: Goto 2 Until: you have moved through the entire list and not made any changes

Bubble Sort - Example Element Number Value 1 2 3 4 5 6 7 8 13 9 10 12 1) Compare elements 1 and 2 2) Is element 1 > element 2? 1 2 3 4 5 6 7 8 13 9 10 12 3) Yes: so swap them 1 2 3 4 5 6 7 8 13 9 10 12 4) Compare elements 2 and 3 5) Is element 2 > element 3? 1 2 3 4 5 6 7 8 13 9 10 12 6) Yes: so swap them

Bubble Sort - Example Talk through the next steps that are taken in the bubble sort: 1 2 3 4 5 6 7 8 13 9 10 12 1 2 3 4 5 6 7 8 13 9 10 12 1 2 3 4 5 6 7 8 13 9 10 12 1 2 3 4 5 6 7 8 9 13 10 12

Bubble Sort - Example 1 2 3 4 5 6 7 8 9 13 10 12 Compare elements 5 and 6 Is element 5 > element 6? 1 2 3 4 5 6 7 8 9 10 13 12 Yes, so swap them 1 2 3 4 5 6 7 8 9 10 13 12 Compare elements 6 and 7 Is element 6 > element 7? 1 2 3 4 5 6 7 8 9 10 12 13 Yes, so swap them

You have come to the end of the list. Bubble Sort - Example 1 2 3 4 5 6 7 8 9 10 12 13 Compare elements 7 and 8 Is element 7 > element 8? 1 2 3 4 5 6 7 8 9 10 12 13 Yes, so swap them You have come to the end of the list. A change has been made. So you start again. Compare elements 1 and 2 1 2 3 4 5 6 7 8 9 10 12 13 Swap? No

Bubble Sort - Example Compare 2 and 3 1 2 3 4 5 6 7 8 9 10 12 13 Swap? No Compare 3 and 4 1 2 3 4 5 6 7 8 9 10 12 13 Swap? No Compare 4 and 5 1 2 3 4 5 6 7 8 9 10 12 13 Swap? No Compare 5 and 6 1 2 3 4 5 6 7 8 9 10 12 13 Swap? No

Task: Work in pairs to complete the bubble sort. Bubble Sort - Example Compare 6 and 7 1 2 3 4 5 6 7 8 9 10 12 13 Swap? Yes 1 2 3 4 5 6 7 8 9 10 12 13 Compare 7 and 8 1 2 3 4 5 6 7 8 9 10 12 13 Swap? No You’ve reached the end. Have you made any swaps? Yes, so start again. Task: Work in pairs to complete the bubble sort.

Complexity In a list of 10 numbers... …positioned in the worst case (i.e. all of the elements are in reverse order)... how many comparisons would the sort algorithm need to do? 100 n*n where n is the number of elements The average number of swaps is n^2.