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

Size: px
Start display at page:

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

Transcription

1 UCSD CSE 21, Spring 2014 [Section B00] Mathematics for Algorithm and System Analysis Lecture 11 Class URL:

2 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 s sent out to prompt 1-1, small-group tutor sessions. See also IDEA Center (TBP, HKN) tutoring If you didn t receive this , and want a copy, please tell me! Possibly of interest ( life advice ): Four parts: Context, Research, Grad School, Life/Career

3 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

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

5 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

6 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) =

7 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/ /N) = N H N H N = N th harmonic number ~N log N packs

8 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

9 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

10 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

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

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

13 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

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

15 Non-Attacking Queens: Leaf in Tree = Solution

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

17 Another Tree: 3-Coloring a Graph Three colors: R, G, B 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

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

19 Another Tree: 3-Coloring a Graph Three colors: R, G, B 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

20 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

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

22 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 X n E(X) = E(X 1 ) + E(X 2 ) E(X n ) = n 1/k = n/k

23 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) Example: 20 items into table of size 10: E(Y) = 10 (9/10)

24 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

25 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

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

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

Backtracking and Branch-and-Bound

Backtracking and Branch-and-Bound Backtracking and Branch-and-Bound Usually for problems with high complexity Exhaustive Search is too time consuming Cut down on some search using special methods Idea: Construct partial solutions and extend

More information

Chapter-6 Backtracking

Chapter-6 Backtracking Chapter-6 Backtracking 6.1 Background Suppose, if you have to make a series of decisions, among various choices, where you don t have enough information to know what to choose. Each decision leads to a

More information

Discrete Mathematics and Probability Theory Fall 2013 Midterm #2

Discrete Mathematics and Probability Theory Fall 2013 Midterm #2 CS 70 Discrete Mathematics and Probability Theory Fall 013 Midterm # 1. (30 points) Short Answer. No justification necessary. Please write only the answer in the space provided after each question. Please

More information

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

UCSD CSE 21, Spring 2014 [Section B00] Mathematics for Algorithm and System Analysis UCSD CSE 21, Spring 2014 [Section B00] Mathematics for Algorithm and System Analysis Lecture 16 Class URL: http://vlsicad.ucsd.edu/courses/cse21-s14/ Lecture 16 Notes Goals for this week Graph basics Types

More information

Trees, Trees and More Trees

Trees, Trees and More Trees Trees, Trees and More Trees August 9, 01 Andrew B. Kahng abk@cs.ucsd.edu http://vlsicad.ucsd.edu/~abk/ How You ll See Trees in CS Trees as mathematical objects Trees as data structures Trees as tools for

More information

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 CS1800 Discrete Structures Fall 2016 Profs. Aslam, Gold, Ossowski, Pavlu, & Sprague December 16, 2016 Instructions: CS1800 Discrete Structures Final 1. The exam is closed book and closed notes. You may

More information

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 CS1800 Discrete Structures Fall 2016 Profs. Aslam, Gold, Ossowski, Pavlu, & Sprague December 16, 2016 Instructions: CS1800 Discrete Structures Final 1. The exam is closed book and closed notes. You may

More information

Discrete Mathematics Course Review 3

Discrete Mathematics Course Review 3 21-228 Discrete Mathematics Course Review 3 This document contains a list of the important definitions and theorems that have been covered thus far in the course. It is not a complete listing of what has

More information

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

Coping with the Limitations of Algorithm Power Exact Solution Strategies Backtracking Backtracking : A Scenario Coping with the Limitations of Algorithm Power Tackling Difficult Combinatorial Problems There are two principal approaches to tackling difficult combinatorial problems (NP-hard problems): Use a strategy

More information

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

Backtracking is a refinement of the brute force approach, which systematically searches for a Backtracking Backtracking is a refinement of the brute force approach, which systematically searches for a solution to a problem among all available options. It does so by assuming that the solutions are

More information

COMP3121/3821/9101/ s1 Assignment 1

