CS10 Final Review by Glenn Sugden is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.Glenn Sugdenmons Attribution-NonCommercial-ShareAlike.

Slides:



Advertisements
Similar presentations
Hash Tables CS 310 – Professor Roch Weiss Chapter 20 All figures marked with a chapter and section number are copyrighted © 2006 by Pearson Addison-Wesley.
Advertisements

Introduction to Algorithms Quicksort
CS Section 600 CS Section 002 Dr. Angela Guercio Spring 2010.
1 Divide & Conquer Algorithms. 2 Recursion Review A function that calls itself either directly or indirectly through another function Recursive solutions.
CS Section 600 CS Section 002 Dr. Angela Guercio Spring 2010.
CS 206 Introduction to Computer Science II 09 / 10 / 2008 Instructor: Michael Eckmann.
CSE115/ENGR160 Discrete Mathematics 03/03/11 Ming-Hsuan Yang UC Merced 1.
Recursion. Objectives At the conclusion of this lesson, students should be able to Explain what recursion is Design and write functions that use recursion.
Cmpt-225 Algorithm Efficiency.
CS 206 Introduction to Computer Science II 09 / 05 / 2008 Instructor: Michael Eckmann.
Unit 11a 1 Unit 11: Data Structures & Complexity H We discuss in this unit Graphs and trees Binary search trees Hashing functions Recursive sorting: quicksort,
CS 206 Introduction to Computer Science II 01 / 28 / 2009 Instructor: Michael Eckmann.
CS2336: Computer Science II
 2006 Pearson Education, Inc. All rights reserved Searching and Sorting.
LIAL HORNSBY SCHNEIDER
Recursion.
LIAL HORNSBY SCHNEIDER
Abstract Data Types (ADTs) Data Structures The Java Collections API
Data Structures Introduction Phil Tayco Slide version 1.0 Jan 26, 2015.
February 17, 2015Applied Discrete Mathematics Week 3: Algorithms 1 Double Summations Table 2 in 4 th Edition: Section th Edition: Section th.
Mathematics of Cryptography Part I: Modular Arithmetic, Congruence,
Comp 249 Programming Methodology Chapter 15 Linked Data Structure - Part B Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia.
TH EDITION Copyright © 2013, 2009, 2005 Pearson Education, Inc. 1 1 Equations and Inequalities Copyright © 2013, 2009, 2005 Pearson Education,
1 Chapter 24 Developing Efficient Algorithms. 2 Executing Time Suppose two algorithms perform the same task such as search (linear search vs. binary search)
(c) University of Washington20d-1 CSC 143 Java Applications of Trees.
Stochastic Algorithms Some of the fastest known algorithms for certain tasks rely on chance Stochastic/Randomized Algorithms Two common variations – Monte.
CS212: DATA STRUCTURES Lecture 10:Hashing 1. Outline 2  Map Abstract Data type  Map Abstract Data type methods  What is hash  Hash tables  Bucket.
Analysis of Algorithms
 2005 Pearson Education, Inc. All rights reserved Searching and Sorting.
 Pearson Education, Inc. All rights reserved Searching and Sorting.
