45
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

Announcements

  • Upload
    tait

  • View
    28

  • Download
    0

Embed Size (px)

DESCRIPTION

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 - PowerPoint PPT Presentation

Citation preview

Page 1: Announcements

AnnouncementsCourse evaluation

Your opinion matters!Attendance grades

Will be posted prior to the finalProject 5 grades

Will be posted prior to the finalOne day extension for Project 5, now due Dec 8th

at 11:59pm

Page 2: Announcements

Final35 Questions Multiple ChoiceSame format as midtermsDo not be surprised to find questions similar to

the most frequently missed questions on your two midterms

Page 3: Announcements

Final – unique questions3 questions complexity3 questions recursion2 questions search2 questions sorting

Page 4: Announcements

Final – some questions may combine multiple

topics!2 questions functions/returns2 questions matrices2 questions dictionaries2 questions I/O files2 questions string manipulation2 questions trees2 questions loops2 questions conditionals2 question binary

Page 5: Announcements

Other Stuff that will (or may) appear

Auxiliary functions and operators: len, range, ord, chr, %, [ : ], not, or, and

Useful string and list manipulation functionsstrip, split, rfind, find, append, etc.

Python short handelif, a,b = b,a, +=

Page 6: Announcements

Other Stuff that will (or may) appear

Modulesrandom

True and FalseWhat values are consider to be True and what

values are considered to be False

Page 7: Announcements

Do a self assessment2 practice midterms2 midtermsFinal Practice questionsRead through solutions to project 1-4

Is there code you do not understand?Read through lab solutions

Is there code you do not understand?

Page 8: Announcements

Key things to go overRecursion examples – recitation + lecture slidesKnow the complexity of your searching and

sorting algorithms (memorize!)You do NOT need to memorize the code for the

algorithms themselvesYou should know the intuition behind why they

workKnow the complexity classes (least complex to

most complex) (memorize!)

Page 9: Announcements

Key things to go overBe able to identify the growth term

(hint: think about the relation to complexity classes)

Example code in prelabs!Review slides from both midtermsReview slides for the final

Page 10: Announcements

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 itNaming of loops:

Sentinel, Interactive, File, Nested You just need to know what the loop is doing, not what it is

calledLab 15 solutionOS Module, urllib ModuleGraphics library

Page 11: Announcements

What should you know about bucket sort?

Consider a special (simpler) case of bucket sortAssume we know something about the list of

numbers we are sortingAll numbers are integersWe know the maximum numberWe know the minimum number

Page 12: Announcements

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 sortPlace integer in corresponding bucketNote: 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 bucketsWhat is the complexity of this?

Page 13: Announcements

Complexity of Bucket SortOne 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)

Page 14: Announcements

What does this code do?

def myFun(myList): n = len(myList) i = 1 while ( i<n):

myList[i] = i i = i*2

return myList

Page 15: Announcements

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]

Page 16: Announcements

What is the complexity?

A: O(n) B: O(n2)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 problemlike this on the final

Page 17: Announcements

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

Page 18: Announcements

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

Page 19: Announcements

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 kA: O(n)

B: O(n2)C: O(1)D: O(log n) NOTE: you will NOT need to be able to do a problem

like this on the final

Page 20: Announcements

How to think about recursion

First identify the terminating conditionThen think about the problem in terms of a

supply chainWhat is each entity in the supply chain doing?

Try tracing on a small input

Page 21: Announcements

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

Page 22: Announcements

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

Page 23: Announcements

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

Page 24: Announcements

Tracing the mystery function

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

Page 25: Announcements

What if we had this function?

def mystery(x): if x == 0: return 0 else: return x - mystery(x-1)

Page 26: Announcements

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>>>

Page 27: Announcements

Fun things to do with Python

Build video gameshttp://pygame.org/news.htmlhttp://rene.f0o.com/mywiki/

PythonGameProgramming

Page 28: Announcements

Lego MindstormsProgram your robots with Python

http://code.google.com/p/nxt-python/

Page 29: Announcements

Professional Python UseBio Informatics

http://shop.oreilly.com/product/9780596154516.doNumpy / Scipy

http://numpy.scipy.org/

Page 30: Announcements

Final35 Questions Multiple ChoiceSame format as midtermsDo not be surprised to find questions similar to

the most frequently missed questions on your two midterms

Page 31: Announcements

Book ChaptersChapters 4-8Chapters 11 and 13

Page 32: Announcements

Identify the term that has the largest growth rate

Num of steps growth term complexity6n + 3 6n O(n)2n2 + 6n + 3 2n2 O(n2)2n3 + 6n + 3 2n3 O(n3)2n10 + 2n + 3 2n O(2n)n! + 2n10 + 2n + 3 n! O(n!)

Page 33: Announcements

Comparison of complexities:

fastest to slowestO(1) – constant timeO(log n) – logarithmic timeO(n) – linear timeO(n log n) – log linear timeO(n2) – quadratic timeO(2n) – exponential timeO(n!) – factorial time

Page 34: Announcements

SearchingLinear Search

Complexity O(n)Why: scan each element

Binary SearchComplexity O(log n)Why: break list into two pieces, discard one piece

Page 35: Announcements

SortingBubble 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 swapsMerge 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

Page 36: Announcements

SortingSimplified bucket sort:

Complexity O(n)Why: can each element and place it in a bucket,

then glue all buckets togetherAssumptions: 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)

Page 37: Announcements

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?

Page 38: Announcements

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?

Page 39: Announcements

What does this do?

def t4(c): x = {} for i in range(128): x[chr(i)] = i return x[c]

Page 40: Announcements

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]

Page 41: Announcements

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]

Page 42: Announcements

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 listIn the second example we looked at all pairs in

the list (similar to what you did / are doing in project 5)

Page 43: Announcements

Conditionals

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

Page 44: Announcements

Conditionalsdef 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

Page 45: Announcements

HomeworkStudy for the final