Incremental Problem Solving for CS1100

Slides:



Advertisements
Similar presentations
DMOR Branch and bound. Integer programming Modelling logical constraints and making them linear: – Conjuction – Disjunction – Implication – Logical constraints.
Advertisements

CSC 421: Algorithm Design & Analysis
Counting the bits Analysis of Algorithms Will it run on a larger problem? When will it fail?
Example 6.1 Capital Budgeting Models | 6.3 | 6.4 | 6.5 | 6.6 | Background Information n The Tatham Company is considering seven.
Iteration and Recursion Tonga Institute of Higher Education.
The Simplex Method: Standard Maximization Problems
Lesson 19 Recursion CS1 -- John Cole1. Recursion 1. (n) The act of cursing again. 2. see recursion 3. The concept of functions which can call themselves.
Constraint Satisfaction Problems
Network Optimization Models: Maximum Flow Problems In this handout: The problem statement Solving by linear programming Augmenting path algorithm.
Linear and Integer Programming Models
Branch and Bound Algorithm for Solving Integer Linear Programming
Objectives: Set up a Linear Programming Problem Solve a Linear Programming Problem.
Key Stone Problem… Key Stone Problem… next Set 24 © 2007 Herbert I. Gross.
A Simple Model Checker for CTL. The problem n We need efficient algorithms to solve the problems [1]M,s  [2]M,s  where M should have finitely many states,
February 17, 2015Applied Discrete Mathematics Week 3: Algorithms 1 Double Summations Table 2 in 4 th Edition: Section th Edition: Section th.
Module B: Linear Programming
Copyright © 2010 Pearson Education, Inc. All rights reserved. 4.3 – Slide 1.
ECE 556 Linear Programming Ting-Yuan Wang Electrical and Computer Engineering University of Wisconsin-Madison March
Analysis of Algorithms
1 Prune-and-Search Method 2012/10/30. A simple example: Binary search sorted sequence : (search 9) step 1  step 2  step 3  Binary search.
Data Structure and Algorithms. Algorithms: efficiency and complexity Recursion Reading Algorithms.
Class Opener: Solve each equation for Y: 1.3x + y = y = 2x 3.x + 2y = 5 4. x – y = x + 3y = x – 5y = -3.
1 Searching and Sorting Searching algorithms with simple arrays Sorting algorithms with simple arrays –Selection Sort –Insertion Sort –Bubble Sort –Quick.
A Different Solution  alternatively we can use the following algorithm: 1. if n == 0 done, otherwise I. print the string once II. print the string (n.
Production Scheduling Lorena Kawas lk2551 Raul Galindo rg2802.
Ways to Check for Divisibility Dividing by 2 All even numbers are divisible by 2 Even numbers are numbers that end with either 2, 4, 6, 8, or 0.
Sullivan Algebra and Trigonometry: Section 12.9 Objectives of this Section Set Up a Linear Programming Problem Solve a Linear Programming Problem.
Various Problem Solving Approaches. Problem solving by analogy Very often problems can be solved by looking at similar problems. For example, consider.
Searching and Sorting Searching algorithms with simple arrays
The Transportation and Assignment Problems
Divide and Conquer.
Applied Discrete Mathematics Week 2: Functions and Sequences
Nonlinear Programming Prepared by Lee Revere and John Large
Modeling with Recurrence Relations
CSC 421: Algorithm Design & Analysis
CSC 421: Algorithm Design & Analysis
Analysis of Algorithms
Table of Contents Chapter 5 (What-If Analysis for Linear Programming)
Chapter 5 The Simplex Method
CSC 421: Algorithm Design & Analysis
Searching & Sorting "There's nothing hidden in your head the sorting hat can't see. So try me on and I will tell you where you ought to be." -The Sorting.
Enough Mathematical Appetizers!
Binary and Ternary Search
Types of Algorithms.
Bubble Sort Bubble sort is one way to sort an array of numbers. Adjacent values are swapped until the array is completely sorted. This algorithm gets its.
Binary Search Back in the days when phone numbers weren’t stored in cell phones, you might have actually had to look them up in a phonebook. How did you.
12 Systems of Linear Equations and Inequalities.
Dr. Arslan Ornek IMPROVING SEARCH
Algorithm design and Analysis
Simple linear equation
ALGEBRA II HONORS/GIFTED SECTION 3-4 : LINEAR PROGRAMMING
Applied Discrete Mathematics Week 6: Computation
Chapter 6: Transform and Conquer
Divide and Conquer Algorithms Part I
Algorithms and Problem Solving
Solving Recurrence Relations
Linear Programming Example: Maximize x + y x and y are called
Heuristic Minimization of Two Level Circuits
CSC 421: Algorithm Design & Analysis
Ch. 2: Getting Started.
Inside Microsoft Research
Unit 2: Computational Thinking, Algorithms & Programming
CSC 421: Algorithm Design & Analysis
Table Lookup Illustrated with Product Stress Testing
Branch-and-Bound Algorithm for Integer Program
Divide and Conquer Merge sort and quick sort Binary search
CS 2210 Discrete Structures Algorithms and Complexity
Multidisciplinary Optimization
Presentation transcript:

Incremental Problem Solving for CS1100 Karl Lieberherr

Incremental Problem Solving is Important in CS Comes under different names Incremental Development Iterative Development Staged Development Stepwise Refinement Problem Solving by Reduction or Simplification Divide and Conquer (as a special case) The theme is: start with a simple subproblem first, build your confidence with the simple subproblem, and then attack the next more complex subproblem. Iterate until you have the problem solved. Very useful for spreadsheet development and for query development and for problem solving in general.

Demonstrated with Problem 2 in Assignment 2 Look for a partial solution. Find a solution which satisfies conditions 1 to 4 (called a feasible solution). Once we have such a solution, we improve it also satisfying the maximization constraint. How can we find a feasible solution? Look at dependencies between variables. x2 influences x1 (x1=2*x2). x2 influences x4 (x4=x2-1 minimally satisfying condition 3). x2 influences x3 (sum must be 1000). So let’s start with giving x2 only 1 share: x2=1. x2 =1, x1 = 2, x4 = 0, x3 = 997 which gives a total of 1000. Success: A feasible solution. x1 x2 x3 x4 total 2 1 997 0 1000

Improve feasible solution We have only a partial solution to the problem: we have a feasible solution. But we must also maximize x4! Before we maximize x4 lets try to find a better x4, again solving a simpler problem. What if we add 1 to x2? Success: we found a better x4 (1 instead of 0). Check carefully that all constraints are satisfied including x3>x1+x2. x1 x2 x3 x4 total 4 2 993 1 1000

Can we repeat this? Let’s take a big jump, using the idea of binary search. x2 = 200. But now we left the region of feasibility. (x3>x1+x2 is violated). Let’s go in the middle: x2 = 100. We are back to feasibility. (x3>x1+x2 is satisfied) The correct maximum must be between 100 and 200. How can you find it? x1 x2 x3 x4 total 400 200 201 199 1000 x1 x2 x3 x4 total 200 100 601 99 1000

Linear Search versus Binary Search With linear search you try 101, 102, 103, … until you exit the feasible region. Why will you exit the feasible region at some point? Notice how the value for x3 monotonically decreases. So eventually, x3 will not get enough shares. With binary search you try 150, if it does not succeed you go again in the middle and try 125. If that is in the feasible region, you go into the middle again and try 137 or 138 etc. The linear search you can easily automate in Excel by dragging your formulas down the spreadsheet. Conditional formatting will tell you when to stop. Linear search works for this problem because we found a simple way to enumerate feasible solutions by incrementing x2 while in the feasible region.

Better Solution Use Excel to get intuition Generalize the problem: Solve the Problem for TotalShares. 1000 is one special case. Find maximum solutions satisfying all constraints. x2 x1= 2*x2 x4=x2-1 (minimally satisfy constraint) x3=x1+x2+1 (minimally satisfy constraint) TotalShares = 7*x2

Closed Form Solution (Through Excel Inspiration) No need for linear or binary search. Works if TotalShares >= 7. x2 = trunc(TotalShares/7) x1= 2*x2 x3= 3*x2+1+MOD(TotalShares,7) ; Third child gets remaining shares. x4= x2-1 Note that x1+x2+x3+x4=7*trunc(TotalShares/7)+mod(TotalShares,7)=TotalShares

Summary We solved the ShareDistribution problem in two incremental steps. First we solved the subproblem of finding feasible solutions which resulted in a systematic and efficient way to enumerate feasible solutions. We then used Linear Search or Binary Search to find the maximum feasible solution. Finally we came up with a closed form solution. We will utilize Incremental Problem Solving several times in this course.