Ch 18 – Big-O Notation: Sorting & Searching Efficiencies Our interest in the efficiency of an algorithm is based on solving problems of large size. If.
Arrays Tonga Institute of Higher Education. Introduction An array is a data structure Definitions  Cell/Element – A box in which you can enter a piece.
Unsolvability and Infeasibility. Computability (Solvable) A problem is computable if it is possible to write a computer program to solve it. Can all problems.
Copyright © Cengage Learning. All rights reserved. 4 Quadratic Functions.
CSC 211 Data Structures Lecture 13
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.
Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy Walters, and Godfrey Muganda Modified for use by MSU Dept. of Computer Science.
Chapter 10 Hashing. The search time of each algorithm depend on the number n of elements of the collection S of the data. A searching technique called.
Java Methods Big-O Analysis of Algorithms Object-Oriented Programming
3.3 Complexity of Algorithms
1 Algorithms  Algorithms are simply a list of steps required to solve some particular problem  They are designed as abstractions of processes carried.
1 CSCD 326 Data Structures I Hashing. 2 Hashing Background Goal: provide a constant time complexity method of searching for stored data The best traditional.
Fall 2008Programming Development Techniques 1 Topic 17 Assignment, Local State, and the Environment Model of Evaluation Section 3.1 & 3.2.
Copyright © Curt Hill Sorting Ordering an array.
2IS80 Fundamentals of Informatics Fall 2015 Lecture 6: Sorting and Searching.
Searching Topics Sequential Search Binary Search.
1 Ch. 2: Getting Started. 2 About this lecture Study a few simple algorithms for sorting – Insertion Sort – Selection Sort (Exercise) – Merge Sort Show.
A Introduction to Computing II Lecture 5: Complexity of Algorithms Fall Session 2000.
CSC317 1 So far so good, but can we do better? Yes, cheaper by halves... orkbook/cheaperbyhalf.html.
Search Algorithms Written by J.J. Shepherd. Sequential Search Examines each element one at a time until the item searched for is found or not found Simplest.
Hash Tables Ellen Walker CPSC 201 Data Structures Hiram College.
Big O David Kauchak cs302 Spring Administrative Assignment 1: how’d it go? Assignment 2: out soon… Lab code.
Recursion. Objectives At the conclusion of this lesson, students should be able to Explain what recursion is Design and write functions that use recursion.
Algorithm Analysis 1.
16 Searching and Sorting.
Sorting and "Big Oh" ASFA AP Computer Science A SortingBigOh.
Searching – Linear and Binary Searches
Unit 1. Sorting and Divide and Conquer
CS 3343: Analysis of Algorithms
Algorithm An algorithm is a finite set of steps required to solve a problem. An algorithm must have following properties: Input: An algorithm must have.
ITEC 2620M Introduction to Data Structures
Big O Notation.
Data Structures Review Session
CS 201 Fundamental Structures of Computer Science
Applied Discrete Mathematics Week 6: Computation
Topic 1: Problem Solving
Copyright © 2017, 2013, 2009 Pearson Education, Inc.
CSE 2010: Algorithms and Data Structures Algorithms
David Kauchak cs161 Summer 2009
Presentation transcript:

CS10 Final Review by Glenn Sugden is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.Glenn Sugdenmons Attribution-NonCommercial-ShareAlike 3.0 Unported License. 1 CS10 Final Review Programming

2 Concept Review Loops & Variables Conditionals Lists Algorithms & Complexity Concurrency Recursion Data Structures Hash Tables Lamdas & HOFs

3 Loops & Variables Correct? Multiplying operand1 by operand2

4 Loops & Variables No! Why? Multiplying operand1 by operand2

5 Loops & Variables Uninitialized Variable Multiplying operand1 by operand2

6 Loops & Variables Initialized Variable! Multiplying operand1 by operand2

7 Loops & Variables Be sure that your variables are initialized to a correct / known / sane value!

8 Loops & Variables Correct now? Multiplying operand1 by operand2

9 Loops & Variables What if operand1 is negative? Or a “real” number like 2.3? Multiplying operand1 by operand2

10 Loops & Variables Be sure that your looping conditions are valid!

11 Reports “+” for positive numbers, “-” for negative numbers. Correct? Conditionals

12 Reports “+” for positive numbers, “-” for negative numbers. No! Why? Conditionals

13 Conditionals Reports “+” for positive numbers, “-” for negative numbers. What about number = 0?

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

15 Lists Duplicate words beginning with ‘c’ Does this correctly loop over list?

16 Lists No! Why? Duplicate words beginning with ‘c’

17 Lists Index within conditional! Duplicate words beginning with ‘c’

18 Duplicate words beginning with ‘c’ Lists Correct now?

19 Lists No! Why? Duplicate words beginning with ‘c’

20 Lists Off by 1 ! Duplicate words beginning with ‘c’

