Lecture # 2 Algorithms and Programs. Today Questions: From Homework #1 1.Introduce: What is an Algorithm? 2.Explain: Algorithm defined 3.Demo: Examples.

Slides:



Advertisements
Similar presentations
Md. Ahsan Arif, Assistant Professor, Dept. of CSE, AUB
Advertisements

College of Information Technology & Design
Designed and Presented by Dr. Ayman Elshenawy Elsefy Dept. of Systems & Computer Eng.. Al-Azhar University
Announcements You survived midterm 2! No Class / No Office hours Friday.
MATH 224 – Discrete Mathematics
1 CS101 Introduction to Computing Lecture 17 Algorithms II.
1 ICS102: Introduction To Computing King Fahd University of Petroleum & Minerals College of Computer Science & Engineering Information & Computer Science.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Algorithmic Thinking What’s the Plan? lawrence snyder c h a p t e r 10.
Basic Programming Concepts INTRO TO PROGRAMMING. Questions to answer  What is a computer program?  What are computer instructions  How is a program.
CMPT 120 Introduction to Computer Science and Programming I Chris Schmidt.
Computer Science 101 Overview of Algorithms. Example: Make Pancakes Prepare batter Beat 2 eggs Add 1 tablespoon of brown sugar Add 1 cup of milk Add 2.
Learning Objectives Explain similarities and differences among algorithms, programs, and heuristic solutions List the five essential properties of an algorithm.
Chapter 10 Algorithmic Thinking. Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Learning Objectives List the five essential.
Chapter 10 What's The Plan?: Algorithmic Thinking.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Introduction to Computers CS Dr. Zhizhang Shen Chapter 10: How to.
Text Chapters 1, 2. Sorting ä Sorting Problem: ä Input: A sequence of n numbers ä Output: A permutation (reordering) of the input sequence such that:
1 Lecture 1: Course Overview Course: CSE 360 Instructor: Dr. Eric Torng TA: Huamin Chen.
Lecture 14 Go over midterm results Algorithms Efficiency More on prime numbers.
Algorithms and Problem Solving. Learn about problem solving skills Explore the algorithmic approach for problem solving Learn about algorithm development.
Chapter 2: Algorithm Discovery and Design
Chapter 2 The Algorithmic Foundations of Computer Science
CS /29/2004 (Recitation Objectives) and Computer Science and Objects and Algorithms.
School of Computing Science CMT1000 © Ed Currie Middlesex University 1 CMT1000: Introduction to Programming Ed Currie Lecture 1B: Problem Solving.
Chapter 2: Algorithm Discovery and Design
Chapter 2: Algorithm Discovery and Design
Sort an array - the selection sort algorithm. Selection Sort Selection sort a classic computer algorithm that is used to sort an array The selection sort.
Introduction Dr. Ying Lu RAIK 283: Data Structures & Algorithms.
Lecture # 3 HTML and Arrays. Today Questions: From notes/reading/life? From Lab # 2 – Preview of Lab # 2 1.Introduce: How do you make a Web Page?: HTML.
Invitation to Computer Science, Java Version, Second Edition.
Introduction. 2COMPSCI Computer Science Fundamentals.
Analysis of Algorithms
Some quotes…. I really hate this damned machine I wish that they would sell it. It never does quite what I want But only what I tell it. ~Anon These machines.
ดร.สุรศักดิ์ มังสิงห์ SPU, Computer Science Dept.
Prepared By Ms.R.K.Dharme Head Computer Department.
Lecture 6 Problem Solving: Algorithm Design & Analysis.
Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy Walters, and Godfrey Muganda Modified for use by MSU Dept. of Computer Science.
New Mexico Computer Science For All Algorithm Analysis Maureen Psaila-Dombrowski.
1 Section 2.1 Algorithms. 2 Algorithm A finite set of precise instructions for performing a computation or for solving a problem.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Fluency with Information Technology Third Edition by Lawrence Snyder Chapter.
CSCI-100 Introduction to Computing
Data Structures and Algorithms Dr. Tehseen Zia Assistant Professor Dept. Computer Science and IT University of Sargodha Lecture 1.
ALGORITHMS.
CS404 Design and Analysis of Algorithms BBy DDr. M V S Peri Sastry BB.E, PhD(BITS-Pilani)
Introduction to design and analysis algorithm
DATA STRUCTURES (CS212D) Overview & Review Instructor Information 2  Instructor Information:  Dr. Radwa El Shawi  Room: 
Flowchart. a diagram of the sequence of movements or actions of people or things involved in a complex system or activity. a graphical representation.
CS 101 – Oct. 7 Solving simple problems: create algorithm Structure of solution –Sequence of steps (1,2,3….) –Sometimes we need to make a choice –Sometimes.
Software. Introduction n A computer can’t do anything without a program of instructions. n A program is a set of instructions a computer carries out.
1 Introduction to design and analysis algorithm. 2.
Introduction to Computer Science and Programming I Chris Schmidt
ICS 3UI - Introduction to Computer Science
Applied Discrete Mathematics Week 2: Functions and Sequences
COP 3503 FALL 2012 Shayan Javed Lecture 15
Data Structures and Algorithms
Algorithms Today we will look at: what the word algorithm means
An Introduction to Control Structures
Lesson 15: Processing Arrays
Rosen 5th ed., §2.1 ~31 slides, ~1 lecture
CSCI 1250 Information Technologies
Rosen 5th ed., §2.1 ~31 slides, ~1 lecture
Chapter 10: Algorithm TECH Prof. Jeff Cheng.
Algorithms and Problem Solving
What's The Plan?: Algorithmic Thinking
An Introduction to Control Structures
Click to add Text Computers & Instructions. Computers are given instructions in the form of computer programs that are created through the development.
Discrete Mathematics and its Applications
Recipes.
What's The Plan?: Algorithmic Thinking
What's The Plan?: Algorithmic Thinking
Presentation transcript:

