CS 10 Final Review Programming CS 10 Final
- Slides: 70
CS 10 Final Review Programming CS 10 Final Review by Glenn Sugden is licensed under a Creative Commons Attribution-Non. Commercial-Share. Alike 3. 0 Unported License. 1
Concept Review • • • Loops & Variables • • Conditionals Lists Algorithms & Complexity Concurrency 2 Recursion Data Structures Hash Tables Lamdas & HOFs
Loops & Variables Multiplying operand 1 by operand 2 Correct? 3
Loops & Variables Multiplying operand 1 by operand 2 No! Why? 4
Loops & Variables Multiplying operand 1 by operand 2 Uninitialized Variable 5
Loops & Variables Multiplying operand 1 by operand 2 Initialized Variable! 6
Loops & Variables Be sure that your variables are initialized to a correct / known / sane value! 7
Loops & Variables Multiplying operand 1 by operand 2 Correct now? 8
Loops & Variables Multiplying operand 1 by operand 2 What if operand 1 is negative? Or a “real” number like 2. 3? 9
Loops & Variables Be sure that your looping conditions are valid! 10
Conditionals Reports “+” for positive numbers, “-” for negative numbers. Correct? 11
Conditionals Reports “+” for positive numbers, “-” for negative numbers. No! Why? 12
Conditionals Reports “+” for positive numbers, “-” for negative numbers. What about number = 0? 13
Conditionals Loops & Variables • Be sure that your conditionals handle all possible cases! • Double-check edge cases, or inputs that fall on either side of your predicate. 14
Lists Duplicate words beginning with ‘c’ Does this correctly loop over list? 15
Lists Duplicate words beginning with ‘c’ No! Why? 16
Lists Duplicate words beginning with ‘c’ Index within conditional! 17
Lists Duplicate words beginning with ‘c’ Correct now? 18
Lists Duplicate words beginning with ‘c’ No! Why? 19
Lists Duplicate words beginning with ‘c’ Off by 1! 20
Lists Duplicate words beginning with ‘c’ Correct now? 21
Lists Duplicate words beginning with ‘c’ No! Why? 22
Lists Duplicate words beginning with ‘c’ The list keeps changing size! 23
Lists Duplicate words beginning with ‘c’ The list keeps changing size! 24
Lists How do you correct it? Here is one solution. . . 25
Lists Duplicate words beginning with ‘c’ Push the index past the inserted 26
Lists Seems pretty “kludgy” though. . . Here is a much, much better solution. . . 27 http: //en. wikipedia. org/wiki/Kludge
Lists Duplicate words beginning with ‘c’ Make a new, resulting list! 28
Lists Duplicate words beginning with ‘c’ Much better! And our original list is still intact! 29
Check-Lists • Be sure indexes are correct during the entire loop. • BYOB starts list indexing at 1 • If the input list changes size during the loop, your index will be off! 30
Algorithms & Complexity Order of growth? 31
Algorithms & Complexity Constant: O(c) Reason: No matter what “n” is, the loop always repeats 1000 times. 32
Algorithms & Complexity Order of growth? 33
Algorithms & Complexity Still Constant: O(c) Reason: No matter what the list is, the loop always repeats 1000 times. 34
Algorithms & Complexity Order of growth? 35
Algorithms & Complexity Linear: O(n) Reason: Number of operations proportional to the input size (n) 36
Algorithms & Complexity Order of growth? 37
Algorithms & Complexity Still Linear: O(n) Reason: Number of operations proportional to the input size (length) 38
Algorithms & Complexity Order of growth? 39
Algorithms & Complexity Quadratic: 2 O(n ) Reason: Number of operations proportional to the square of the size of the input data (n) 40
Algorithms & Complexity # of operations Input size Quadratic: O(n 2) 41
Algorithms & Complexity Order of growth? 42
Algorithms & Complexity Still Quadratic: O(n 2) Reason: Number of operations proportional to the square of the size of the input data (length) 43
Algorithms & Complexity Order of growth? 44
Algorithms & Complexity Exponential: O(cn) Reason: the recursive call is run twice for each value of n. 45
Algorithms & Complexity # of operations Input size Exponential: O(2 n) 46
Algorithms & Complexity Order of growth? 47
Algorithms & Complexity Logarithmic: O(Logcn) Reason: the number of times the loop runs grows far more slowly (square root) than 48 “n”
Algorithms & Complexity Note that these have traded places! Input size # of operations Logarithmic: O(Log 2 n) 49
Algorithms & Complexity 2 Compare! 2 50 Note that linear growth doesn’t even register on this graph!
Algorithms & Complexity Consider the number of times the calculation repeats, rather than specific inputs. 51
Algorithms & Complexity Examples Constant Hash Table Lookup Linear Text or List Length Quadratic Square Matrix Calcs. Exponential Recursive Fractals Logarithmic Binary Searches (Naïve) Sorting 52
Concurrency List adds up to 200? 53
Concurrency List adds up to 200? No! 54
Concurrency These might choose the same number at the same time! List adds up to 200? No! 55
Concurrency List adds up to 200? Anything 56
Concurrency List adds up to 200? No! 57 No “wait” here means these might access the same indexes (or not access them at all), by interrupting a broadcast script that is already running!
Recursion n=0 n=1 58
Recursion n=2 n=4 n=3 n=∞ 59
Recursion n=2 n=4 n=3 n=∞ 60
Recursion An algorithmic technique where a function, in order to accomplish a task, calls itself with some part of the task. • Recursive solutions involve two major parts: • Base case(s), in which the problem is simple enough to be solved directly, 1. Recursive case(s). A recursive case has three components: 1. Divide the problem into one or more simpler or smaller parts of the problems, 2. Invoke the function (recursively) on each part, and 3. Combine the solutions of the parts into a solution for the problem. • Depending on the problem, any of these may be trivial or complex. http: //inst. eecs/~cs 3 l/sp 09/lectures/L 06/2009 Sp. CS 3 L 06. htm 61
Data Structure : Hash Tables Can we use “Map. Reduce” to build a hash table? (we’ll come back to that. . . ) 62
Lambdas & HOFs • What is a Lambda? • What is a Higher. Order Function (HOF)? 63
Lambdas & HOFs • A “First Class” Procedure • “Function as Data” 64
Lambdas & HOFs • What is a Higher-Order Function (HOF)? • In mathematics and computer science, higher-order functions, functional forms, or functionals are functions which do at least one of the following: ■ take one or more functions as an input ■ output a function http: //en. wikipedia. org/wiki/Higher-order_function 65
Lambdas & HOFs § Useful HOFs (you can build your own!) ú map Reporter over List Report a new list, every element E of List becoming Reporter(E) ú keep items such that Predicate from List Report a new list, keeping only elements E of List if Predicate(E) ú combine with Reporter over List Combine all the elements of List with Reporter(E) This is also known as “reduce” § Acronym example ú keep map combine http: //inst. eecs. berkeley. edu/~cs 10/sp 11/lec/17/src/2011 -03 -30 -CS 10 -L 17 -DGHOF-I. pptx 66
Data Structure : Hash Tables 67
Data Structure : Hash Tables • Determine size of hash table. • Hashing function (algorithm) to generate keys (index) from values (items). • Modulo key (index) by hash table size. • Store key and value in hash table at the resulting index. • Find key in table using above algorithms (reading value instead of storing it). 68 http: //en. wikipedia. org/wiki/Hash_table
Data Structure : HOF/Hash Tables Can we use “Map. Reduce” to build a hash table? 69
Data Structure : HOF/Hash Tables Yes! • Try to program one on your own. . . it’s great practice with HOFs, Lists, etc. ! • I will post the solution to Piazzza. . . 70
- Writ of certiorari ap gov example
- Perbedaan linear programming dan integer programming
- Greedy algorithm vs dynamic programming
- System programming
- Linear vs integer programming
- Definisi linear
- Fundamentals of patrolling
- Cs 1101 final
- Cs 1101 programming fundamentals final exam
- World history spring final exam review answers
- World history final exam study guide
- Spanish 1 review packet answer key
- Pltw human body systems final exam review
- Poe practice test kinematics answers
- Ied final exam review
- World history semester 2 final review packet
- World history b semester exam review practice
- Principles of business final exam answer key
- Spanish 2 final exam review answer key
- Environmental science final
- Ap world history final exam
- American history semester 2 final exam
- Algebra 1 semester 2 final review
- Geometry final review
- English 11 semester exam
- Physics 20 final exam practice
- Hft 2401
- Fe exam statics
- Giles the crucible
- Physical science final exam study guide
- Mat1033c
- Zoology semester 1 exam review answers
- Lna
- World history semester 1 final exam study guide answers
- Earth science sol review
- Apes semester 1 final review
- World history semester 1 final exam study guide answers
- Spanish 2a final exam answers
- Personal finance final exam review
- Antigone open-ended questions
- Psychology final exam review
- Chapter review motion part a vocabulary review answer key
- Narrative review vs systematic review
- Inclusion criteria examples
- Narrative review vs systematic review
- Scratch
- Dts garage motor
- Dts gate motor 4 beeps
- Dts remote programming
- Vba object oriented
- Virtualization reference model
- Ruby unit testing
- Assembly language programming
- Computational thinking algorithms and programming
- Pic18 assembly language
- Tiny gals
- Cern programming language
- Extreme programming model
- Beta programming language
- Baud rate in 8051
- Microcontroller assembly language programming
- 2018 virginia tech high school programming contest
- Virginia tech high school programming contest
- 뮤텍스 세마포어
- Tcp echo server and client in network programming
- Declarative statement in assembly language
- Suggestive programming
- Stochastic programming
- Generic programming and the stl
- Simplex method
- Value result arguments in network programming