CS 2420 Class Notes Week 3
CS 2420 Class Notes Week 3 CS 2420
Popular in Intro Algorithms and Data Structures
Popular in Computer science
This 4 page Class Notes was uploaded by Nick on Friday September 9, 2016. The Class Notes belongs to CS 2420 at University of Utah taught by Miriah Meyer in Fall 2016. Since its upload, it has received 9 views. For similar materials see Intro Algorithms and Data Structures in Computer science at University of Utah.
Reviews for CS 2420 Class Notes Week 3
Report this Material
What is Karma?
Karma is the currency of StudySoup.
You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!
Date Created: 09/09/16
CS 2420 9716 Complexity next assignment requires a partner due next wed TAs will not be able to help unless both you and your partner are together. have one week to ask for regrade. email TAs directly don’t leave comments in the assignment submissions need to include name in every assignment. name and UID at the top of every file. In the future need to add javadoc comments! no javadocs on tests get answers about code in person not on email. expect 515 hours per assignment if spent more than 20 hours, then this will be an especially hard class for you. generic programming generic placeholder type is very specific ArrayList<Shape> will treat a Triangle as a Shape. wildcard placeholder: ? < ? super Circle> <?> is so unspecific it is basically useless. Comparable interface Comparator interface Collection is a generic data structure that holds items. does not say how they are held. Iterator allows iterating (think for loop) through a data structure without a for loop. Algorithm analysis Correctness is only half the battle. in this class will expect programs to terminate ina certain amount ot time. this is determined by the choice of algorithm to find a word in a paper dictionary: algorithm 1: one at a time starting at the beginning. algorithm 2: go to middle word is this our word, if so done if not then if greater go to middle word of the greater half else go to middle word of lesser half 180K words algorithm1: 12 hours [linear] algorithm 2: 4 seconds [binary] Binary search: n# words searches 180k 1 90k 1 45k 1 … 75 1 36 1 … 4 1 2 1 1 1 total of 18 searches * .25 sec = 4 seconds 180000=~2^18 N=2^x x is number of searches needed to find the word. x=log2(N) log refresher: log B (N) = x B^x=N default base in this class is 2 9 < log 1000 < 10 T is the time for N 2*linear search = 2*T 2*binary search = T+1 Determine complexity of code: count number instructions assume one insruction is: assigning a value to a variable looking up the valueof a particular array element cmopareing 2 values incrementing a value basic arithmetic ops branching is instantaneous ex int max = array; has an instruction count of 2: assign and lookup int i=0; i<n each have one no matter what N is total of 4 every iteration: 2n i<n i++ body of loop: 2n array[i] > max max = array[i]; worst case: max number of work best case: minimum number of instructions: 4+2n+2n+2n #instructions = f(n)=6n+4 but time will vary by computer, language, compiler, available CPU but they are beyond our control asymptotic behavior just keep the fastest growing term. we will ignore constants, and coefficients (decorative constants) examples: f(n)=5n+12 → n f(n)=109 → 1=n^0 f(n)=n^2+3n+112 → n^2 f(n)=n^3+1999 → n^3 f(n)=n+n^(½) → n no loop has asymptotic behavior of 1 single loop from 1>n is n n^2 and n^3 are not acceptable in this class. log growth comes from iterations of 2*n or n/2 Big O notation used to capture runtime behavior assume large N O(N^2) = “order n squared” clever programming tricks cannot make an inefficient algorithm fast. so, optimizing the algorithm will do better than optimizing the code worst case average case the most useful best case usually don’t care
Are you sure you want to buy this material for
You're already Subscribed!
Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'