Problem Solving - Divide & Conquer

Slides:



Advertisements
Similar presentations
MapReduce.
Advertisements

CS252: Systems Programming Ninghui Li Program Interview Questions.
1 ICS102: Introduction To Computing King Fahd University of Petroleum & Minerals College of Computer Science & Engineering Information & Computer Science.
Michelle Koch For other treats around the holidays, visit:
Greedy Algorithms Greed is good. (Some of the time)
Baking Chocolate Chip Cookies Ms. Davis Life Skill Class July 11th, 2004.
White Chocolate Orange Cookies. 1 cup butter softened 1/2 cup white sugar 1/2 cup brown sugar 1 egg 1 tablespoon orange zest 2 1/4 cups all-purpose flour.
CS 206 Introduction to Computer Science II 10 / 15 / 2008 Instructor: Michael Eckmann.
Programming Fundamentals (750113) Ch1. Problem Solving
Problem Solving 101 DEFN An algorithm is a group of instructions (often expressed informally) for performing some task. DEFN An algorithm is a group of.
 Chapter 1: Why You Should Cook  Chapter 2: What’s Cooking  Chapter 3: Cooking VS. Crafting  Bonus Chapter: One Recipe  Chapter 4: Supplies You Will.
1.02 I Preparation Tasks List 11.02I Listing Preparation Tasks.
Baking Cookies English Club eats chocolate chip cookies!
Computer Science 121 Scientific Computing Winter 2014.
Problem Solving 101 DEFN An algorithm is a group of instructions (often expressed informally) for performing some task. DEFN An algorithm is a group of.
Lecture 10: Class Review Dr John Levine Algorithms and Complexity March 13th 2006.
Computer Science 101 Fast Searching and Sorting. Improving Efficiency We got a better best case by tweaking the selection sort and the bubble sort We.
SEARCHING UNIT II. Divide and Conquer The most well known algorithm design strategy: 1. Divide instance of problem into two or more smaller instances.
1 Computers Can’t Cook! Programming Methodology Girls Engaged in Math and Science, June 2012 Bri Chapman.
Computer Science & Engineering An Introduction (and Some Advanced Concepts Too!) Prof. Paul Sivilotti Dept. of Computer Science & Engineering The Ohio.
1.02 C Work Plans 1 The secret for success!. Why use a work plan? Helps meal preparation run smoothly Implement these steps: 1.02CWork Plans2 Steps 1-
The Algorithmic Model. What is Computer Science What is Programming Algorithms –Definition –Properties of Good Algorithms –Describing Algorithms –Examples.
Chapter 9 (modified) Abstract Data Types and Algorithms Nell Dale John Lewis.
Chapter 9 Abstract Data Types and Algorithms Nell Dale John Lewis.
Computer Science An Introduction and Some Advanced Concepts Too! Prof. Paul Sivilotti Dept. of Computer & Info. Science The Ohio State University
CSC 211 Data Structures Lecture 13
By: Lokman Chan Recursive Algorithm Recursion Definition: A function that is define in terms of itself. Goal: Reduce the solution to.
CS 61B Data Structures and Programming Methodology July 21, 2008 David Sun.
1 Pre-Exam Lecture 4 Final Examination is scheduled on Monday December 18th at 1:30PM in class 4 There are 8 questions with or without sub- parts and.
COSC 2007 Data Structures II Chapter 13 Advanced Implementation of Tables IV.
Introduction to design and analysis algorithm
How to Make Chocolate Chip Cookies
Chapter 9 Abstract Data Types and Algorithms Nell Dale John Lewis.
1 Introduction to design and analysis algorithm. 2.
CPS120: Introduction to Computer Science Sorting.
Algorithm Design Techniques, Greedy Method – Knapsack Problem, Job Sequencing, Divide and Conquer Method – Quick Sort, Finding Maximum and Minimum, Dynamic.
Computer Science Department
B/B+ Trees 4.7.
CSC 421: Algorithm Design & Analysis
CSC 421: Algorithm Design & Analysis
CS 315 Data Structures B. Ravikumar Office: 116 I Darwin Hall Phone:
Microsoft Official Academic Course, Microsoft Word 2013
CSC 421: Algorithm Design & Analysis
Teach A level Computing: Algorithms and Data Structures
Introduction to Data Structure
Definition In simple terms, an algorithm is a series of instructions to solve a problem (complete a task) We focus on Deterministic Algorithms Under the.
Building Java Programs
2008/12/03: Lecture 20 CMSC 104, Section 0101 John Y. Park
Funny robots Read the descriptions Draw the robot.
Problem Solving - Divide & Conquer
Programming Fundamentals (750113) Ch1. Problem Solving
COMP 208/214/215/216 Lecture 3 Planning.
Experimental Plan? Who needs a plan anyway??.
Welcome back to Software Development!
Welcome back to Software Development!
Problem Solving - Divide & Conquer
Programming Fundamentals (750113) Ch1. Problem Solving
CSC 421: Algorithm Design & Analysis
Incremental Problem Solving for CS1100
Programming Fundamentals (750113) Ch1. Problem Solving
Algorithms vs. Programming
CPS120: Introduction to Computer Science
Applications of Stacks and Queues
CPS120: Introduction to Computer Science
LPD Church of the Week We praise God for the smooth transition to two services and for the new faces we have seen as a result of increasing our capacity.
Human and Computer Interaction (H.C.I.) &Communication Skills
CSC 421: Algorithm Design & Analysis
Algorithm Course Algorithms Lecture 3 Sorting Algorithm-1
Algorithms vs. Programming
CPU Scheduling David Ferry CSCI 3500 – Operating Systems
Presentation transcript:

