UCSD CSE 21, Spring 2014 [Section B00] Mathematics for Algorithm and System Analysis

Similar documents
Backtracking and Branch-and-Bound

Chapter-6 Backtracking

Discrete Mathematics and Probability Theory Fall 2013 Midterm #2

UCSD CSE 21, Spring 2014 [Section B00] Mathematics for Algorithm and System Analysis

Trees, Trees and More Trees

CS1800 Discrete Structures Fall 2016 Profs. Aslam, Gold, Ossowski, Pavlu, & Sprague December 16, CS1800 Discrete Structures Final

CS1800 Discrete Structures Fall 2016 Profs. Aslam, Gold, Ossowski, Pavlu, & Sprague December 16, CS1800 Discrete Structures Final

Discrete Mathematics Course Review 3

Coping with the Limitations of Algorithm Power Exact Solution Strategies Backtracking Backtracking : A Scenario

Backtracking is a refinement of the brute force approach, which systematically searches for a

COMP3121/3821/9101/ s1 Assignment 1

CPSC 320: Intermediate Algorithm Design and Analysis. Tutorial: Week 3

Applications. 72 Variables and Patterns

Notes slides from before lecture. CSE 21, Winter 2017, Section A00. Lecture 10 Notes. Class URL:

Extra Practice Problems 2

Practice Problems for the Final

CSC 8301 Design and Analysis of Algorithms: Exhaustive Search

Department of Computer Applications. MCA 312: Design and Analysis of Algorithms. [Part I : Medium Answer Type Questions] UNIT I

Lecture 14: General Problem-Solving Methods

Discrete Mathematics Exam File Fall Exam #1

Trees and Intro to Counting

CS 251, LE 2 Fall MIDTERM 2 Tuesday, November 1, 2016 Version 00 - KEY

Lecture 3. Brute Force

ICS 161 Algorithms Winter 1998 Final Exam. 1: out of 15. 2: out of 15. 3: out of 20. 4: out of 15. 5: out of 20. 6: out of 15.

CS 561, Lecture 1. Jared Saia University of New Mexico

Introduction to Computer Science

Midterm 2 Solutions. CS70 Discrete Mathematics and Probability Theory, Spring 2009

CSE 417 Branch & Bound (pt 4) Branch & Bound

Packet #6: Counting & Graph Theory. Applied Discrete Mathematics

More NP-complete Problems. CS255 Chris Pollett May 3, 2006.

PSD1A. DESIGN AND ANALYSIS OF ALGORITHMS Unit : I-V

Combinatorics: The Fine Art of Counting

Unit 1, Lesson 1: Moving in the Plane

Instructor: Paul Zeitz, University of San Francisco

CS 440 Theory of Algorithms /

Randomized Algorithms: Element Distinctness

Parallel and Sequential Data Structures and Algorithms Lecture (Spring 2012) Lecture 16 Treaps; Augmented BSTs

COMP251: Background. Jérôme Waldispühl School of Computer Science McGill University

CMSC Introduction to Algorithms Spring 2012 Lecture 16

CS 231: Algorithmic Problem Solving

CSE 100: B+ TREE, 2-3 TREE, NP- COMPLETNESS

MC 302 GRAPH THEORY 10/1/13 Solutions to HW #2 50 points + 6 XC points

Chapter 6 Backtracking Algorithms. Backtracking algorithms Branch-and-bound algorithms

Sankalchand Patel College of Engineering - Visnagar Department of Computer Engineering and Information Technology. Assignment

Math 55 - Spring Lecture notes # 14 - March 9 (Tuesday)

Exercise 1. D-ary Tree

Lecture 3: Recursion; Structural Induction

Ma/CS 6b Class 26: Art Galleries and Politicians

Backtracking. Chapter 5

1 Leaffix Scan, Rootfix Scan, Tree Size, and Depth

Design and Analysis of Algorithms

Elements of Graph Theory

COSC 2007 Data Structures II Final Exam. Part 1: multiple choice (1 mark each, total 30 marks, circle the correct answer)

CS 350 Final Algorithms and Complexity. It is recommended that you read through the exam before you begin. Answer all questions in the space provided.

CSE 20. Lecture 4: Number System and Boolean Function. CSE 20: Lecture2

Mathematics and Statistics, Part A: Graph Theory Problem Sheet 1, lectures 1-4

CSE 21 Summer 2017 Homework 4

Year 2 Spring Term Week 5 to 7 - Geometry: Properties of Shape

Chapter 4. Relations & Graphs. 4.1 Relations. Exercises For each of the relations specified below:

2.) From the set {A, B, C, D, E, F, G, H}, produce all of the four character combinations. Be sure that they are in lexicographic order.