21 Lists Correct now? Duplicate words beginning with ‘c’

22 Lists No! Why? Duplicate words beginning with ‘c’

23 Duplicate words beginning with ‘c’ Lists The list keeps changing size!

24 Lists The list keeps changing size! Duplicate words beginning with ‘c’

25 Lists How do you correct it? Here is one solution...

26 Duplicate words beginning with ‘c’ Lists Push the index past the inserted item...

27 Lists Seems pretty “kludgy” though... Here is a much, much better solution...

28 Duplicate words beginning with ‘c’ Lists Make a new, resulting list!

29 Lists Much better! And our original list is still intact! Duplicate words beginning with ‘c’

30 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! Check-Lists

31 Algorithms & Complexity Order of growth?

32 Constant: O(c) Reason: No matter what “n” is, the loop always repeats 1000 times. Algorithms & Complexity

33 Algorithms & Complexity Order of growth?

34 Still Constant: O(c) Reason: No matter what the list is, the loop always repeats 1000 times. Algorithms & Complexity

35 Algorithms & Complexity Order of growth?

36 Linear: O(n) Reason: Number of operations proportional to the input size (n) Algorithms & Complexity

37 Algorithms & Complexity Order of growth?

38 Still Linear: O(n) Reason: Number of operations proportional to the input size (length) Algorithms & Complexity

39 Algorithms & Complexity Order of growth?

40 Reason: Number of operations proportional to the square of the size of the input data (n) Algorithms & Complexity Quadratic: O(n 2 )

41 Algorithms & Complexity Quadratic: O(n 2 ) Input size # of operations

42 Algorithms & Complexity Order of growth?

43 Algorithms & Complexity Still Quadratic: O(n 2 ) Reason: Number of operations proportional to the square of the size of the input data (length)

44 Algorithms & Complexity Order of growth?

45 Algorithms & Complexity Reason: the recursive call is run twice for each value of n. Exponential: O(c n )

46 Algorithms & Complexity Exponential: O(2 n ) Input size # of operations

47 Algorithms & Complexity Order of growth?

48 Algorithms & Complexity Reason: the number of times the loop runs grows far more slowly (square root) than “n” Logarithmic: O(Log c n)

49 # of operations Algorithms & Complexity 2 Input size Note that these have traded places! Logarithmic: O(Log n)

50 Algorithms & Complexity 2 2 Compare! Note that linear growth doesn’t even register on this graph!

51 Consider the number of times the calculation repeats, rather than specific inputs. Algorithms & Complexity

52 Algorithms & Complexity Examples Constant Linear Quadratic Exponential Logarithmic Hash Table Lookup Text or List Length Square Matrix Calcs. (Naïve) Sorting Recursive Fractals Binary Searches

53 Concurrency List adds up to 200? 53

54 Concurrency List adds up to 200? No! Why? 54

55 Concurrency List adds up to 200? No! Why? These might choose the same number at the same time! 55

56 Concurrency List adds up to 200? Anything else? 56

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! Concurrency List adds up to 200? No! Why? 57

58 Recursion n=0 n=1

59 n=4 n=∞ n=2 n=3 Recursion

60 n=4 n=∞ n=2 n=3 Recursion

61 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: 1.Base case(s), in which the problem is simple enough to be solved directly, 2.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.

62 Data Structure : Hash Tables Can we use “MapReduce” to build a hash table? (we’ll come back to that...)

63 Lambdas & HOFs What is a Lambda? What is a Higher- Order Function (HOF)?

64 Lambdas & HOFs A “First Class” Procedure “Function as Data”

65 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:mathematicscomputer sciencefunctionalsfunctions ■ take one or more functions as an input ■ output a function

66 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 HOF-I.pptx

67 Data Structure : Hash Tables

68 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).

69 Data Structure : HOF/Hash Tables Can we use “MapReduce” to build a hash table?

70 Try to program one on your own... it’s great practice with HOFs, Lists, etc.! I will post the solution to Piazzza... Yes! Data Structure : HOF/Hash Tables