COMP3121/3821/9101/ s1 Assignment 1 Sample solutions to assignment 1 1. (a) Describe an O(n log n) algorithm (in the sense of the worst case performance) that, given an array S of n integers and another integer x, determines whether or not

More information

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

CPSC 320: Intermediate Algorithm Design and Analysis. Tutorial: Week 3 CPSC 320: Intermediate Algorithm Design and Analysis Author: Susanne Bradley Tutorial: Week 3 At the time of this week s tutorial, we were approaching the end of our stable matching unit and about to start

More information

Applications. 72 Variables and Patterns

Applications. 72 Variables and Patterns Applications. Sean bought a DVD player and a receiver. The store offered him an interest-free payment plan with weekly installments. Sean figured out that after n weeks of payments, he would still owe

More information

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

Notes slides from before lecture. CSE 21, Winter 2017, Section A00. Lecture 10 Notes. Class URL: Notes slides from before lecture CSE 21, Winter 2017, Section A00 Lecture 10 Notes Class URL: http://vlsicad.ucsd.edu/courses/cse21-w17/ Notes slides from before lecture Notes February 13 (1) HW5 is due

More information

Extra Practice Problems 2

Extra Practice Problems 2 CS103 Handout 31 Fall 2018 October 29, 2018 Extra Practice Problems 2 Here's a set of a bunch of practice problems you can work through to solidify your understanding of the topics from Problem Sets Three,

More information

Practice Problems for the Final

Practice Problems for the Final ECE-250 Algorithms and Data Structures (Winter 2012) Practice Problems for the Final Disclaimer: Please do keep in mind that this problem set does not reflect the exact topics or the fractions of each

More information

CSC 8301 Design and Analysis of Algorithms: Exhaustive Search

CSC 8301 Design and Analysis of Algorithms: Exhaustive Search CSC 8301 Design and Analysis of Algorithms: Exhaustive Search Professor Henry Carter Fall 2016 Recap Brute force is the use of iterative checking or solving a problem by its definition The straightforward

More information

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

Department of Computer Applications. MCA 312: Design and Analysis of Algorithms. [Part I : Medium Answer Type Questions] UNIT I MCA 312: Design and Analysis of Algorithms [Part I : Medium Answer Type Questions] UNIT I 1) What is an Algorithm? What is the need to study Algorithms? 2) Define: a) Time Efficiency b) Space Efficiency

More information

Lecture 14: General Problem-Solving Methods

Lecture 14: General Problem-Solving Methods Lecture 14: General Problem-Solving Methods Problem Solving Methods Greedy Method Divide-and-Conquer Backtracking Dynamic Programming Branch-and-Bound Greedy Method The greedy method consists of an iteration

More information

Discrete Mathematics Exam File Fall Exam #1

Discrete Mathematics Exam File Fall Exam #1 Discrete Mathematics Exam File Fall 2015 Exam #1 1.) Which of the following quantified predicate statements are true? Justify your answers. a.) n Z, k Z, n + k = 0 b.) n Z, k Z, n + k = 0 2.) Prove that

More information

Trees and Intro to Counting

Trees and Intro to Counting Trees and Intro to Counting CSE21 Winter 2017, Day 15 (B00), Day 10/11 (A00) February 15, 2017 http://vlsicad.ucsd.edu/courses/cse21-w17 Another Special Type of Graph: Trees (Rooted) Trees: definitions

More information

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

CS 251, LE 2 Fall MIDTERM 2 Tuesday, November 1, 2016 Version 00 - KEY CS 251, LE 2 Fall 2016 MIDTERM 2 Tuesday, November 1, 2016 Version 00 - KEY W1.) (i) Show one possible valid 2-3 tree containing the nine elements: 1 3 4 5 6 8 9 10 12. (ii) Draw the final binary search

More information

Lecture 3. Brute Force

Lecture 3. Brute Force Lecture 3 Brute Force 1 Lecture Contents 1. Selection Sort and Bubble Sort 2. Sequential Search and Brute-Force String Matching 3. Closest-Pair and Convex-Hull Problems by Brute Force 4. Exhaustive Search

