CS 410 Applied Algorithms Applied Algorithms Lecture #7 Counting.

Slides:



Advertisements
Similar presentations
Chapter 4 Distributed Bellman-Ford Routing
Advertisements

Michael Alves, Patrick Dugan, Robert Daniels, Carlos Vicuna
Contest format 5 hours, around 8-12 problems One computer running (likely)Linux, plus printer 3 people on one machine No cell phones, calculators, USB.
Pearls of Functional Algorithm Design Chapter 2 1 Roger L. Costello July 2011.
CS2420: Lecture 19 Vladimir Kulyukin Computer Science Department Utah State University.
CS 410 Applied Algorithms Applied Algorithms Lecture #3 Data Structures.
Cs536 Functional Programming 16/13/2015 Lecture #2.5 Today’s Topics A Few Less Trivial Examples – Numerical Functions »Differentiation and square root.
ITC242 – Introduction to Data Communications ITC431 – Computer Networks Week 13 Exam Preparation.
CS 280 Data Structures Professor John Peterson. Goals Understand “Programming in the small” Java programming Know what’s under the hood in complex libraries.
CS 410 Applied Algorithms Applied Algorithms Lecture #1 Introduction, class information, first problems.
CS 280 Data Structures Professor John Peterson. Goals Understand “Programming in the small” Java programming Know what’s under the hood in complex libraries.
CS 206 Introduction to Computer Science II 04 / 29 / 2009 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 03 / 03 / 2008 Instructor: Michael Eckmann.
Administrative Issues ICS 151 Fall 2007 Instructor: Eli Bozorgzadeh.
CS 410 Applied Algorithms Applied Algorithms Lecture #5 Sorting.
CS 410 Applied Algorithms Applied Algorithms Lecture # Backtracking.
CS 410 Applied Algorithms Applied Algorithms Lecture #6 Arithmetic and Algebra.
MGQ 201 WEEK 9 VICTORIA LOJACONO. Chapter 5 Question 1 A discrete probability distribution equals 1 I did this in excel to make it easier, but all you.
7/2/2015 IENG 486 Statistical Quality & Process Control 1 IENG Lecture 05 Interpreting Variation Using Distributions.
Ma 109 College Algebra Section 001 Fall 2005 Dr. Carl Eberhart, Professor of Mathematics
Please open your laptops, log in to the MyMathLab course web site, and open Quiz 3.6B. IMPORTANT NOTE: If you have time left after you finish the problems.
Computer Science 102 Data Structures and Algorithms V Fall 2009 Lecture 1: administrative details Professor: Evan Korth New York University 1.
MATH 310, FALL 2003 (Combinatorial Problem Solving) MoWeFr 1:20 McGregory 214.
BIT 115: Introduction To Programming1 Sit in front of a computer Log in –Username: 230class –password: –domain: student Bring up the course web.
3-2 Relations and Functions
COMP Introduction to Programming Yi Hong May 13, 2015.
1 Chapter 1 Analysis Basics. 2 Chapter Outline What is analysis? What to count and consider Mathematical background Rates of growth Tournament method.
Solve Exponential and Logarithmic Equations Lesson 7.6 Algebra II.
Welcome to CS 115! Introduction to Programming. Class URL
1 My Experiences as Faculty Member and Researcher Dr. Kalim Qureshi.
Astronomy 114 Lab Section 211, Professor Weigel. Outline for Today About Goals for this class Attendance Syllabus Safety Star Project Apparent vs. Absolute.
BIT 142:Programming & Data Structures in C#. A2 due date  A2 is due this Friday, June 12 th, by 11:30am BIT 142: Intermediate Programming2.
Dynamic Pages – Quiz #11 Feedback (under assignments) Lecture Code:
Derivative – Power Rule, Product Rule, Chain Rule, Quotient Rule Unit 4.
Week 6 - Monday.  What did we talk about last time?  Exam 1!  Before that:  Recursion.
CS161 Topic #16 1 Today in CS161 Lecture #16 Prepare for the Final Reviewing all Topics this term Variables If Statements Loops (do while, while, for)
INTRODUCTION TO PROGRAMMING ISMAIL ABUMUHFOUZ | CS 146.
Data Structures and Algorithm Analysis Introduction Lecturer: Ligang Dong, egan Tel: , Office: SIEE Building.
Tuesday December 10, 2013 Bell Ringer: Solve the following equation: 4(a - 6) + 4 = 2a - 6.
Foundation of Computing Systems
1 10/3/05CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
A Class to build skills to help in all of your classes Study & Learning Skills A College Class It can be interesting and fun It can be boring and awful.
Introduction to CIS Jan-16.
Textbook C for Scientists and Engineers © Prentice Hall 1997 Available at NUS CO-OP at S$35.10.
REMINDER: If you haven’t yet passed the Gateway Quiz, make sure you take it this week! (You can find more practice quizzes online in the Gateway Info menu.
Introduction to Financial Management. Overview of Financial Management Introduction Keys to Success Recitations Class Structure - Syllabus Text – Financial.
PHY 107 – Programming For Science. Announcements no magic formulas exist  Need to learn concepts: no magic formulas exist  Single solution not useful;
CSE 326: Data Structures Lecture #3 Asymptotic Analysis Steve Wolfman Winter Quarter 2000.
CompSci 101 Introduction to Computer Science November 11, 2014 Prof. Rodger CompSci 101 Fall Review for exam.
ECON 100 Tutorial Ayesha Ali office hours: 3:45PM to 4:45PM tuesdays LUMS C85.
Introduction to CIT Mar-16.
Functional Programming Lecture 16 - Case Study: Huffman Codes con’t.
CS 122 Engineering Computation Lab Lab1 Bruce Char Department of Computer Science Drexel University Summer 2009 ©By the author. All rights reserved. Permission.
PROBLEM SOLVING AND PROGRAMMING ISMAIL ABUMUHFOUZ | CS 170.
REMINDER: If you haven’t yet passed the Gateway Quiz, make sure you take it this week! (You can find more practice quizzes online in the Gateway Info menu.
BIT 142:Programming & Data Structures in C#. BIT 143  Continues where this leaves off  A couple of weeks to review OOP, object composition, Big “Oh”
COMPREHENSION QUIZ 6.4 LEFT 1 1. x > 4 2. x > x < -2 RIGHT 1 1. x > 3 2. x > x < -1 LEFT 2 1. x > 6 2. x > x < 1 RIGHT 2 1. x > 4 2.
Mr. Rizzutto Mathematics Room th Grade Team Mr. Barnisky – Civics Mr. Shreve – Science Miss. Dunsmore – Language Arts Mr. Rizzutto – Mathematics.
1 i206: Lecture 17: Exam 2 Prep ; Intro to Regular Expressions Marti Hearst Spring 2012.
COMP9024: Data Structures and Algorithms
CSE 5311 Advanced Algorithms
Welcome to CS 1010! Algorithmic Problem Solving.
Welcome to CS 1010! Algorithmic Problem Solving.
Suggestions for Preparation
ACCOUNTING II Chapter 13 Assignment Sheet
ACCOUNTING II Chapter 18 Assignment Sheet
Administrative Issues
Administrative Issues
CS144K An Introduction to Computer Networks
Presentation transcript:

CS 410 Applied Algorithms Applied Algorithms Lecture #7 Counting

CS 410 Applied Algorithms Exam Next Week Don’t Forget We will use half of next weeks class time for an exam. The exam will be closed book. You may bring one sheet (8.5 x 11.0 inch) of paper with notes on it. The exam will cover the reading, assignments and lectures upto the day of the exam.

CS 410 Applied Algorithms Quiz We have a 10 minute quiz today on the reading – Chapter 5. We will continue to have quizzes until the class gets an average score high enough to convince me that people are doing the reading.

CS 410 Applied Algorithms Pairsumonious [2, 4, 5, 6] -- Unknown original numbers [ 2+4, 2+5, 2+6, 4+5, 4+6, 5+6 ] -- all pair wise sums [6,7,8,9,10,11] -- Given numbers

CS 410 Applied Algorithms Computing pair-wise positions N = 4 [[(1,2),(1,3),(1,4)], [(2,3),(2,4)], [(3,4)]] N = 5 [[(1,2),(1,3),(1,4),(1,5)], [(2,3),(2,4),(2,5)], [(3,4),(3,5)], [(4,5)]]

CS 410 Applied Algorithms Sort Assumptions Assume that both the unknown list is sorted, and that the given list is sorted. We can sort it, if it isn’t. [x 1, x 2, x 3, x 4 ] -- Unknowns where x 1  x 2, x 2  x 3, x 3  x 4 [6,7,8,9,10] -- Given numbers sorted x 1 + x 2 = 6 x 1 + x 3 = 7 -- Why?

CS 410 Applied Algorithms x m + x n = 8 What are the possible values for m and n? x 1 + x 4 = 8 x 2 + x 3 = 8 Why isn’t x 2 + x 4 = 8, a possiblility?

CS 410 Applied Algorithms Enumerate the possibilities (X3+X4 = 11) (X2+X4 = 10) (X2+X3 = 9) (X1+X4 = 8) (X1+X2 = 6) (X1+X3 = 7) (X2+X3 = 8) (X1+X4 = 9) (X2+X4 = 10) (X3+X4 = 11) Every path from root to leaf is a possible solution.

CS 410 Applied Algorithms Given a Table choose the next nodes in the tree [[(1,2),(1,3),(1,4)], [(2,3),(2,4)], [(3,4)]] next2 :: Table -> [((Int,Int),Table)] next2 [] = [] next2 [(x:xs)] = [(x,[xs])] next2 ([]:ys) = next2 ys next2 ((x:xs):(y:ys):zs) = case order x y of Less -> [(x,xs:(y:ys):zs)] Greater -> [(y,(x:xs):ys:zs)] Incomp -> [(x,xs:(y:ys):zs),(y,(x:xs):ys:zs)]

CS 410 Applied Algorithms Generate All Paths paths :: [Int] -> Path -> ((Int,Int),Table) -> [Path] paths (s:sums) path ((i,j),xs) = case next2 xs of [] -> [reverse ((i,j,s):path)] zs -> concat(map (paths sums ((i,j,s):path)) zs)

CS 410 Applied Algorithms Two Paths [(1,2,6),(1,3,7),(1,4,8),(2,3,9),(2,4,10),(3,4,11)] [(1,2,6),(1,3,7),(2,3,8),(1,4,9),(2,4,10),(3,4,11)]

CS 410 Applied Algorithms Example of size 5 [[(1,2),(1,3),(1,4),(1,5)], [(2,3),(2,4),(2,5)], [(3,4),(3,5)], [(4,5)]] when n= 5 sums = [-1,0,-1,-2,1,0,-1,1,0,1] [-2,-1,-1,-1,0,0,0,1,1,1]

CS 410 Applied Algorithms (X4+X5 = 1) (X3+X5 = 1) (X3+X4 = 1) (X2+X5 = 0) (X2+X3 = 0) (X1+X5 = -1) (X2+X4 = 0) (X3+X4 = 0) (X2+X5 = 1) (X3+X5 = 1) (X4+X5 = 1) (X1+X4 = -1) (X4+X5 = 1) (X3+X5 = 1) (X3+X4 = 1) (X2+X5 = 0) (X2+X4 = 0) (X1+X5 = 0) (X3+X4 = 0) (X2+X5 = 1) (X3+X5 = 1) (X4+X5 = 1) (X2+X3 = -1) (X4+X5 = 1) (X3+X5 = 1) (X2+X5 = 1) (X3+X4 = 0) (X2+X4 = 0) (X1+X5 = 0) (X2+X5 = 0) (X3+X4 = 1) (X3+X5 = 1) (X4+X5 = 1) (X1+X2 = -2) (X1+X3 = -1) (X4+X5 = 1) (X3+X5 = 1) (X3+X4 = 1) (X2+X5 = 0) (X2+X4 = 0) (X1+X5 = 0) (X3+X4 = 0) (X2+X5 = 1) (X3+X5 = 1) (X4+X5 = 1) (X1+X4 = -1) (X2+X3 = -1) (X4+X5 = 1) (X3+X5 = 1) (X2+X5 = 1) (X3+X4 = 0) (X2+X4 = 0) (X1+X5 = 0) (X2+X5 = 0) (X3+X4 = 1) (X3+X5 = 1) (X4+X5 = 1)

CS 410 Applied Algorithms Possible paths from root to leaf [(1,2,-2),(1,3,-1),(1,4,-1),(1,5,-1),(2,3,0),(2,4,0),(2,5,0),(3,4,1),(3,5,1),(4,5,1)] [(1,2,-2),(1,3,-1),(1,4,-1),(1,5,-1),(2,3,0),(2,4,0),(3,4,0),(2,5,1),(3,5,1),(4,5,1)] [(1,2,-2),(1,3,-1),(1,4,-1),(2,3,-1),(1,5,0),(2,4,0),(2,5,0),(3,4,1),(3,5,1),(4,5,1)] [(1,2,-2),(1,3,-1),(1,4,-1),(2,3,-1),(1,5,0),(2,4,0),(3,4,0),(2,5,1),(3,5,1),(4,5,1)] [(1,2,-2),(1,3,-1),(1,4,-1),(2,3,-1),(2,4,0),(1,5,0),(2,5,0),(3,4,1),(3,5,1),(4,5,1)] [(1,2,-2),(1,3,-1),(1,4,-1),(2,3,-1),(2,4,0),(1,5,0),(3,4,0),(2,5,1),(3,5,1),(4,5,1)] [(1,2,-2),(1,3,-1),(2,3,-1),(1,4,-1),(1,5,0),(2,4,0),(2,5,0),(3,4,1),(3,5,1),(4,5,1)] [(1,2,-2),(1,3,-1),(2,3,-1),(1,4,-1),(1,5,0),(2,4,0),(3,4,0),(2,5,1),(3,5,1),(4,5,1)] [(1,2,-2),(1,3,-1),(2,3,-1),(1,4,-1),(2,4,0),(1,5,0),(2,5,0),(3,4,1),(3,5,1),(4,5,1)] [(1,2,-2),(1,3,-1),(2,3,-1),(1,4,-1),(2,4,0),(1,5,0),(3,4,0),(2,5,1),(3,5,1),(4,5,1)]

CS 410 Applied Algorithms Is a path feasible? [(1,2,6),(1,3,7),(1,4,8),(2,3,9),(2,4,10),(3,4,11)] [(x 1 +x 2 =6),(x 1 +x 3 =7),(x 1 +x 4 =8), (x 2 +x 3 =9),(x 2 +x 4 =10),(x 3 +x 4 =11)] How can we test this?

CS 410 Applied Algorithms Every path contains all pair-wise sums So they must contain the following (x 1 +x 2 =A) (x 1 +x 3 =B) (x 2 +x 3 =C) N=4 examples –[(1,2,6),(1,3,7),(1,4,8),(2,3,9),(2,4,10),(3,4,11)] –[(1,2,6),(1,3,7),(2,3,8),(1,4,9),(2,4,10),(3,4,11)] N=5 example [(1,2,-2),(1,3,-1),(1,4,-1),(2,3,-1),(2,4,0),(1,5,0),(2,5,0),(3,4,1),(3,5,1),(4,5,1)]

CS 410 Applied Algorithms (x 1 +x 2 =A) (x 1 +x 3 =B) (x 2 +x 3 =C) (x 1 +x 2 ) + (x 1 +x 3 ) - (x 2 +x 3 ) = A + B – C 2 * x 1 = A + B – C Solving for x1 we get x 1 = (A+B-C)/2 Algorithm find the 3 pairs in the path and solve

CS 410 Applied Algorithms Code solveX1 :: Int -> Int -> Int -> Path -> Maybe Int solveX1 x12 x13 x23 ((1,2,w):ys) = solveX1 w x13 x23 ys solveX1 x12 x13 x23 ((1,3,w):ys) = solveX1 x12 w x23 ys solveX1 x12 x13 x23 ((2,3,w):ys) = solveX1 x12 x13 w ys solveX1 x12 x13 x23 (y:ys) = solveX1 x12 x13 x23 ys solveX1 x12 x13 x23 [] = if even sum then Just(sum `div` 2) else Nothing where sum = x12+x13-x23

CS 410 Applied Algorithms Every path also contains N=4 examples –[(1,2,6),(1,3,7),(1,4,8),(2,3,9),(2,4,10),(3,4,11)] –[(1,2,6),(1,3,7),(2,3,8),(1,4,9),(2,4,10),(3,4,11)] N=5 example [(1,2,-2),(1,3,-1),(1,4,-1),(2,3,1),(2,4,0),(1,5,0),(2,5,0),(3,4,1),(3,5,1),(4,5,1)]

CS 410 Applied Algorithms Code solveRest :: Int -> Path -> [(Int,Int)] -> [(Int,Int)] solveRest x1 [] pairs = pairs solveRest x1 ((1,xn,sum):xs) pairs = solveRest x1 xs ((xn,sum - x1):pairs) solveRest x1 (x:xs) pairs = solveRest x1 xs pairs solve [] = Nothing solve (p:paths) = case solveX p of Just x1 -> Just(map snd (sort(solveRest x1 p [(1,x1)]))) Nothing -> solve paths

CS 410 Applied Algorithms In Class Problems How Many Fibs? –Page 137 of the text –We will write this together as a class Expressions –Page 140 of the text –

CS 410 Applied Algorithms Today’s Assignments Read for next time Chapter 7 of the text. pp Be prepared to answer questions in class next Friday from the reading. Programming assignment Steps Page 145 Write a solution Submit your solution (until you get it right) Hand in both your program, and the judge output. Those who volunteer to discuss their program get class participation points. me solutions before noon on Friday, May 6.