Download presentation
Presentation is loading. Please wait.
1
4. Computational Problem Solving
Yusung Kim
2
Motivation The first electronic computers were referred to as “Electronic Brains”. Computer = Powerful + Stupid Execute a series of instructions very quickly (billions of operations per second) No more intelligence than what it is instructed to do (nothing like insight or understanding) How to make computers useful ?
3
How does a computer work ?
Computer is driven by code instructions Instructions simple such as “add two numbers” The computer runs a long series of instructions code computer Instruction1 (1+2) Instruction2 2 < 10 ? Instruction3 … instruction4 Instruction5 …
4
How to get an useful code ?
Human thinks of a useful feature Break a problem down Think up a good algorithm (steps) Write codes for the computer Code is like lego bricks Individual pieces are very simple Eventually build up great combinations
5
Computational Problem Solving
Computational problem solving lets computers be able to solve a problem. To perform computational problem solving, we need to do; problem analysis that identifies the main problem a representation that captures all the relevant aspects of the problem an algorithm that is a set of step-by-step operations to solve the problem
6
Problem Analysis Identifying the main problem and establishing the causes and effects related to that problem. What is the problem? Why does the problem exist? Who is causing the problem, and who is affected by it? When did the problem first occur or when did it become significant?
7
Problem Analysis Tools
fishbone diagram problem tree
8
Abstraction A representation that leaves out detail of what is being represented is a form of abstraction. Abstraction is prevalent in the everyday world. For example, maps are abstract representations.
9
Below is the original 1908 map of the London Subway
10
Below is a more abstract, but topologically correct
Below is a more abstract, but topologically correct. It shows the bends and curves of each track. This map contains too much information for its purpose—that is, to find out where each subway line leads, and where the connections are between lines.
11
This particular abstraction is still in use today.
12
Decomposition Breaking a complex problem or system into parts that are easier to conceive, understand, program, and maintain.
13
Algorithm A set of rules for solving a problem in a finite number of steps with given input and output.
14
Problem Solving Example: Man, Cabbage, Goat, Wolf
A man lives on the east side of a river. He wishes to bring a cabbage, a goat, and a wolf to the west side of the river to sell. However, his boat is only big enough to hold himself, and either the cabbage, goat, or wolf. In addition, the man cannot leave the goat alone with the cabbage because the goat will eat the cabbage, and he cannot leave the wolf alone with the goat because the wolf will eat the goat. How to solve this problem?
15
Abstraction Example What would be an appropriate representation for this problem? Representation should include only the aspects of the problem that are relevant for its solution. Color of the boat? Name of the man? Width of the river? Speed of the boat? The only information relevant for this problem is where each particular item is at each step in the problem solving. Therefore, by the use of abstraction, we define a representation that captures only this needed information.
16
The relevant, minimal representation is a sequence to indicate where each object currently is,
man cabbage goat wolf [east, west, east, west] The first item in the sequence is the location of the man, the second is the location of the cabbage, etc.
17
to the goal state (all objects on the west side of the river),
The actual problem is to determine how the man can row objects across the river, with certain constraints. The computational problem is to find a way to convert the start state of the problem (all is on the east side of the river), man cabbage goat wolf [ E , E , E , E ] to the goal state (all objects on the west side of the river), [ W , W , W , W ] with the constraint that invalid states should never be used.
18
Decomposition Example
A man wants to row a cabbage, a goat, and a wolf across a river. Select a single object (or nothing) Check validation of given constraints Row the selected object a river
19
Algorithm Example start select an object check validation
no (invalid) check validation yes(valid) cross the river check final state no yes end
20
Examine Algorithm For example, from the start state, there are three possible moves that can be made, only one of which results in a valid state. man cabbage goat wolf [E, E, E, E] START STATE [W, E, W, E] Man rows goat across VALID STATE Cabbage left alone with wolf [W, E, E, W] Man rows wolf across INVALID STATE Cabbage left alone with goat [W, W, E, E] Man rows cabbage across INVALID STATE Goat left alone with wolf
21
Therefore, we continue searching from the current state.
We check if the current state is the goal state. If true, then we solved the problem. Otherwise, keep going. man cabbage goat wolf [E, E, E, E] START STATE [W, E, W, E] CURRENT STATE Man rows goat across Is it goal state [W,W,W,W]? No Therefore, we continue searching from the current state.
22
There are only two possible options from here,
man cabbage goat wolf [W, E, W, E] CURRENT STATE [E, E, E, E] Man rows goat across VALID STATE But, this is same to the START STATE. No progress made! [E, E, W, E] Man rows back alone VALID STATE Goat left alone
23
This would continue until the goal state is reached,
man cabbage goat wolf [E, E, W, E] [W, W, W, W] GOAL STATE As reaching the goal state, we can find a solution of the actual problem. .
24
The Limits of Computational Problem Solving
Once an algorithm for a given problem is developed or found, an important question is “can a solution to the problem be found in a reasonable amount of time?” “But aren’t computers very fast, and getting faster all the time?” Yes, but some problems require an amount of time to compute a solution that is astronomical compared to the capabilities of current computing devices. Let’s see a classic problem in computer science, the Traveling Salesman Problem (TSP).
25
Problem Solving Example #2. The Traveling Salesman Problem
A salesman needs to visit a set of cities. He wants to find the shortest route of travel that visits each city exactly once and returns to the origin city. You may simply try all possible combinations of routes, and find the shortest one. (called “a brute-force approach”) for a given set of cities, how many possible routes are there?
26
How big the number is as increasing the number of cities?
If we consider a route to be a specific sequence of names of cities, then how many permutations of that list are there? New York, Boston, Chicago, San Francisco, Los Angeles, Atlanta Boston, New York, Chicago, San Francisco, Los Angeles, Atlanta Chicago, Boston, New York, San Francisco, Los Angeles, Atlanta …. Mathematically, the number of permutations for n entities is n! (n factorial). How big the number is as increasing the number of cities?
27
Assume: a computer could compute one million routes per second.
For Example; Ten Cities : 10! 3,628, 800 (over three million) Twenty Cities : 20! 2,432,902,008,176,640,000 Fifty Cities : 50! Over 1064 Assume: a computer could compute one million routes per second. For ten cities, it would take 3.6 seconds For twenty cities, it would take 77,000 years For fifty cities, it would take longer than the age of the universe! For problems such as the Traveling Salesman Problem (TSP), a brute-force approach is impractical to use. More clever and more efficient problem-solving methods must be discovered to find either an exact or an approximate solution to the problem.
28
Backup slides
29
Problem Solving #3. Searching
Searching a given name in a phone book. tens of million names Names are sorted Sequential searching (starting form the first/last page) Worst case ? Average case ? Binary searching (1) Open to middle of book, and look at the name (2) Look at the page (3) if the name is in the page, call him (her) (4) if the name is earlier in book, open to middle of left half of book; go to (2) (5) if the name is later in book, open to middle of right half of book; go to (2)
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.