Problem Solving - Divide & Conquer

Problem Solving 101 example another Preheat oven to 350° F (175° C). DEFN An algorithm is a group of instructions (often expressed informally) for performing some task. example Preheat oven to 350° F (175° C). Beat in 2 eggs, then stir in vanilla (2t.). Dissolve 1t. of baking soda in hot water and add to mixture. Stir in salt (1/2t.), flour (3c.), chocolate chips (2c.), and chopped walnuts (1c.). 3) Bake in oven for 10 min. until edges are nicely browned The first example is a recipe for making chocolate chip cookies. The second is directions from Morris Hall to the La Crosse Center. Of course, the algorithms become more complicated for things like a recipe for a Thanksgiving Feast for 200 or the directions from GMH to the Louvre in Paris. This leads to the need for problem solving skills... another From 16th St. walk straight east on State St. for ten blocks 2) Continuing, State St. turns to a northeasterly direction just before 5th Ave. Continue in this direction for three blocks after 5th Ave. Turn left onto 2nd St. and walk south east for just under three blocks. The La Crosse Center is on your right.

Problem Solving 101 7 ± 2 Divide & Conquer Strategy An algorithm poses a solution to a problem, but how is this solution discovered? Step #1 - Recognize your limitations! 7 ± 2 George Miller (1956) “The Magical Number Seven, Plus or Minus Two: Some Limits on Our Capacity for Processing Information” The basic approach is a... Divide & Conquer Strategy http://cogprints.org/730/

Divide and Conquer Basic approach: Divide a problem into smaller subproblems then solve (conquer) the subproblems. Example: outlining a theme: how did I spend my summer vacation? I. What I did in June. II. What I did in July. III. What I did in August. This is the point of the Aesop fable.

Top-down Design Successively decompose algorithms into sub-algorithms and sub-algorithms into sub-sub-algorithms. Example: write a graphics program to draw the following image using lines, rectangles, and ovals

top level of design 1. Draw a top hat and head 2. Draw scarf 3. Draw middle body section 4. Lowest body section & surrounding snow 5. Draw trees in the background

next refinement 1. Draw a top hat and head 1.1 Draw hat 2. Draw scarf 3. Draw middle body section 4. Lowest body section & surrounding snow 5. Draw trees in the background 1.1 Draw hat 1.2 Draw purple hat ribbon 1.3 Draw head 1.4 Draw face 2.1 Draw scarf’s knot 2.2 Draw scarf fringes 2.3 Draw main portion of scarf 3.1 Draw center white body 3.2 Draw three buttons 3.3 Draw arms 4.1 Draw lowest body section 4.2 Draw surrounding snow 5.1 Draw trees to the left of snowman 5.2 Draw trees to the right of snowman

still more refinement 1. Draw a top hat 1.1 Draw main section of hat 2. Draw scarf 3. Draw middle body section 1.1 Draw main section of hat 1.2 Draw purple hat ribbon 1.3 Draw head 1.4 Draw face 2.1 Draw scarf’s knot 2.2 Draw scarf fringes 2.3 Draw main portion of scarf 3.1 Draw center white body 3.2 Draw three buttons 3.3 Draw arms 1.4.1 Draw left eye 1.4.2 Draw right eye 1.4.3 Draw nose 1.4.4 Draw mouth from 3 ovals 1.4.5 Draw pink cheek ovals Q: When do you stop refining? A: When the sub-tasks are simple enough to code. 3.2.1 Draw top green button (an oval) 3.2.2 Draw middle purple button (a square) 3.2.3 Draw botom blue button with snowflake on top