More information

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.

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. ICS 161 Algorithms Winter 1998 Final Exam Name: ID: 1: out of 15 2: out of 15 3: out of 20 4: out of 15 5: out of 20 6: out of 15 total: out of 100 1. Solve the following recurrences. (Just give the solutions;

More information

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

CS 561, Lecture 1. Jared Saia University of New Mexico CS 561, Lecture 1 Jared Saia University of New Mexico Quicksort Based on divide and conquer strategy Worst case is Θ(n 2 ) Expected running time is Θ(n log n) An In-place sorting algorithm Almost always

More information

Introduction to Computer Science

Introduction to Computer Science Introduction to Computer Science CSCI 109 Readings St. Amant, Ch. 4, Ch. 8 China Tianhe-2 Andrew Goodney Spring 2018 An algorithm (pronounced AL-go-rithum) is a procedure or formula for solving a problem.

More information

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

Midterm 2 Solutions. CS70 Discrete Mathematics and Probability Theory, Spring 2009 CS70 Discrete Mathematics and Probability Theory, Spring 2009 Midterm 2 Solutions Note: These solutions are not necessarily model answers. Rather, they are designed to be tutorial in nature, and sometimes

More information

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

CSE 417 Branch & Bound (pt 4) Branch & Bound CSE 417 Branch & Bound (pt 4) Branch & Bound Reminders > HW8 due today > HW9 will be posted tomorrow start early program will be slow, so debugging will be slow... Review of previous lectures > Complexity

More information

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

Packet #6: Counting & Graph Theory. Applied Discrete Mathematics Packet #6: Counting & Graph Theory Applied Discrete Mathematics Table of Contents Counting Pages 1-8 Graph Theory Pages 9-16 Exam Study Sheet Page 17 Counting Information I. Product Rule: A B C = A * B

More information

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

More NP-complete Problems. CS255 Chris Pollett May 3, 2006. More NP-complete Problems CS255 Chris Pollett May 3, 2006. Outline More NP-Complete Problems Hamiltonian Cycle Recall a hamiltonian cycle is a permutation of the vertices v i_1,, v i_n of a graph G so

More information

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

PSD1A. DESIGN AND ANALYSIS OF ALGORITHMS Unit : I-V PSD1A DESIGN AND ANALYSIS OF ALGORITHMS Unit : I-V UNIT I -- Introduction -- Definition of Algorithm -- Pseudocode conventions -- Recursive algorithms -- Time and space complexity -- Big- o notation --

More information

Combinatorics: The Fine Art of Counting

Combinatorics: The Fine Art of Counting Combinatorics: The Fine Art of Counting Week Eight Problems 1. Diagrams of all the distinct non-isomorphic trees on 6 or fewer vertices are listed in the lecture notes. Extend this list by drawing all

More information

Unit 1, Lesson 1: Moving in the Plane

Unit 1, Lesson 1: Moving in the Plane Unit 1, Lesson 1: Moving in the Plane Let s describe ways figures can move in the plane. 1.1: Which One Doesn t Belong: Diagrams Which one doesn t belong? 1.2: Triangle Square Dance m.openup.org/1/8-1-1-2

More information

Instructor: Paul Zeitz, University of San Francisco

Instructor: Paul Zeitz, University of San Francisco Berkeley Math Circle Graph Theory and Ramsey Theory Instructor: Paul Zeitz, University of San Francisco (zeitz@usfca.edu) Definitions 1 A graph is a pair (V,E), where V is a finite set and E is a set of

More information

CS 440 Theory of Algorithms /

CS 440 Theory of Algorithms / CS 440 Theory of Algorithms / CS 468 Algorithms in Bioinformaticsi Brute Force. Design and Analysis of Algorithms - Chapter 3 3-0 Brute Force A straightforward approach usually based on problem statement

More information

Randomized Algorithms: Element Distinctness

Randomized Algorithms: Element Distinctness Randomized Algorithms: Element Distinctness CSE21 Winter 2017, Day 24 (B00), Day 16-17 (A00) March 13, 2017 http://vlsicad.ucsd.edu/courses/cse21-w17 Element Distinctness: WHAT Given list of positive integers

More information

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

Parallel and Sequential Data Structures and Algorithms Lecture (Spring 2012) Lecture 16 Treaps; Augmented BSTs Lecture 16 Treaps; Augmented BSTs Parallel and Sequential Data Structures and Algorithms, 15-210 (Spring 2012) Lectured by Margaret Reid-Miller 8 March 2012 Today: - More on Treaps - Ordered Sets and Tables

More information

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

COMP251: Background. Jérôme Waldispühl School of Computer Science McGill University COMP251: Background Jérôme Waldispühl School of Computer Science McGill University Big-Oh notation f(n) is O(g(n)) iff there exists a point n 0 beyond which f(n) is less than some fixed constant times

More information

CMSC Introduction to Algorithms Spring 2012 Lecture 16

CMSC Introduction to Algorithms Spring 2012 Lecture 16 CMSC 351 - Introduction to Algorithms Spring 2012 Lecture 16 Instructor: MohammadTaghi Hajiaghayi Scribe: Rajesh Chitnis 1 Introduction In this lecture we will look at Greedy Algorithms and Dynamic Programming.

More information

CS 231: Algorithmic Problem Solving

CS 231: Algorithmic Problem Solving CS 231: Algorithmic Problem Solving Naomi Nishimura Module 7 Date of this version: January 28, 2019 WARNING: Drafts of slides are made available prior to lecture for your convenience. After lecture, slides

More information

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

CSE 100: B+ TREE, 2-3 TREE, NP- COMPLETNESS CSE 100: B+ TREE, 2-3 TREE, NP- COMPLETNESS Analyzing find in B-trees Since the B-tree is perfectly height-balanced, the worst case time cost for find is O(logN) Best case: If every internal node is completely

More information

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

MC 302 GRAPH THEORY 10/1/13 Solutions to HW #2 50 points + 6 XC points MC 0 GRAPH THEORY 0// Solutions to HW # 0 points + XC points ) [CH] p.,..7. This problem introduces an important class of graphs called the hypercubes or k-cubes, Q, Q, Q, etc. I suggest that before you

More information

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

Chapter 6 Backtracking Algorithms. Backtracking algorithms Branch-and-bound algorithms Chapter 6 Backtracking Algorithms Backtracking algorithms Branch-and-bound algorithms 1 Backtracking Algorithm The task is to determine algorithm for finding solutions to specific problems not by following

More information

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

Sankalchand Patel College of Engineering - Visnagar Department of Computer Engineering and Information Technology. Assignment Class: V - CE Sankalchand Patel College of Engineering - Visnagar Department of Computer Engineering and Information Technology Sub: Design and Analysis of Algorithms Analysis of Algorithm: Assignment

More information

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

Math 55 - Spring Lecture notes # 14 - March 9 (Tuesday) Math 55 - Spring 2004 - Lecture notes # 14 - March 9 (Tuesday) Read Chapter 4 Goals for Today: Continue counting principles Tree diagrams Pigeonhole principle Permutations Combinations Homework: 1) (Based

More information

Exercise 1. D-ary Tree

Exercise 1. D-ary Tree CSE 101: Design and Analysis of Algorithms Winter 2018 Homework 1 Solutions Due: 01/19/2018, 11.59 PM Exercise 1. D-ary Tree A d-ary tree is a rooted tree in which each node has at most d children. Show

More information

Lecture 3: Recursion; Structural Induction

Lecture 3: Recursion; Structural Induction 15-150 Lecture 3: Recursion; Structural Induction Lecture by Dan Licata January 24, 2012 Today, we are going to talk about one of the most important ideas in functional programming, structural recursion

More information

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

Ma/CS 6b Class 26: Art Galleries and Politicians Ma/CS 6b Class 26: Art Galleries and Politicians By Adam Sheffer The Art Gallery Problem Problem. We wish to place security cameras at a gallery, such that they cover it completely. Every camera can cover

More information

Backtracking. Chapter 5

Backtracking. Chapter 5 1 Backtracking Chapter 5 2 Objectives Describe the backtrack programming technique Determine when the backtracking technique is an appropriate approach to solving a problem Define a state space tree for

More information

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

1 Leaffix Scan, Rootfix Scan, Tree Size, and Depth Lecture 17 Graph Contraction I: Tree Contraction Parallel and Sequential Data Structures and Algorithms, 15-210 (Spring 2012) Lectured by Kanat Tangwongsan March 20, 2012 In this lecture, we will explore

More information

Design and Analysis of Algorithms

Design and Analysis of Algorithms CSE 101, Winter 018 D/Q Greed SP s DP LP, Flow B&B, Backtrack Metaheuristics P, NP Design and Analysis of Algorithms Lecture 8: Greed Class URL: http://vlsicad.ucsd.edu/courses/cse101-w18/ Optimization

More information

Elements of Graph Theory

Elements of Graph Theory Elements of Graph Theory Quick review of Chapters 9.1 9.5, 9.7 (studied in Mt1348/2008) = all basic concepts must be known New topics we will mostly skip shortest paths (Chapter 9.6), as that was covered

More information

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

COSC 2007 Data Structures II Final Exam. Part 1: multiple choice (1 mark each, total 30 marks, circle the correct answer) COSC 2007 Data Structures II Final Exam Thursday, April 13 th, 2006 This is a closed book and closed notes exam. There are total 3 parts. Please answer the questions in the provided space and use back

More information

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.

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. It is recommended that you read through the exam before you begin. Answer all questions in the space provided. Name: Answer whether the following statements are true or false and briefly explain your answer

More information

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

CSE 20. Lecture 4: Number System and Boolean Function. CSE 20: Lecture2 CSE 20 Lecture 4: Number System and Boolean Function Next Weeks Next week we will do Unit:NT, Section 1. There will be an assignment set posted today. It is just for practice. Boolean Functions and Number

More information

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

Mathematics and Statistics, Part A: Graph Theory Problem Sheet 1, lectures 1-4 1. Draw Mathematics and Statistics, Part A: Graph Theory Problem Sheet 1, lectures 1-4 (i) a simple graph. A simple graph has a non-empty vertex set and no duplicated edges. For example sketch G with V

More information

CSE 21 Summer 2017 Homework 4

CSE 21 Summer 2017 Homework 4 CSE 21 Summer 201 Homework Key Concepts Minimum Spanning Trees, Directed Acyclic Graphs, Topological Sorting, Single source shortest paths, Counting, Basic probability principles, Independence, Linearity

More information

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

Year 2 Spring Term Week 5 to 7 - Geometry: Properties of Shape 1 Year 2 Spring Term Week 5 to 7 - Geometry: Properties of Shape Recognise 2-D and 3-D shapes Count sides on 2-D shapes Count vertices on 2-D shapes Draw 2-D shapes Lines of symmetry Sort 2-D shapes Make

More information

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

Chapter 4. Relations & Graphs. 4.1 Relations. Exercises For each of the relations specified below: Chapter 4 Relations & Graphs 4.1 Relations Definition: Let A and B be sets. A relation from A to B is a subset of A B. When we have a relation from A to A we often call it a relation on A. When we have

More information

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.

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. Discrete Mathematics 2 - Test File - Spring 2013 Exam #1 1.) RSA - Suppose we choose p = 5 and q = 11. You're going to be sending the coded message M = 23. a.) Choose a value for e, satisfying the requirements

More information

Chapter 11: Graphs and Trees. March 23, 2008

Chapter 11: Graphs and Trees. March 23, 2008 Chapter 11: Graphs and Trees March 23, 2008 Outline 1 11.1 Graphs: An Introduction 2 11.2 Paths and Circuits 3 11.3 Matrix Representations of Graphs 4 11.5 Trees Graphs: Basic Definitions Informally, a

More information

Algorithm classification

Algorithm classification Types of Algorithms Algorithm classification Algorithms that use a similar problem-solving approach can be grouped together We ll talk about a classification scheme for algorithms This classification scheme

More information

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

1 5,9,2,7,6,10,4,3,8,1 The first number (5) is automatically the first number of the sorted list Algorithms One of the more challenging aspects of Computer Science are algorithms. An algorithm is a plan that solves a problem. When assembling a bicycle based on the included instructions, in this case,

More information

UNIT 4 Branch and Bound

UNIT 4 Branch and Bound UNIT 4 Branch and Bound General method: Branch and Bound is another method to systematically search a solution space. Just like backtracking, we will use bounding functions to avoid generating subtrees

More information

Steven Skiena. skiena

Steven Skiena.   skiena Lecture 22: Introduction to NP-completeness (1997) Steven Skiena Department of Computer Science State University of New York Stony Brook, NY 11794 4400 http://www.cs.sunysb.edu/ skiena Among n people,

More information

Figure 4.1: The evolution of a rooted tree.

Figure 4.1: The evolution of a rooted tree. 106 CHAPTER 4. INDUCTION, RECURSION AND RECURRENCES 4.6 Rooted Trees 4.6.1 The idea of a rooted tree We talked about how a tree diagram helps us visualize merge sort or other divide and conquer algorithms.

More information

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

CIS 121 Data Structures and Algorithms Midterm 3 Review Solution Sketches Fall 2018 CIS 121 Data Structures and Algorithms Midterm 3 Review Solution Sketches Fall 2018 Q1: Prove or disprove: You are given a connected undirected graph G = (V, E) with a weight function w defined over its

More information

Lower Bound on Comparison-based Sorting

Lower Bound on Comparison-based Sorting Lower Bound on Comparison-based Sorting Different sorting algorithms may have different time complexity, how to know whether the running time of an algorithm is best possible? We know of several sorting

More information

Randomized Algorithms, Hash Functions

Randomized Algorithms, Hash Functions Randomized Algorithms, Hash Functions Lecture A Tiefenbruck MWF 9-9:50am Center 212 Lecture B Jones MWF 2-2:50pm Center 214 Lecture C Tiefenbruck MWF 11-11:50am Center 212 http://cseweb.ucsd.edu/classes/wi16/cse21-abc/

More information

1. Read each problem carefully and follow the instructions.

1. Read each problem carefully and follow the instructions. SSII 2014 1 Instructor: Benjamin Wilson Name: 1. Read each problem carefully and follow the instructions. 2. No credit will be given for correct answers without supporting work and/ or explanation. 3.

More information

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

Treaps. 1 Binary Search Trees (BSTs) CSE341T/CSE549T 11/05/2014. Lecture 19 CSE34T/CSE549T /05/04 Lecture 9 Treaps Binary Search Trees (BSTs) Search trees are tree-based data structures that can be used to store and search for items that satisfy a total order. There are many types

More information

Randomized Algorithms: Selection

Randomized Algorithms: Selection Randomized Algorithms: Selection CSE21 Winter 2017, Day 25 (B00), Day 16 (A00) March 15, 2017 http://vlsicad.ucsd.edu/courses/cse21-w17 Selection Problem: WHAT Given list of distinct integers a 1, a 2,,

More information

CSCE 411 Design and Analysis of Algorithms

CSCE 411 Design and Analysis of Algorithms CSCE 411 Design and Analysis of Algorithms Set 4: Transform and Conquer Slides by Prof. Jennifer Welch Spring 2014 CSCE 411, Spring 2014: Set 4 1 General Idea of Transform & Conquer 1. Transform the original

More information

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

Angles of Polygons. Essential Question What is the sum of the measures of the interior angles of a polygon? 7.1 Angles of Polygons Essential Question What is the sum of the measures of the interior angles of a polygon? The Sum of the Angle Measures of a Polygon Work with a partner. Use dynamic geometry software.

More information

CS 373: Combinatorial Algorithms, Spring 1999

CS 373: Combinatorial Algorithms, Spring 1999 CS 373: Combinatorial Algorithms, Spring 1999 Final Exam (May 7, 1999) Name: Net ID: Alias: This is a closed-book, closed-notes exam! If you brought anything with you besides writing instruments and your

More information

Lecture 21: Other Reductions Steven Skiena

Lecture 21: Other Reductions Steven Skiena Lecture 21: Other Reductions Steven Skiena Department of Computer Science State University of New York Stony Brook, NY 11794 4400 http://www.cs.stonybrook.edu/ skiena Problem of the Day Show that the dense

More information

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

Quiz 1 Solutions. (a) f(n) = n g(n) = log n Circle all that apply: f = O(g) f = Θ(g) f = Ω(g) Introduction to Algorithms March 11, 2009 Massachusetts Institute of Technology 6.006 Spring 2009 Professors Sivan Toledo and Alan Edelman Quiz 1 Solutions Problem 1. Quiz 1 Solutions Asymptotic orders

More information

Final Examination CSE 100 UCSD (Practice)

Final Examination CSE 100 UCSD (Practice) Final Examination UCSD (Practice) RULES: 1. Don t start the exam until the instructor says to. 2. This is a closed-book, closed-notes, no-calculator exam. Don t refer to any materials other than the exam

More information

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

CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators) Name: Email address: Quiz Section: CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators) Instructions: Read the directions for each question carefully before answering. We will