Chapter 11: Graphs and Trees. March 23, 2008

Algorithm classification

1 5,9,2,7,6,10,4,3,8,1 The first number (5) is automatically the first number of the sorted list

UNIT 4 Branch and Bound

Steven Skiena. skiena

Figure 4.1: The evolution of a rooted tree.

CIS 121 Data Structures and Algorithms Midterm 3 Review Solution Sketches Fall 2018

Lower Bound on Comparison-based Sorting

Randomized Algorithms, Hash Functions

1. Read each problem carefully and follow the instructions.

Treaps. 1 Binary Search Trees (BSTs) CSE341T/CSE549T 11/05/2014. Lecture 19

Randomized Algorithms: Selection

CSCE 411 Design and Analysis of Algorithms

Angles of Polygons. Essential Question What is the sum of the measures of the interior angles of a polygon?

CS 373: Combinatorial Algorithms, Spring 1999

Lecture 21: Other Reductions Steven Skiena

Quiz 1 Solutions. (a) f(n) = n g(n) = log n Circle all that apply: f = O(g) f = Θ(g) f = Ω(g)

Final Examination CSE 100 UCSD (Practice)

CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators)

1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1

Copyright 2000, Kevin Wayne 1

Discrete Math: Selected Homework Problems

The problem: given N, find all solutions of queen sets and return either the number of solutions and/or the patterned boards.

Data Structures (CS 1520) Lecture 28 Name:

Dynamic Programming Homework Problems

Combinatorial Search. permutations backtracking counting subsets paths in a graph. Overview

Discrete Mathematics 2 Exam File Spring 2012

Notes for Lecture 24

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Sorting lower bound and Linear-time sorting Date: 9/19/17

Instructions. Definitions. Name: CMSC 341 Fall Question Points I. /12 II. /30 III. /10 IV. /12 V. /12 VI. /12 VII.

Math 574 Review Exam #1

The Probabilistic Method

Design and Analysis of Algorithms

Search and Optimization

Algorithms and Data Structures (INF1) Lecture 15/15 Hua Lu

CSE100 Practice Final Exam Section C Fall 2015: Dec 10 th, Problem Topic Points Possible Points Earned Grader

TILING PROBLEMS: FROM DOMINOES, CHECKERBOARDS, AND MAZES TO DISCRETE GEOMETRY

Sorting. There exist sorting algorithms which have shown to be more efficient in practice.

CSE 332 Spring 2014: Midterm Exam (closed book, closed notes, no calculators)

Assignment No 2 (Group B)

Transcription:

UCSD CSE 21, Spring 2014 [Section B00] Mathematics for Algorithm and System Analysis Lecture 11 Class URL: http://vlsicad.ucsd.edu/courses/cse21-s14/

Lecture 11 Notes Goals for this week (Tuesday) Linearity of expectation; Joint distributions (Today) Decision trees, hashing example, For quiz: MT solutions, mean/variance, Tuesday material Next week: conditional probability, Bayes rule; induction and recursion Please do your reading in BW Emails sent out to prompt 1-1, small-group tutor sessions. See also IDEA Center (TBP, HKN) tutoring If you didn t receive this email, and want a copy, please tell me! Possibly of interest ( life advice ): Four parts: Context, Research, Grad School, Life/Career http://vlsicad.ucsd.edu/courses/cse101-w14/slides/cse101-w14-gradschoolplus.pdf

Main Points From Last Time Expectation E(X) = k p k x k Variance X2 = E(X 2 ) (E(X)) 2 Linearity of Expectation: E(aX) = ae(x) E(aX + by) = ae(x) + be(y) r.v. s X, Y on same sample space indicator variable technique X j = 1 if letter j in correct envelope Joint distribution: h X,Y : Im(X) Im(Y) [0,1] h X,Y (i,j) = probability of ((X = i) AND (Y = j)) Independence: X and Y are independent r.v. s iff h X,Y (i,j) = f X (i) f Y (j) for all (i,j) Im(X) Im(Y) Info about one r.v. doesn t give info about the other E(X Y) = E(X) E(Y) only if X, Y independent

iclicker Quiz, Week 6 please don t do this Image courtesy ucsd snaps