Lecture # 2 Algorithms and Programs

Today Questions: From Homework #1 1.Introduce: What is an Algorithm? 2.Explain: Algorithm defined 3.Demo: Examples of Algorithms 4.Practice: You will create an Algorithm 5.Evaluate: We will share and evaluate our Algorithms 6.Re-practice: Analyze your favorite recipe as an Algorithm We will look at a classical sorting Algorithm together You will look at a Program on your own

Review of Homework # 1 Groups share Sorting Algorithms What is the Key Idea of the Algorithm? What makes an algorithm efficient? What is the best Sorting Algorithm?

Today Questions: From Homework #1 1.Introduce: What is an Algorithm? 2.Explain: Algorithm defined 3.Demo: Examples of Algorithms 4.Practice: You will create an Algorithm 5.Evaluate: We will share and evaluate our Algorithms 6.Re-practice: Analyze your favorite recipe as an Algorithm We will look at a classical sorting Algorithm together You will look at a Program on your own

Algorithms What is an Algorithm? A precise, repeatable method or finite sequence of steps to solve a problem or accomplish a task What are some examples of algorithms? - In everyday life? - In Science? - In Computing? - In the workplace?

Algorithms What is an Algorithm? A precise, repeatable method or finite sequence of steps to solve a problem or accomplish a task What are some examples of algorithms? - In everyday life? Recipes – Dressing - Driving - In Science? Temperature Conversion - Adding - In Computing? Searching – Network Traffic - In the workplace? Purchasing – Food Preparation

Algorithms Example 1 To Die-For Pot Roast: Ingredients: 1 (4 -5 lb) beef roast, any kind 1 (1 1/4 ounce) package brown gravy mix, dry 1 (1 1/4 ounce) package dried Italian salad dressing mix 1 (1 1/4 ounce) package ranch dressing mix, dry 1/2 cup water

Algorithms Example 1 (cont.) To Die-For Pot Roast: Directions: Step 1: Place beef roast in crock pot. Step 2: Mix the dried mixes together in a bowl and sprinkle over the roast. Step 3: Pour the water around the roast. Step 4: Cook on low for 7-9 hours.

Today Questions: From Homework #1 1.Introduce: What is an Algorithm? 2.Explain: Algorithm defined 3.Demo: Examples of Algorithms 4.Practice: You will create an Algorithm 5.Evaluate: We will share and evaluate our Algorithms 6.Re-practice: Analyze your favorite recipe as an Algorithm We will look at a classical sorting Algorithm together You will look at a Program on your own.

Algorithm Exercise Algorithm for Getting to School – write it on your laptop so you can share it Step 1: Unsleep (must be specific – when?) Step 2: Step 3: Step 4: Step 5: Step 6: Step 7:

What’s in Your Algorithm? WPbasic – on screen Share and Evaluate

Algorithm Efficiency What makes an algorithm efficient? - Is it the time that it takes? - Is it the number of steps required? - Is it the complexity?

Algorithm Efficiency What has been the decrease in the mile run over the past 5 decades? What has been the decrease in the amount of time required by a computer to add two numbers over the past 5 decades? Has the algorithm for addition changed?

What are the Essential Ingredients of an Algorithm? Input: Define type, format of input data Output: Define output/result Steps: Specific sequence of steps or instructions Computable: steps can be performed, validated Halts: The algorithm will halt in finite time

Today Questions: From Homework #1 1.Introduce: What is an Algorithm? 2.Explain: Algorithm defined 3.Demo: Examples of Algorithms 4.Practice: You will create an Algorithm 5.Evaluate: We will share and evaluate our Algorithms 6.Re-practice: Analyze your favorite recipe as an Algorithm We will look at a classical sorting Algorithm together You will look at a Program on your own

