Computer Science 2 Review the Bubble Sort

Slides:



Advertisements
Similar presentations
CS107 Introduction to Computer Science Lecture 5, 6 An Introduction to Algorithms: List variables.
Advertisements

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.
Chapter 10 Strings, Searches, Sorts, and Modifications Midterm Review By Ben Razon AP Computer Science Period 3.
Chapter 6: Arrays: Lists and Tables
Python Repetition. We use repetition to prevent typing the same code out many times and to make our code more efficient. FOR is used when you know how.
Java Methods 11/10/2015. Learning Objectives  Be able to read a program that uses methods.  Be able to write a write a program that uses methods.
Static block can be used to check conditions before execution of main begin, Suppose we have developed an application which runs only on Windows operating.
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.
Permutations and Combinations Review Plus a little Dry Run, Sorting and Code.
Marr CollegeHigher Software DevelopmentSlide 1 Higher Computing Software Development Topic 4: Standard Algorithms.
Computer Science 2 Arrays of Records. First Record Program Input an unknown number of Team Names, School names, and Total scores. (While loop) –Output:
Copyright Prentice Hall Modified by Sana odeh, NYU
GCSE COMPUTER SCIENCE Practical Programming using Python
Canvas and Arrays in Apps
Regular Expressions 'RegEx'.
Data Types Variables are used in programs to store items of data e.g a name, a high score, an exam mark. The data stored in a variable is entered from.
Fundamentals of Java: AP Computer Science Essentials, 4th Edition
Chapter 2 (16M) Sorting and Searching
Lesson 5-15 AP Computer Science Principles
Chapter 8 Arrays Objectives
Chapter 7 Arrays.
Chapter 5: Arrays: Lists and Tables
CIS 170 Education for Service-- snaptutorial.com.
CIS 170 Teaching Effectively-- snaptutorial.com
Array Review Selection Sort
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
Sorts on the AP Exam Insertion Sort.
Computer Science 2 Arrays of Records.
Continue on the Array of Records program
Insertion Sort Quiz on Thursday.
Computer Science 2 Arrays of Records.
Computer Science 2 Getting an unknown # of …. Into an array.
Repeat Day2 Dry Run Second Repeat Program
Insertion Sort.
Computer Science Sorting.
Computer Science 1 1/19/2011 On the record (paper) write the following
Computer Science 2 Arrays of Records.
How do you store a bunch of similar stuff?
Computer Science Sorting Pre-Test Discussion/program
Computer Science 2 Tally Arrays 2/4/2016.
CS 2 Records 2/22/2018.
Chapter 8 Arrays Objectives
AP Java 9/21/2018.
Computer Science 1 Online time for Graphics Program Random review
How can you make a guessing game?
Sorting Develop a sorting algorithm
Computer Science 1 while
Computer Science 1 For..do loop Dry Run Take notes on the For loop
Computing Spans Given an an array X, the span S[i] of X[i] is
How can you make a guessing game?
COP3530- Data Structures Introduction
Message game One person from each group( a messenger)
How do you store a bunch of similar stuff?
Welcome Back CS 2 2/4/2013 On the record (paper) write the following
Computer Science I: Get out your notes.
Unit 2: Computational Thinking, Algorithms & Programming
Array Review Selection Sort
Computer Science 1 while
Insertion Sort.
Random Numbers while loop
WJEC GCSE Computer Science
Computer Science 1 while
Dry Run Fix it Write a program
Algorithms For use in Unit 2 Exam.
Insertion and Shell Sorts
Presentation transcript:

Computer Science 2 Review the Bubble Sort Getting an unknown # of …. Into an array. Looking at another type of sort.

Learning Objectives Demonstrate how a Bubble Sort Works Be able to implement the code in order to sort values Develop a method to storing an unknown number of items in an array. Take a look at another method of sorting.

Bubble Sort Review In your notes answer the following: What is the speed of a bubble sort? Is it stable? What does stability mean? How does a bubble Sort Work? Show the following items after each pass of the Bubble sort until they are in order. LOW HIGH 50 8 20 14 6 12 2

Sorting Program Online time. 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.

How can you store an unknown number of Song Titles into an array? Type Songtype = array[1..100] of string; Var Songs:songtype; numberOfSongs:integer;

Code

Another Sort Selection Sort http://en.wikipedia.org/wiki/Selection_sort Speed:_________ Stability: _____________ How it works: _____________

Showing it after each pass Low High 8 30 22 15 2 45 3 High Low 10 14 3 26 15 31 7

Selection Sort: Code {*** This is just the sorting code } for pass:= size downto 2 do begin mark:=pass; for check:= 1 to pass do if TheArray[check] > TheArray[mark] then mark:=check; {Mark} dummy:=TheArray[mark]; {Switch} TheArray[mark]:=TheArray[pass]; TheArray[pass]:= dummy; end; {Of the for pass loop}

Program Options Song Sort: Input an unknown number of songs (but less than 100) Show out of order Sort Show in order Push: Let the user also enter the Style of music, and be able to sort by style. Name age sort Input: An unknown number of names and ages Output: The names and corresponding ages in a chart sorted by age. Push: Let the user decide if they want to sort by age or name, then sort and show the chart.