iclicker Quiz, Week 6 Q1: The number of integer solutions to x 1 +x 2 +x 3 +x 4 = 15, with x 2 2 and x 4 3, is: A: C(18,3) B: C(18,3) C(15,3) C(14,3) C: C(19,4) C(16,4) C(15,4) D: C(18,3) C(15,3) C(14,3) + C(11,3) E: None of the above Q2: You park in a 10-minute space at the coffee shop, but stay inside for 30 minutes. The parking officer comes by once every 20 minutes. If he sees your car twice in a row, you get a ticket. The probability that you receive a ticket is: A: 1/2 B: 1/3 C: 2/3 D: 1 E: None of the above Q3: You roll a fair six-sided die 10 times. Define the r.v. X to be the sum of the 10 rolls. Then, E(X) = A: 30 B: 60 C: 35 D: 25 E: None of the above Q4: You flip a fair coin 3 times. Define r.v. s: X 1 = number of heads obtained; X 2 = 1 if the second flip is heads, 0 otherwise. The joint probability h X 1,X2 (2,1) = A: 1/2 B: 3/8 C: 1/4 D: 1/8 E: 2/3 Q5: In the above question, variance X22 = E(X 22 ) (E(X 2 )) 2 is: A: 1/2 B: 1/4 C: 1/8 D: 1 E: 0

