Announcements Course evaluation Your opinion matters! Attendance grades Will be posted prior to the final Project 5 grades Will be posted prior to the.

Slides:



Advertisements
Similar presentations
Algorithm Analysis Input size Time I1 T1 I2 T2 …
Advertisements

Garfield AP Computer Science
Recursion Genome 559: Introduction to Statistical and Computational Genomics Elhanan Borenstein.
CSE Lecture 3 – Algorithms I
Analysis of Algorithms
A simple example finding the maximum of a set S of n numbers.
Fundamentals of Python: From First Programs Through Data Structures
© The McGraw-Hill Companies, Inc., Chapter 2 The Complexity of Algorithms and the Lower Bounds of Problems.
CSCE 3110 Data Structures & Algorithm Analysis
Announcements Midterm next week! No class next Friday Review this Friday.
Scott Grissom, copyright 2004 Chapter 5 Slide 1 Analysis of Algorithms (Ch 5) Chapter 5 focuses on: algorithm analysis searching algorithms sorting algorithms.
2 -1 Chapter 2 The Complexity of Algorithms and the Lower Bounds of Problems.
1 CS 177 Week 15 Recitation Slides Review. Announcements Final Exam on Sat. May 8th  PHY 112 from 8-10 AM Complete your online review of your classes.
1 Algorithm Efficiency, Big O Notation, and Role of Data Structures/ADTs Algorithm Efficiency Big O Notation Role of Data Structures Abstract Data Types.
Mergesort and Quicksort Chapter 8 Kruse and Ryba.
Abstract Data Types (ADTs) Data Structures The Java Collections API
Week 2 CS 361: Advanced Data Structures and Algorithms
Design and Analysis of Algorithms - Chapter 21 Analysis of Algorithms b Issues: CorrectnessCorrectness Time efficiencyTime efficiency Space efficiencySpace.
Analysis of Algorithms
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 19: Searching and Sorting.
Analysis of Algorithms These slides are a modified version of the slides used by Prof. Eltabakh in his offering of CS2223 in D term 2013.
CS 61B Data Structures and Programming Methodology July 28, 2008 David Sun.
1 Lecture 5 Generic Types and Big O. 2 Generic Data Types A generic data type is a type for which the operations are defined but the types of the items.
SortingBigOh ASFA AP Computer Science A. Big-O refers to the order of an algorithm runtime growth in relation to the number of items I. O(l) - constant.
Survey of Sorting Ananda Gunawardena. Naïve sorting algorithms Bubble sort: scan for flips, until all are fixed Etc...
Data Structure Introduction.
Hossain Shahriar Announcement and reminder! Final exam date December 19: 4pm-6pm Topics to be covered in this lecture Sort.
Java Methods Big-O Analysis of Algorithms Object-Oriented Programming
Sorting: Implementation Fundamental Data Structures and Algorithms Klaus Sutner February 24, 2004.
Announcements: Project 5 Everything we have been learning thus far will enable us to solve interesting problems Project 5 will focus on applying the skills.
Computer Science 101 Fast Algorithms. What Is Really Fast? n O(log 2 n) O(n) O(n 2 )O(2 n )
Quick sort, lower bound on sorting, bucket sort, radix sort, comparison of algorithms, code, … Sorting: part 2.
Midterm Review Important control structures Functions Loops Conditionals Important things to review Binary Boolean operators (and, or, not) Libraries (import.
COMP108 Algorithmic Foundations Polynomial & Exponential Algorithms
1 CS 177 Week 6 Recitation Slides Review for Midterm Exam.
Selection Sort main( ) { int a[ ] = { 17, 6, 13,12, 2 } ; int i, j, t ; for ( i = 0 ; i
Searching Topics Sequential Search Binary Search.
Sorting & Searching Geletaw S (MSC, MCITP). Objectives At the end of this session the students should be able to: – Design and implement the following.
INTRO2CS Tirgul 8 1. Searching and Sorting  Tips for debugging  Binary search  Sorting algorithms:  Bogo sort  Bubble sort  Quick sort and maybe.
1 CS Review, iClicker -Questions Week 15. Announcements 2.
Advanced Sorting 7 2  9 4   2   4   7
Chapter 11 Sorting Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich, Tamassia and Mount.
Design and Analysis of Algorithms
Sorting and "Big Oh" ASFA AP Computer Science A SortingBigOh.
Growth of Functions & Algorithms
CSCI 104 Sorting Algorithms
Algorithmic complexity: Speed of algorithms
COMP108 Algorithmic Foundations Polynomial & Exponential Algorithms
Algorithm Analysis The case of recursion.
Recitation 13 Searching and Sorting.
COMP 53 – Week Seven Big O Sorting.
CMSC201 Computer Science I for Majors Lecture 27 – Final Exam Review
Teach A level Computing: Algorithms and Data Structures
Adapted from slides by Marty Stepp and Stuart Reges
Quick-Sort 11/14/2018 2:17 PM Chapter 4: Sorting    7 9
Big-Oh and Execution Time: A Review
Quick-Sort 11/19/ :46 AM Chapter 4: Sorting    7 9
CSc 110, Spring 2017 Lecture 39: searching.
Analysis of Bubble Sort and Loop Invariant
CSS 342 Data Structures, Algorithms, and Discrete Mathematics I
Algorithmic complexity: Speed of algorithms
Sub-Quadratic Sorting Algorithms
Quick-Sort 2/23/2019 1:48 AM Chapter 4: Sorting    7 9
Introduction to Data Structures
Quick-Sort 4/8/ :20 AM Quick-Sort     2 9  9
Algorithmic complexity: Speed of algorithms
CS203 Lecture 15.
Presentation transcript:

Announcements Course evaluation Your opinion matters! Attendance grades Will be posted prior to the final Project 5 grades Will be posted prior to the final One day extension for Project 5, now due Dec 8 th at 11:59pm

Final 35 Questions Multiple Choice Same format as midterms Do not be surprised to find questions similar to the most frequently missed questions on your two midterms

Final – unique questions 3 questions complexity 3 questions recursion 2 questions search 2 questions sorting

Final – some questions may combine multiple topics! 2 questions functions/returns 2 questions matrices 2 questions dictionaries 2 questions I/O files 2 questions string manipulation 2 questions trees 2 questions loops 2 questions conditionals 2 question binary

Other Stuff that will (or may) appear Auxiliary functions and operators: len, range, ord, chr, %, [ : ], not, or, and Useful string and list manipulation functions strip, split, rfind, find, append, etc. Python short hand elif, a,b = b,a, +=

Other Stuff that will (or may) appear Modules random True and False What values are consider to be True and what values are considered to be False

Do a self assessment 2 practice midterms 2 midterms Final Practice questions Read through solutions to project 1-4 Is there code you do not understand? Read through lab solutions Is there code you do not understand?

Key things to go over Recursion examples – recitation + lecture slides Know the complexity of your searching and sorting algorithms (memorize!) You do NOT need to memorize the code for the algorithms themselves You should know the intuition behind why they work Know the complexity classes (least complex to most complex) (memorize!)

Key things to go over Be able to identify the growth term (hint: think about the relation to complexity classes) Example code in prelabs! Review slides from both midterms Review slides for the final

Things you do NOT need to review Project 5 Solution It will be posted too close to the exam Chapter 9 and the recitation slides that go along with it Naming of loops: Sentinel, Interactive, File, Nested You just need to know what the loop is doing, not what it is called Lab 15 solution OS Module, urllib Module Graphics library

What should you know about bucket sort? Consider a special (simpler) case of bucket sort Assume we know something about the list of numbers we are sorting All numbers are integers We know the maximum number We know the minimum number

How should we sort such a list? Create one bucket for each integer including and between min and max Traverse the list we want to sort Place integer in corresponding bucket Note: we do not need to sort the buckets as each number in them is the same! What is the complexity of this? Afterwards combine all the buckets What is the complexity of this?

Complexity of Bucket Sort One final assumption: size of list that we want to sort > (max- min) How can we find the complexity? Traversing the list and placing an integer into a bucket is O(n) We do one “piece” of work for each item in the list Inserting into a list without worrying about order is O(1) Combining buckets is no more complex than O(n)

What does this code do? def myFun(myList): n = len(myList) i = 1 while ( i<n): myList[i] = i i = i*2 return myList

What does this code do? def myFun(myList): n = len(myList) i = 1 while ( i<n): myList[i] = i i = i*2 return myList >>> myFun([0]) [0] >>> myFun([0,0,0,0]) [0, 1, 2, 0] >>> myFun([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]) [0, 1, 2, 0, 4, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 16, 0]

What is the complexity? A: O(n) B: O(n 2 ) C: O(1) D: O(log n) def myFun(myList): n = len(myList) i = 1 while ( i<n): myList[i] = i i = i*2 return myList NOTE: you will NOT need to be able to do a problem like this on the final

What does this code do? def trickyReturns(list): k = 0 for w in range(len(list)): if(list[w] == 1001): return w else: k=k+1 return k

What does this code do? def trickyReturns(list): k = 0 for w in range(len(list)): if(list[w] == 1001): return w else: k=k+1 return k >>> trickyReturns([0,1,3,4,5]) 1 >>> trickyReturns([1001,1,3,4,5]) 0 >>> trickyReturns([0,1,1001,3,4,5]) 1

What is the complexity? def trickyReturns(list): k = 0 for w in range(len(list)): if(list[w] == 1001): return w else: k=k+1 return k A: O(n) B: O(n 2 ) C: O(1) D: O(log n) NOTE: you will NOT need to be able to do a problem like this on the final

How to think about recursion First identify the terminating condition Then think about the problem in terms of a supply chain What is each entity in the supply chain doing? Try tracing on a small input

What does this code do? def mystery(x): if x == 1: return 1 else: return x * mystery(x-1)

What does this do? def mystery(x): return x + mystery(x-1)

How do we fix it? def mystery(x): if x == 0: return 0 else: return x + mystery(x-1)

Tracing the mystery function mystery(5) 5 + (mystery(4)) 5 + (4 + (mystery(3))) 5 + (4 + (3 + (mystery(2)))) …. Why are the parenthesis important?

What if we had this function? def mystery(x): if x == 0: return 0 else: return x - mystery(x-1)

Tracing the mystery function mystery(5) 5 - (mystery(4)) 5 - (4 - (mystery(3))) 5 - (4 - (3 - (mystery(2)))) …. >>> mystery(3) 2 >>> mystery(4) 2 >>> mystery(5) 3 >>>

Fun things to do with Python Build video games

Lego Mindstorms Program your robots with Python

Professional Python Use Bio Informatics Numpy / Scipy

Final 35 Questions Multiple Choice Same format as midterms Do not be surprised to find questions similar to the most frequently missed questions on your two midterms

Book Chapters Chapters 4-8 Chapters 11 and 13

Identify the term that has the largest growth rate Num of steps growth term complexity 6n + 3 6n O(n) 2n 2 + 6n + 3 2n 2 O(n 2 ) 2n 3 + 6n + 3 2n 3 O(n 3 ) 2n n n O(2 n ) n! + 2n n + 3 n! O(n!)

Comparison of complexities: fastest to slowest O(1) – constant time O(log n) – logarithmic time O(n) – linear time O(n log n) – log linear time O(n 2 ) – quadratic time O(2 n ) – exponential time O(n!) – factorial time

Searching Linear Search Complexity O(n) Why: scan each element Binary Search Complexity O(log n) Why: break list into two pieces, discard one piece

Sorting Bubble sort Complexity O(n^2) Why: Inner loop compares every pair of elements in the list, there are n-1 pairs of elements Why: outer loop runs n times, the last time there will be no swaps Merge sort Complexity O(n log n) Why: there are log n “level” – ie it takes us log(n) splits to get to lists of length one Why: it takes us O(n) work to merge all lists on each level

Sorting Simplified bucket sort: Complexity O(n) Why: can each element and place it in a bucket, then glue all buckets together Assumptions: know the range of elements in the list, assume all elements are integers (finite distribution), distribution is dense (ie the number of elements in the list is equal to or greater than max-min) Observation: in the worst case we have one element per bucket, merging is still O(n)

What is the terminating condition? def mystery(x): if x == 1: return 1 else: return x * mystery(x-1) What if we call mystery with a negative number?

Now what is the terminating condition? def mystery(x): if x <=1: return 1 else: return x * mystery(x-1) What if we call mystery with a negative number?

What does this do? def t4(c): x = {} for i in range(128): x[chr(i)] = i return x[c]

What is the output of the following code? list = ['A',1,'B',2,'C',3,'D',4] myDict = {} for i in range(0,len(list),2): myDict[list[i]] = list[i+1 ]

What is the output of the following code? list = ['A',1,'B',2,'C',3,'D',4] myDict = {} for i in range(len(list)-1): myDict[list[i]] = list[i+1 ]

How can we characterize the difference between the two pieces of code? In the first example we looked at each non overlapping par in the list In the second example we looked at all pairs in the list (similar to what you did / are doing in project 5)

Conditionals def sel(mylist): for i in range(len(mylist)): if mylist[i] % 2: print(i)

Conditionals def t1(x,y,z): if x and y or z: x = y if x and not z: print("goal") else: x = z else: z = y

Homework Study for the final