Exercise Determine the inputs, outputs, steps and stopping condition for your favorite recipe Determine the inputs, outputs, steps and stopping conditions for other everyday tasks How can you increase the efficiency of some of these tasks?

Today Questions: From Homework #1 1.Introduce: What is an Algorithm? 2.Explain: Algorithm defined 3.Demo: Examples of Algorithms 4.Practice: You will create an Algorithm 5.Evaluate: We will share and evaluate our Algorithms 6.Re-practice: Analyze your favorite recipe as an Algorithm We will look at a classical sorting Algorithm together You will look at a Program on your own

Programs Computer Programs are simply algorithms that are implemented in a particular programming language like java, javascript, HTML, C, python, etc. These Languages use a sequence of steps, named variables, assignment statements, and data types and data structures to implement the algorithm.

Program A sequence of things to do A = 75; B = A+13; A = A-B+3; C = A/2 + 1;

Program A sequence of things to do A = 75; B = A+13; A = A-B+3; C = A/2 + 1;

Program A sequence of things to do A = 75; B = A+13; A = A-B+3; C = A/2 + 1; A = 88

Program A sequence of things to do A = 75; B = A+13; A = A-B+3; C = A/2 + 1; A-B = -10

Program A sequence of things to do A = 75; B = A+13; A = A-B+3; C = A/2 + 1; A / / = -4

Today Questions: From Homework #1 1.Introduce: What is an Algorithm? 2.Explain: Algorithm defined 3.Demo: Examples of Algorithms 4.Practice: You will create an Algorithm 5.Evaluate: We will share and evaluate our Algorithms 6.Re-practice: Analyze your favorite recipe as an Algorithm We will look at a classical sorting Algorithm together You will look at a Program on your own

Exercise: Write a Sorting Algorithm Create an algorithm to sort (alphabetize) a list of names. How will you represent the names? How will you solve this problem? What will be the key idea of the algorithm? - now that you are an expert (of “Sorts”)

A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name AJim BBill Alice Nancy Bob

A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name AJim BBill Alice Nancy Bob

A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name ABill BJim Alice Nancy Bob

A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name ABill BJim Alice Nancy Bob

A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name ABill Jim BAlice Nancy Bob

A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name ABill Jim BAlice Nancy Bob

A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name AAlice Jim BBill Nancy Bob

A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name AAlice Jim BBill Nancy Bob

A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name AAlice Jim Bill BNancy Bob

A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name AAlice Jim Bill BNancy Bob

A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name AAlice Jim Bill BNancy Bob

A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name AAlice Jim Bill Nancy BBob

A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name AAlice Jim Bill Nancy BBob

A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name AAlice Jim Bill Nancy BBob

A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name AAlice Jim Bill Nancy BBob

A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice AJim Bill Nancy BBob

A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice AJim BBill Nancy Bob

A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice AJim BBill Nancy Bob

A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice AJim BBill Nancy Bob

A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice ABill BJim Nancy Bob

A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice ABill BJim Nancy Bob

A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice ABill Jim BNancy Bob

A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice ABill Jim BNancy Bob

A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice ABill Jim BNancy Bob

A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice ABill Jim Nancy BBob

A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice ABill Jim Nancy BBob

A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice ABill Jim Nancy BBob

A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice ABill Jim Nancy BBob

A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice Bill AJim Nancy BBob

A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice Bill AJim BNancy Bob

A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice Bill AJim BNancy Bob

A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice Bill AJim BNancy Bob

A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice Bill AJim BNancy Bob

A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice Bill AJim BNancy Bob

A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice Bill AJim Nancy BBob

A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice Bill AJim Nancy BBob

A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice Bill ABob Nancy BJim

A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice Bill ABob Nancy BJim

A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice Bill ABob Nancy BJim

A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice Bill Bob ANancy BJim

A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice Bill Bob ANancy BJim

A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice Bill Bob ANancy BJim

A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice Bill Bob AJim BNancy

A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice Bill Bob AJim BNancy

A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice Bill Bob AJim BNancy

A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice Bill Bob AJim BNancy

Algorithm Analysis What is the Key Idea? - It makes use of an Exchange Sort - It compares 2 items and swaps them if they are out of order - This continues until we sweep through all of the names

Algorithm Analysis How efficient is this algorithm? - How many compares/swaps? - How many times do we “visit” each name on the list? - How can we characterize the “speed” or efficiency of this algorithm?

Algorithm Analysis How can we measure algorithm efficiency? - If there are n items in the list … - and we “visit” each item n times … - Then the algorithm is

Algorithm Analysis How can we measure algorithm efficiency? - If there are n items in the list … - and we “visit” each item n times … - Then the algorithm is ~n 2 complexity

Algorithm Analysis Can we do better than ~n 2 complexity? - Can we do ~n complexity? - Can we do ~2n complexity? - The most efficient algorithms are ~n log n