Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 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 instructions (often expressed informally) for performing some task. example 1)Preheat oven to 350° F (175° C). 2)Cream together butter (1c.), sugar (1c.), brown sugar (1c.). 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 another 1)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. 3)Turn left onto 2nd St. and walk south east for just under three blocks. The La Crosse Center is on your right.

2 Problem Solving 101 An algorithm poses a solution to a problem, but how is this solution discovered? Two basic approaches are... Step #1 - Recognize your limitations! http://cogprints.org/730/

3 Divide and Conquer Basic approach: Divide a problem into smaller subproblems then solve (conquer) the subproblems. Example: outlining a theme “How I Spent Summer Vacation” I. What I did in June. II. What I did in July. III. What I did in August. A. the plane flight from La Crosse to Wuhan, China B. the initial meeting with students and faculty C. Chinese living arrangements A. a typical day in the life of a professor in China B. tour southeast Asia before returning to the U.S. A. the flight back to La Crosse B. a visit to the daughter in Connecticut 1. Guillin, China 2. Vietnam 3. Cambodia 4. Thailand

4 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

5 Design by Prototype Software managers/customers like to see progress in software design. A second approach to software design is to use successive prototypes. A prototype is ___________________. Successive prototyping is a staged design process moving from prototype to ever more capable prototype. Successive prototyping is another form of divide and conquer.

6 Binary Search Binary search is a classic divide and conquer algorithm. Suppose you are given an alphabetized stack of 1,000 transcripts. What is the most efficient way to look for your own transcript? Example: 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... if your transcript is not in the stack?... if your transcript is in the stack?

7 Greedy Algorithms Not every algorithm is a divide and conquer style. A greedy algorithm is any algorithm based on _____________________.

8 ...service first messages first messagesizetime sent A2 MB 0 B10 MB 1 C2 MB 2 D3 MB 4 E 5 MB 6 Example collection of five messages: Assume that the capacity of the network is 1 MB/sec. 0246810121416182022 A B C D E first come, first served algorithm total wait time = 0 + 1 + 10 + 10 + 12 = 23 sec. average wait time = 23/5 = 4.6 sec. median wait time = 10 sec.

9 0246810121416182022...service shorter messages first messagesizetime sent A2 MB 0 B10 MB 1 C2 MB 2 D3 MB 4 E 5 MB 6 Example collection of five messages: Assume that the capacity of the network is 1 MB/sec. A B C D E total wait time = 0 + 12 + 0 + 0 + 2 = 14 sec. average wait time = 14/5 = 2.8 sec. median wait time = 2 sec. greedy algorithm


Download ppt "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."

Similar presentations


Ads by Google