Sorting Develop a sorting algorithm

Slides:



Advertisements
Similar presentations
Chapter 12 Sorting and searching. This chapter discusses n Two fundamental list operations. u Sorting u Searching n Sorted lists. n Selection/bubble sort.
Advertisements

Revision.
Order Analysis of Algorithms Debdeep Mukhopadhyay IIT Madras.
CS107 Introduction to Computer Science Lecture 5, 6 An Introduction to Algorithms: List variables.
CS 106 Introduction to Computer Science I 03 / 08 / 2010 Instructor: Michael Eckmann.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the basic concepts and uses of arrays ❏ To be able to define C.
End Show Writing a computer program involves performing the following tasks. 1. Understanding the problem 2. Developing an Algorithm for the problem 3.
Computer Science 101 Introduction to Sorting. Sorting One of the most common activities of a computer is sorting data Arrange data into numerical or alphabetical.
Sorts Tonga Institute of Higher Education. Introduction - 1 Sorting – The act of ordering data Often, we need to order data.  Example: Order a list of.
Fundamentals of Algorithms MCS - 2 Lecture # 15. Bubble Sort.
To know and use the Bubble Sort and Shuttle Sort Algorithms.
Sorting List is rearranged into sorted order How is the sorted order determined? – The ItemType is responsible for determining the key to be used in comparison.
1. Understand the application of Pseudo Code for programming purposes 2. Be able to write algorithms in Pseudo Code.
Computer Science I: Understand how to evaluate expressions with DIV and MOD Random Numbers Reading random code Writing random code Odds/evens/…
Array Review Selection Sort Get out your notes.. Learning Objectives Be able to dry run programs that use arrays Be able to dry run programs that use.
Computer Science 2 Arrays of Records. First Record Program Input an unknown number of Team Names, School names, and Total scores. (While loop) –Output:
Searching and Sorting Copyright Prentice Hall (with additions / modifications by Evan Korth)
Starter Complete the Word Search. CG3.7 Algorithms (The Insertion Sort (Chapter 46) & Algorithm Testing)
Copyright Prentice Hall Modified by Sana odeh, NYU
Introduction to Sorting
Growth of Functions & Algorithms
Learning outcomes 2 Developing Code – Input Output Model
Fundamentals of Java: AP Computer Science Essentials, 4th Edition
Data Structures and Algorithms
Chapter 2 (16M) Sorting and Searching
Lesson 5-15 AP Computer Science Principles
Chapter 8 Arrays Objectives
Topics discussed in this section:
Array Review Selection Sort
Quick Sort (11.2) CSE 2011 Winter November 2018.
Analysis of Bubble Sort and Loop Invariant
Topics discussed in this section:
مفاهیم بهره وري.
Computer Science 1 Online time to complete/enhance second repeat program Be able to read and write a program that uses the ‘case’ statement.
How do you store a bunch of similar stuff?
Chapter 8 Arrays Objectives
Big O Notation.
Sorts on the AP Exam Insertion Sort.
Simple Algorithms to Teach the Ideas Behind Coding
Computer Science 2 Arrays of Records.
Computer Science 2 Review the Bubble Sort
Insertion Sort Quiz on Thursday.
Computer Science And he made a molten sea, ten cubits from the one brim to the other: it was round all about, and his height was five cubits: and.
Computer Science 2 Getting an unknown # of …. Into an array.
Insertion Sort.
Computer Science Sorting.
Computer Science 2 Arrays of Records.
How do you store a bunch of similar stuff?
Simple Algorithms to Teach the Ideas Behind Coding
Sorting Example Bubble Sort
CS150 Introduction to Computer Science 1
Computer Science Sorting Pre-Test Discussion/program
Computer Science 2 Tally Arrays 2/4/2016.
Chapter 8 Arrays Objectives
AP Java 9/21/2018.
Computer Science 2 More Trees.
COP3530- Data Structures Introduction
How do you store a bunch of similar stuff?
Computer Science I: Get out your notes.
Array Review Selection Sort
Dry Run Fix it Write a program
Program: Mini Phone Book 2/11/2016
Computer Science 1 Review and finish Number base conversion
Insertion Sort.
Random Numbers while loop
Computer Science 1 while
Dry Run Fix it Write a program
WJEC GCSE Computer Science
Algorithms.
Insertion and Shell Sorts
Presentation transcript:

Sorting Develop a sorting algorithm Computer Science Sorting Develop a sorting algorithm

Learning Objectives Be able to complete the Tally Array program. Be able to develop a strategy to put information in order using an array.

Sorting How do you put things in order? (Low to high) Pseudo-Code Develop a sorting algorithm

Bubble Sort Low High 8 2 6 9 21 1 Speed: O(n2) Stability: Stable How it works: Check- Switch http://www.dat.ruc.dk/~keld/algoritmik_e99/Applets/Chap08/Bubble/BubbleSort.html Show it after each pass Low High 8 2 6 9 21 1

Bubble Sort {This is just the code for Bubble Sort} for pass:= 1 to (size -1) do begin for check:= 1 to size-1 do if TheArray[check]>TheArray[check+1] then dummy:= TheArray[check]; TheArray[check]:= TheArray[check+1]; TheArray[check+1]:= dummy; End; {Of the if and the for check loop} end;{Of the for pass loop}

Sorting Program Option #1 Option #2 Randomly generate 100 scores from 1 to 50. Show the numbers before they are sorted show the numbers after they are sorted. Push: Show graphically the numbers being sorted. Push: Change it to 5000 numbers and time how long it takes for them to sort. Push: Improve the efficiency of the sort. Option #2 Input 10 race times for the 100 meter dash. (enter the time as seconds) Output: The times sorted from fastest to slowest. Push: Enter the name that goes with each time, and show a chart of names and times for the race.