More information

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

1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1 Asymptotics, Recurrence and Basic Algorithms 1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1 2. O(n) 2. [1 pt] What is the solution to the recurrence T(n) = T(n/2) + n, T(1)

More information

Copyright 2000, Kevin Wayne 1

Copyright 2000, Kevin Wayne 1 Guessing Game: NP-Complete? 1. LONGEST-PATH: Given a graph G = (V, E), does there exists a simple path of length at least k edges? YES. SHORTEST-PATH: Given a graph G = (V, E), does there exists a simple

More information

Discrete Math: Selected Homework Problems

Discrete Math: Selected Homework Problems Discrete Math: Selected Homework Problems 2006 2.1 Prove: if d is a common divisor of a and b and d is also a linear combination of a and b then d is a greatest common divisor of a and b. (5 3.1 Prove:

More information

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

The problem: given N, find all solutions of queen sets and return either the number of solutions and/or the patterned boards. N-ueens Background Problem surfaced in 1848 by chess player Ma Bezzel as 8 queens (regulation board size) Premise is to place N queens on N N board so that they are non-attacking A queen is one of si different

More information

Data Structures (CS 1520) Lecture 28 Name:

Data Structures (CS 1520) Lecture 28 Name: Traeling Salesperson Problem (TSP) -- Find an optimal (ie, minimum length) when at least one exists A (or Hamiltonian circuit) is a path from a ertex back to itself that passes through each of the other

More information

Dynamic Programming Homework Problems

Dynamic Programming Homework Problems CS 1510 Dynamic Programming Homework Problems 1. (2 points) Consider the recurrence relation T (0) = T (1) = 2 and for n > 1 n 1 T (n) = T (i)t (i 1) i=1 We consider the problem of computing T (n) from

More information

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

Combinatorial Search. permutations backtracking counting subsets paths in a graph. Overview Overview Exhaustive search. Iterate through all elements of a search space. Combinatorial Search Backtracking. Systematic method for examining feasible solutions to a problem, by systematically eliminating

More information

Discrete Mathematics 2 Exam File Spring 2012

Discrete Mathematics 2 Exam File Spring 2012 Discrete Mathematics 2 Exam File Spring 2012 Exam #1 1.) Suppose f : X Y and A X. a.) Prove or disprove: f -1 (f(a)) A. Prove or disprove: A f -1 (f(a)). 2.) A die is rolled four times. What is the probability

More information

Notes for Lecture 24

Notes for Lecture 24 U.C. Berkeley CS170: Intro to CS Theory Handout N24 Professor Luca Trevisan December 4, 2001 Notes for Lecture 24 1 Some NP-complete Numerical Problems 1.1 Subset Sum The Subset Sum problem is defined

More information

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

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Sorting lower bound and Linear-time sorting Date: 9/19/17 601.433/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Sorting lower bound and Linear-time sorting Date: 9/19/17 5.1 Introduction You should all know a few ways of sorting in O(n log n)

More information

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

Instructions. Definitions. Name: CMSC 341 Fall Question Points I. /12 II. /30 III. /10 IV. /12 V. /12 VI. /12 VII. CMSC 341 Fall 2013 Data Structures Final Exam B Name: Question Points I. /12 II. /30 III. /10 IV. /12 V. /12 VI. /12 VII. /12 TOTAL: /100 Instructions 1. This is a closed-book, closed-notes exam. 2. You

More information

Math 574 Review Exam #1

Math 574 Review Exam #1 Math 574 Review Exam 1 1. How many 8-card hands, dealt from a standard deck of 5, consist of: (a). 5 of one suit and 3 of another suit? (b). 4 each of two suits. (c). 3 of one suit, 3 of a second suit,

More information

The Probabilistic Method

The Probabilistic Method The Probabilistic Method Po-Shen Loh June 2010 1 Warm-up 1. (Russia 1996/4 In the Duma there are 1600 delegates, who have formed 16000 committees of 80 persons each. Prove that one can find two committees

More information

Design and Analysis of Algorithms

Design and Analysis of Algorithms CSE, Winter 8 Design and Analysis of Algorithms Lecture : Graphs, DFS (Undirected, Directed), DAGs Class URL: http://vlsicad.ucsd.edu/courses/cse-w8/ Graphs Internet topology Graphs Gene-gene interactions

More information

Search and Optimization

Search and Optimization Search and Optimization Search, Optimization and Game-Playing The goal is to find one or more optimal or sub-optimal solutions in a given search space. We can either be interested in finding any one solution

More information

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

Algorithms and Data Structures (INF1) Lecture 15/15 Hua Lu Algorithms and Data Structures (INF1) Lecture 15/15 Hua Lu Department of Computer Science Aalborg University Fall 2007 This Lecture Minimum spanning trees Definitions Kruskal s algorithm Prim s algorithm

More information

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

CSE100 Practice Final Exam Section C Fall 2015: Dec 10 th, Problem Topic Points Possible Points Earned Grader CSE100 Practice Final Exam Section C Fall 2015: Dec 10 th, 2015 Problem Topic Points Possible Points Earned Grader 1 The Basics 40 2 Application and Comparison 20 3 Run Time Analysis 20 4 C++ and Programming

More information

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

TILING PROBLEMS: FROM DOMINOES, CHECKERBOARDS, AND MAZES TO DISCRETE GEOMETRY TILING PROBLEMS: FROM DOMINOES, CHECKERBOARDS, AND MAZES TO DISCRETE GEOMETRY BERKELEY MATH CIRCLE 1. Looking for a number Consider an 8 8 checkerboard (like the one used to play chess) and consider 32

More information

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

Sorting. There exist sorting algorithms which have shown to be more efficient in practice. Sorting Next to storing and retrieving data, sorting of data is one of the more common algorithmic tasks, with many different ways to perform it. Whenever we perform a web search and/or view statistics

More information

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

CSE 332 Spring 2014: Midterm Exam (closed book, closed notes, no calculators) Name: Email address: Quiz Section: CSE 332 Spring 2014: Midterm Exam (closed book, closed notes, no calculators) Instructions: Read the directions for each question carefully before answering. We will

More information

Assignment No 2 (Group B)

Assignment No 2 (Group B) Assignment No 2 (Group B) 1 Problem Statement : Concurrent Implementation of Travelling Salesman Problem. 2 Objective : To develop problem solving abilities using Mathematical Modeling. To apply algorithmic

More information