Design by Prototype A prototype is a partially-functional program. Software managers/customers like to see progress in software design. A second approach to software design is to use successive prototypes. A prototype is a partially-functional program. Successive prototyping is a staged design process moving from prototype to ever more capable prototype. Successive prototyping is another form of divide and conquer. Top-down design fails to demonstrate sufficient progress for many customers. Consider Ford Motor Co. who uses a small clay model, followed by a full-sized mockup, followed by a concept car taken to a Car Show, followed by the real car.

Successive Prototyping Example - creating new UW-L web pages Note how the customer sees progress at each stage. Note how the customer has considerable opportunity to provide input.

Successive Prototyping Example - creating new UW-L web pages prototype 1: A new UW-L home page with no working links prototype 2: A UW-L home page with working links to a second tier of pages prototype 3: A complete set of hyperlinked web pages without interactive forms prototype 4: All prototype 3 functionality plus an online, searchable directory of students and staff prototype 5: All prototype 4 functionality plus a page to permit students and staff to communicate email securely Note how the customer sees progress at each stage. Note how the customer has considerable opportunity to provide input. Successive prototyping works well for modern graphical user interfaces.

Divide and Conquer • useful for software design strategies (examples: top-down design, successive prototyping) • useful for software implementation approaches (examples: parallel supercomputers, distributed computing) • useful for algorithms... In 1998 DES Cracker (a $250K parallel computer) could crack DES keys in 3 days. In 1999 DES Cracker + 100,000 desktop computers crack DES in one day. Talk about distributed computations of PI.

Binary Search Binary search is a classic divide and conquer algorithm. Example: Suppose you are given an alphabetized stack of 1,000 transcripts. What is the most efficient way to look for your own transcript? linear search algorithm 1) Examine the top transcript in the stack and remove it. 2) Repeat Step 1 until your transcript is found or stack is empty. How many transcripts do you expect to examine be certain to emphasize the importance of alphabetization. Also point out that you don’t know anything about the stack, except alphabetization - no info on distribution. If your transcript is in the stack then we could expect it to be halfway through. ... if your transcript is not in the stack? ... if your transcript is in the stack?

Binary Search Example: Suppose you are given an alphabetized stack of 1,000 transcripts. What is the most efficient way to look for your own transcript? Example: binary search algorithm 1) Examine the middle transcript in the stack. 2) If your name alphabetically precedes the middle name from Step 1, then discard all transcripts after the middle. Otherwise, if your name alphabetically follows the middle, then discard all transcripts before the middle. Repeat the process on the remaining portion of the stack, until only one transcript remains. 1 - 500 transcripts remain 2 - 250 transcripts remain 3 - 125 transcripts remain 4 - 63 transcripts remain 5 - 32 transcripts remain 6 - 16 transcripts remain 7 - 8 transcripts remain 8 - 4 transcripts remain 9 - 2 transcripts remain 10 - 1 transcript remains Also, note that with binary search if the stack is twice the size it only take one additional probe. So the next time you look for a word in a dictionary ... START IN THE MIDDLE! There are similar D&C algorithms for sorting, etc., but you will need to study CS to see these.

Greedy Algorithms Example: “Pick the low-hanging fruit.” A greedy algorithm is any algorithm based on selecting the “best” options first. Example: “Pick the low-hanging fruit.” Another example: Suppose you want to pack the trunk of your car. In order to make best use of your limited trunk space, which bags should you pack first? Greedy divides the alternatives based on an “easiest first” strategy. The low hanging fruit maximizes the number of apples you can pick in a certain amount of time.

Greedy Algorithms An example scheduling algorithm: How should you schedule the order of network messages? Suppose the goal is to minimize the average time that a message must wait to be sent. The greedy algorithm: Service shorter messages first. Scheduling algorithms, like searching algorithms, are common in CS.

...service first messages first Example collection of five messages: message size time sent A 2 MB 0 B 10 MB 1 C 2 MB 2 D 3 MB 4 E 5 MB 6 Assume that the capacity of the network is 1 MB/sec. first come, first served algorithm 2 4 6 8 10 12 14 16 18 20 22 A B  C  D  Scheduling algorithms, like searching algorithms, are common in CS. E  total wait time = 0 + 1 + 10 + 10 + 11 = 32 sec. average wait time = 32/5 = 6.4 sec.

...service shorter messages first Example collection of five messages: message size time sent A 2 MB 0 B 10 MB 1 C 2 MB 2 D 3 MB 4 E 5 MB 6 Assume that the capacity of the network is 1 MB/sec. greedy algorithm 2 4 6 8 10 12 14 16 18 20 22 A B  C D E  total wait time = 0 + 11 + 0 + 0 + 1 = 12 sec. average wait time = 12/5 = 2.4 sec.