Linearity of Expectation: Baseball Cards A bubble gum company puts one random major league baseball player s card into every pack of its gum. There are N major leaguers in the league this year. If X is the number of packs of gum that a collector must buy up until she has at least one of each player s card, what is E(X)? Think about the card collecting in phases Phase 1: collect the first unique card Phase 2: collect the second unique card Phase k-1: collect the (k-1) st unique card Phase k: collect the k th unique card P(next pack ends this phase) = E(# packs to buy in this phase) =

Linearity of Expectation: Baseball Cards A bubble gum company puts one random major league baseball player s card into every pack of its gum. There are N major leaguers in the league this year. If X is the number of packs of gum that a collector must buy up until she has at least one of each player s card, what is E(X)? Define r.v. X k = #packs bought in Phase k E(X) = E( k=1..n X k ) = k=1..n E(X k ) linearity of expectation! = k=1..n N / (N k + 1) = N (1/1 + 1/2 + 1/3 + 1/4 + + 1/N) = N H N H N = N th harmonic number ~N log N packs

Decision Trees Decision trees are a systematic way of listing templates / possibilities Decision trees are a type of graph Tree: graph with n vertices: n 1 edges, connected, no cycles Can be used for enumeration (counting things systematically) Can be used to capture recursive solution approaches (algorithms) Vehicle for correspondences between induction and recursion

From Lecture 4: Sorting (w/comparisons) Input: sequence of numbers Output: a sorted sequence Sorting == Identifying a Permutation 1. This DECISION TREE is a sorting algorithm! A < B 2. To correctly sort any input, this tree needs at least as many leaves as there are possible outcomes i.e., permutations of n elements Y N 3. #comparisons needed to get to the leaf at greatest depth is the worst-case complexity of the sorting algorithm B < C A < C Y N Y N A < B < C A < C B < A < C B < C Y N Y N A < C < B C < A < B B < C < A C < B < A

Bounds on Complexity of Sorting (w/ comparisons) In any binary tree with n! leaves, some leaf has depth at least log 2 (n!) From P5.2 and P5.3: log 2 (n!) ~ n log n = Lower bound on worst-case complexity of sorting P11.3: In any binary tree with M leaves, the average leaf depth is at least log 2 M. If all n! permutations are equally likely, then average time to sort is at least log2(n!) ~ n log n = Lower bound on average-case complexity of sorting

A Traveling Salesperson s Tours Recall from Lecture 2 slides: Bob the salesman starts at his home in San Diego, and tours 6 cities (Abilene, Bakersfield, Corona, Denver, Eastville and Frankfort), visiting each city exactly once before returning home. In how many possible ways could Bob make his tour?

Number of Non-Increasing Functions How many functions from A = {1,2,3,4} to itself are non-increasing? (similar to HW6 #7) Each function can be defined by a sequence of decisions: What is f(1) What is f(2) What is f(3) What is f(4) but these are not independent decisions! If f(1) = 1, then we must have f(2) = f(3) = f(4) = 1 If f(1) = 2, then we must have f(2) {1,2} If f(2) = 2, then f(3) {1,2} Etc. (There are 35 such functions)

Non-Increasing Functions Decision Tree f(1) = 1 f(1) = 2 f(1) = 3 f(1) = 4 f(2) = 1 =1 =2 =1 =2 =3 =1 =2 =3 = 4 f(3) = 1 =1 =1 =2 =1 =2 =3 =1 =1 =2 =3 =4 f(4) = 1 =1 =1 =1 =2

Decision Tree: Non-Attacking Queens Put N queens on an N x N chessboard such that no queen attacks another queen or, in how many ways can A queen in chess can attack any square on the same row, column, or diagonal. Given an n x n chessboard, we seek to place n queens onto squares of the chessboard, such that no queen attacks another queen. The example shows a placement (red squares) of four mutually non-attacking queens.

Non-Attacking Queens: Leaf in Tree = Solution 1 2 3 4 3 4 4 1 1 2 2 1 4 3 3 2

Non-Attacking Queens Decision Tree Comments Our tree corresponded to a solution space of size 4 4 = 256 What if we numbered the squares as 1, 2,, 16 and tried to enumerate all P(16,4) choices? Solution space would have size 16 * 15 * 14 * 13 = 43680 Our decision tree was smarter We realized that there must be exactly one queen per row, so the decision for the k th row (i.e., k th queen) boils down to picking a square in the row Our illustration of the tree did not show any infeasible configurations

Another Tree: 3-Coloring a Graph Three colors: R, G, B 4 3 2 Graph 5 A graph is legally colored with k colors if each vertex has a color (label) between 1 and k (inclusive), and no adjacent vertices have the same color. 1 Example: scheduling classes into classrooms Each class = vertex in graph Edge between two vertices if class times overlap #colors = #distinct classrooms needed

4 Another Tree: 3-Coloring a Graph Three colors: R, G, B B G Graph 1B,2G By symmetry, can use any two colors for vertices 1 and 2 Tree of Colorings 3 R 5 3R 2 G?? 4G 4B 1 B A graph is legally colored with k colors if each vertex has a color (label) between 1 and k (inclusive), and no adjacent vertices have the same color.

Another Tree: 3-Coloring a Graph Three colors: R, G, B 4 3 2 G B G Graph 5 R 4G 3R 4B 1B,2G By symmetry, can use any two colors for vertices 1 and 2 4R 3B Tree of Colorings 4G 1 B A graph is legally colored with k colors if each vertex has a color (label) between 1 and k (inclusive), and no adjacent vertices have the same color. 5R

Dealing With Hard Problems (!!!) Some problems are hard No known efficient (worst-case runtime complexity that is polynomial in the size of the input) algorithm Include traveling salesperson, graph coloring (Decision) tree organization of the solution space allows systematic enumeration with pruning Kind of an intelligent brute-force Backtrack Depth-first branch-and-bound

Hashing Definition: A hash function maps data of variable length to data of a fixed length. The values returned by a hash function are called hash values or simply hashes. Open Hashing: Each item hashes to a particular location in an array, and locations can hold more than one item. Multiple input data values can have the same hash value. These are called collisions!

Number of Items Per Location n items, hash to table of size k What is expected number of items per location? n independent trials with outcome = location in table (i.e., hash value) Let r.v. X = # inputs that hash to location 1 Let s write X as the sum of X i s : X i = 1 if the i th input hashes to location 1 X i = 0 otherwise X = X 1 + X 2 + + X n E(X) = E(X 1 ) + E(X 2 ) +.. + E(X n ) = n 1/k = n/k

Number of Empty Locations What is expected number of empty locations? Define r.v. Y = # empty locations. We want E(Y) Example: 20 items into table of size 5: E(Y) = 5 (4/5) 20 0.06 Example: 20 items into table of size 10: E(Y) = 10 (9/10) 20 1.22

Toward Conditional Probability, Bayes Rule Probability of A and B, i.e., P(A B) P(A B) = P(B A) P(A) probability of B given A, times probability of A P(A B) = P(A B) P(B) (symmetrical observation) P(A B) P(B) = P(B A) P(A) P(A B) = P(B A) P(A) / P(B) Bayes Rule / Theorem

Toward Conditional Probability, Bayes Rule If a student knows 80% of the material on an exam, what is the probability that he answers a given true-false question correctly? Knows material: correct with P = 1 Doesn t know material: correct with P = 0.5 Total: 0.9

Toward Conditional Probability, Bayes Rule A drug test detects PED use 95% of the time. However, 15% of PED-free individuals also test positive (= false-positive rate). 10% of NFL players use PEDs. Your NFL player friend tests positive. What is the probability that he actually did use steroids? Event A: your friend used steroids Event B: your friend tests positive We want: P(A B)

Problems 11 P11.1 Draw a convex n-gon P, along with all possible diagonals in P. Suppose that no three diagonals pass through any single point. Give an expression (and an explanation) for the number of distinct triangles that you can find in your drawing. P11.2 2n points are chosen on a circle. In how many ways can you join pairs of points by nonintersecting chords? [Hint: this is actually similar to one of the MT review questions!] P11.3 Prove that in any binary tree with M leaves, the average leaf depth is at least log 2 M. (Note: The root is at depth = 0, its children are at depth = 1, etc.)