Last Class We Covered Sorting algorithms “Run” time Selection Sort

Slides:



Advertisements
Similar presentations
Algorithms Algorithm: what is it ?. Algorithms Algorithm: what is it ? Some representative problems : - Interval Scheduling.
Advertisements

Analysis And Algorithms CMSC 201. Search Sometimes, we use the location of a piece of information in a list to store information. If I have the list [4,
Search Lesson CS1313 Spring Search Lesson Outline 1.Searching Lesson Outline 2.How to Find a Value in an Array? 3.Linear Search 4.Linear Search.
1 5. Abstract Data Structures & Algorithms 5.6 Algorithm Evaluation.
Course Code #IDCGRF001-A 5.1: Searching and sorting concepts Programming Techniques.
CSCI 6212 Design and Analysis of Algorithms Which algorithm is better ? Dr. Juman Byun The George Washington University Please drop this course if you.
1 5. Abstract Data Structures & Algorithms 5.6 Algorithm Evaluation.
Intro to Data Structures Concepts ● We've been working with classes and structures to form linked lists – a linked list is an example of something known.
CMSC 104, Version 8/061L24Searching&Sorting.ppt Searching and Sorting Topics Sequential Search on an Unordered File Sequential Search on an Ordered File.
CMSC201 Computer Science I for Majors Lecture 23 – Algorithms and Analysis Prof. Katherine Gibson Based on slides from previous iterations.
CMSC201 Computer Science I for Majors Lecture 25 – Final Exam Review Prof. Katherine Gibson Prof. Jeremy Dixon.
CMSC201 Computer Science I for Majors Lecture 25 – Classes
UMBC CMSC 104 – Section 01, Fall 2016
Computer Networks CNT5106C
CMSC201 Computer Science I for Majors Lecture 23 – Sorting
Algorithmic complexity: Speed of algorithms
Big-O notation Linked lists
Algorithmic Efficency
Last Class We Covered Sorting algorithms Searching algorithms
CMSC201 Computer Science I for Majors Lecture 22 – Searching
Algorithm Analysis The case of recursion.
Intro to Computer Science CS1510 Dr. Sarah Diesburg
IGCSE 6 Cambridge Effectiveness of algorithms Computer Science
Introduction to complexity
Big-O notation.
CMPT 120 Topic: Searching – Part 1
Search Lesson Outline Searching Lesson Outline
COMP 53 – Week Seven Big O Sorting.
CMSC201 Computer Science I for Majors Lecture 24 – Sorting
CMSC201 Computer Science I for Majors Lecture 27 – Final Exam Review
ECET 370 Competitive Success-- snaptutorial.com
ECET 370 Education for Service-- snaptutorial.com
ECET 370 Teaching Effectively-- snaptutorial.com
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Computer Networks CNT5106C
Last Class We Covered Data representation Binary numbers ASCII values
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Algorithm design and Analysis
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Chapter 12: Analysis of Algorithms
Searching and Sorting Topics Sequential Search on an Unordered File
ITEC 2620M Introduction to Data Structures
Binary Search and Intro to Sorting
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Searching and Sorting Topics Sequential Search on an Unordered File
Last Class We Covered Sorting algorithms Searching algorithms
Last Class We Covered Dictionaries Hashing Dictionaries vs Lists
UMBC CMSC 104 – Section 01, Fall 2016
Searching and Sorting Topics Sequential Search on an Unordered File
CMSC201 Computer Science I for Majors Lecture 25 – Final Exam Review
Last Class We Covered Asymptotic Analysis Run “time” Big O
Algorithmic complexity: Speed of algorithms
Searching, Sorting, and Asymptotic Complexity
Searching, Sorting, and Asymptotic Complexity
Prof. Katherine Gibson Prof. Jeremy Dixon
CS 2430 Object Oriented Programming and Data Structures I
Intro to Computer Science CS1510 Dr. Sarah Diesburg
CMSC201 Computer Science I for Majors Final Exam Information
Algorithmic complexity: Speed of algorithms
CMSC201 Computer Science I for Majors Lecture 24 – Sorting
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Computer Networks CNT5106C
Algorithmic complexity
David Kauchak cs161 Summer 2009
Lecture 4: Introduction to Code Analysis
Core Assessments Core #1: This Friday (5/4) Core #2: Tuesday, 5/8.
Quicksort and selection
Last Class We Covered Sorting algorithms Searching algorithms
CMPT 120 Lecture 33 – Unit 5 – Internet and Big Data
CMPT 120 Lecture 26 – Unit 5 – Internet and Big Data
Presentation transcript:

CMSC201 Computer Science I for Majors Lecture 24 – Algorithmic Analysis

Last Class We Covered Sorting algorithms “Run” time Selection Sort Bubble Sort Quicksort “Run” time Why it’s important

Any Questions from Last Time?

Today’s Objectives To discuss “run time” of algorithms Why one algorithm is “better” than another To learn about asymptotic analysis What it is Why it’s important How to calculate it

Alphabetizing a Bookshelf Video from https://www.youtube.com/watch?v=WaNLJf8xzC4

Review: Algorithm Run Time

Example: Sum of All Products Say we have a list, and we want to find the sum of everything in that list multiplied by everything else in that list So if the list is [1, 2, 3], we want to find the value of: 1*1 + 1*2 + 1*3 + 2*1 + 2*2 + 2*3 + 3*1 + 3*2 + 3*3 As an exercise, try writing this function! def sumOfAllProducts(myList):

Exercise Solution def sumOfAllProducts(myList): result = 0 for item in myList: for item2 in myList: result += item * item2 return result

Run Time for Sum of All Products How many multiplications does this have to do for a list of 3 things? For 3 things, it does 9 multiplications 8 things? For 8 things, it does 64 multiplications 16 things? For 16 things, it does 256 multiplications In general, if you give it a list of size N, you’ll have to do N2 multiplications!

Run Time for Search If I am looking through a list of N items… How long does linear search take? N How long does binary search take? lg(N)

Different Run Times As our list gets bigger and bigger, which of the search algorithms is faster? Linear or binary search? How much faster is binary search? A lot! But exactly how much is “a lot”?

Asymptotic Analysis

What is “Big O” Notation? Big O notation is a concept in Computer Science Used to describe the complexity (or performance) of an algorithm Big O describes the worst-case scenario Big Omega (Ω) describes the best-case Big Theta (Θ) is used when the best and worst case scenarios are the same

Asymptotic Analysis For a list of size N, linear search does N operations. So we say it is O(N) (pronounced “big Oh of n”) For a list of size N, binary search does lg(N) operations, so we say it is O(lg(N)) For a list of size N, our sum of products function does N2 operations, which means it is O(N2) The function inside the O() parentheses indicates how fast the algorithm scales

Example What is the big O of the following, given a list of size N: for i in myList: for j in myList: for k in myList: print(i*j*k) This will be O(N3)

Worst-case vs Best-case Why differentiate between the two? Think back to selection sort What is the best case for run time? What is the worst case for run time? They’re the same! Always have to find each minimum by looking through the entire list every time – Θ(N2)

Worst-case vs Best-case What about bubble sort? What is the best case for run time? What is the worst case for run time? Very different! Best case, everything is already sorted – Ω( N ) Worst case, it’s completely backwards – O( N2 )

Worst-case vs Best-case This is why, even though selection sort and bubble sort have the same run times, bubble sort often runs much faster How does this apply to linear search and binary search? What are the best and worst run times for these?

Search Run Times Linear search: Binary search: Best case: Ω( 1 ) Worst case: O( N ) Binary search: Worst case: O( lg(N) )

Why Care?

Why Care?

Why Care?

Why Care? 19,311,800

Why Care? 337,407,000,000,000,000

Why Care? For large problems, there’s a huge difference! If we can do 1,000,000 operations per second, and the list is 337.4 quadrillion items Binary search takes 0.000058 seconds Linear search takes 337,407,000,000 seconds 5,623,450,000 minutes 93,724,166 hours 3,905,173 days 10,699 years

Thursday, December 15th (3:30 – 5:30) Announcements Final is when? Review worksheet will be released online on Friday, so you can start working on it over the weekend Project 2 out now Due on Tuesday, December 13th Survey #3 also out – follow link in announcement Now we’ll talk about SEEQs Thursday, December 15th (3:30 – 5:30)

SEEQs

The Student Evaluation of Educational Quality (SEEQ) is a standardized course evaluation instrument used to provide measures of an instructor’s teaching effectiveness. The results of this questionnaire will be used by promotion and tenure committees as part of the instructor’s evaluation. The Direct Instructor Feedback Forms (DIFFs) were designed to provide feedback to instructors and they are not intended for use by promotion and tenure committees. The responses to the SEEQ and the DIFFs will be kept confidential and will not be distributed until final grades are in.

Completing SEEQs Please take the time now, if you haven’t already, to complete the SEEQ online You can access it via the link in your email, or via Blackboard This is the part  I will get to see