Upload
nurulamierah1996
View
235
Download
0
Embed Size (px)
Citation preview
8/11/2019 Chapter 2: Introduction to Problem Solving
1/25
TOPIC 2:INTRODUCTION TO PROBLEM
SOLVING USING COMPUTER
CSC118 Fundamental of Algorithm Development
8/11/2019 Chapter 2: Introduction to Problem Solving
2/25
Objective overview
At the end of this chapter, student should beable to:
Describe typical Real World ProblemSolving Define what is Algorithm
Represent Algorithm and Logical Thinking
8/11/2019 Chapter 2: Introduction to Problem Solving
3/25
Contents
1. What is problem?2. Types of problem
3. Typical Real World Problems Solving4. Algorithm
1. What is Algorithm?
2. History of Algorithm3. Algorithm and logical thinking4. Problem Solving using different algorithms
http://rds.yahoo.com/_ylt=A0S0201idWVKMC0BN0GJzbkF;_ylu=X3oDMTBxbDR0ZjAyBHBvcwM1BHNlYwNzcgR2dGlkA0kxMTBfMTMx/SIG=1emfjk4uq/EXP=1248249570/**http%3A//images.search.yahoo.com/images/view%3Fback=http%253A%252F%252Fimages.search.yahoo.com%252Fsearch%252Fimages%253Fp%253Dalgorithm%2526ei%253DUTF-8%2526fr%253Dyfp-t-151%26w=320%26h=240%26imgurl=www.algorithm.com%252Falgorithm%252Falg1000b.jpg%26rurl=http%253A%252F%252Fwww.algorithm.com%252Falgorithm%26size=8k%26name=alg1000b%2Bjpg%26p=algorithm%26oid=25eafb9f2c919c28%26fr2=%26no=5%26tt=380294%26sigr=112s0qop5%26sigi=118ernsj8%26sigb=12e9k3ejr8/11/2019 Chapter 2: Introduction to Problem Solving
4/25
1. What is problem?
A problem , can be caused for different reasons,and usually can be solved in a number of
different ways.
8/11/2019 Chapter 2: Introduction to Problem Solving
5/25
2. Types of problem
Knowledge-Lean Problems: Can be solved(though not always skillfully) by use ofinstructions for the task and general problem
solving skillse.g., finding a parking space in the mall,shampooing hair
Knowledge-Rich Problems : Requires specificknowledge or skill to solve the probleme.g., calculus, computer-programmingproblems
8/11/2019 Chapter 2: Introduction to Problem Solving
6/25
3. Typical Real World Problems Solving
6 Steps in Problem Solving:1. _______ the problem2. __________ the problem3. Identify ____________ to solve the problem4. _________________ to solve the problem
from the list of alternative solutions
5. ________________ that enable you to solvethe problem by the selected method.
6. _____________ the solution
8/11/2019 Chapter 2: Introduction to Problem Solving
7/25
Example:a. Identify the problem. hungryb. Understand the problem Skip breakfastc. Identify alternative ways to solve
the problem.1. prepares a sandwich2. prepares instant noodle3. buy a food4. ask friends food
d. Select the best way to solve theproblem from the list ofalternative solutions.
2. prepares instant noodle
e. List instruction that enable youto solve the problem by theselected method.
1. take a kettle2. Put the water in it until it is halfway full.3. boil the water4. open the drawer5. get a packet of instant noodle6. take a bowl7. open the packet of instant noodle8. put the noodles into a bowl9. add the flavor pack10. wait until water is boil11. put the boiled water into a bowl
12. wait for 2 minutesf. Evaluate the solution Still feel hungry?
8/11/2019 Chapter 2: Introduction to Problem Solving
8/25
Typical Real World Problems Solving
Problems Example
Transaction ATM Machine, Web Application
Decision Making Forecasting
Control problems Traffic Controller
Searching problems Search Engines
Sorting problems Transport Schedule
8/11/2019 Chapter 2: Introduction to Problem Solving
9/25
Transaction: ATM Machine
How to draw your money at ATM machine?
1. Insert ATM card in ATM machine2. Choose a language3. Enter pin number of your ATM card4. Choose a withdrawal process5. Enter the amount of money you want to
withdraw6. Take your ATM card. Wait for your money and
transaction slip to come out.
8/11/2019 Chapter 2: Introduction to Problem Solving
10/25
Transaction: Web Application
How to browse a related web page?
1. Switch on the computer2. Wait until windows is display
3. Click the browser4. Wait until the web page is display. Then enter a domain
name/web address.5. Wait until related web page is display. Then browse the
web6. If the sources are not related, enter another domain
name.7. Repeat step 5 to step 6 until the sources are complete8. Close the web .
8/11/2019 Chapter 2: Introduction to Problem Solving
11/25
Decision Making: Forecasting
1. Look at the weather situation.1.1 If weather is raining then
Watch the television in the house.1.2 If weather is not raining then
Go out play football.
1. Look at the weather situation.1.1 If weather is raining then
Watch the television in the house.1.2 ELSE
Go out play football
8/11/2019 Chapter 2: Introduction to Problem Solving
12/25
Question:
There are 20 balloons that colored red andyellow. You have to drop the balloons one byone into the appropriate box; the yellowballoon belongs in the yellow box and the redballoon belongs in the red box.
Control Problem: Traffic Controller
8/11/2019 Chapter 2: Introduction to Problem Solving
13/25
Answer:
1. Repeat 20 times.1.1 Take one balloon.
1.1.1 If the balloon is red
Drop the balloon in the red box1.1.2 If the balloon is yellow
Drop the balloon in the yellow box
8/11/2019 Chapter 2: Introduction to Problem Solving
14/25
Searching Problems: Search Engines
How to browse a related web page?
Answer:1. Input keyword in search engine
2. Check the key word with web address2.1 If keyword is match then
Display the web address
3. Repeats step 2 until all the web address is check
8/11/2019 Chapter 2: Introduction to Problem Solving
15/25
Sorting Problems:
1. Copy the contents of cell A to temp.2. Copy the contents of cell B to cell A.3. Copy the contents of temp to cell B.
5 4Cell A temp Cell B
http://rds.yahoo.com/_ylt=A0S020yYdWVK8R0B4GKJzbkF;_ylu=X3oDMTBxNGR2bWdjBHBvcwM3BHNlYwNzcgR2dGlkA0kxMTBfMTMx/SIG=1hqm8chi4/EXP=1248249624/**http%3A//images.search.yahoo.com/images/view%3Fback=http%253A%252F%252Fimages.search.yahoo.com%252Fsearch%252Fimages%253Fp%253Dalgorithms%2526fr%253Dyfp-t-151%26w=389%26h=215%26imgurl=www.medical.philips.com%252Fus%252Fproducts%252Fcardiography%252Fassets%252Fimages%252Falgorithms%252Falgorithms.jpg%26rurl=http%253A%252F%252Fwww.medical.philips.com%252Fus%252Fproducts%252Fcardiography%252Falgorithms%26size=33k%26name=algorithms%2Bjpg%26p=algorithms%26oid=0a1e7ffcdd71f9ae%26fr2=%26no=7%26tt=240105%26sigr=122aqj96h%26sigi=12o3jnjo6%26sigb=1260mmrg48/11/2019 Chapter 2: Introduction to Problem Solving
16/25
4. What is Algorithm?
Definition:
A step by step problem solving procedure.A sequence of instructions that tell how to solve aparticular problem.A set of precise instructions for perform a computationor for solving a problem.A computable set of steps to achieve a desired result.A step by step sequence of precise instructions that mustterminates and describes how the data is processes toproduce the desired output.
No generally accepted definition.From natural languages to programming languagesCan be expressed in any language
http://rds.yahoo.com/_ylt=A0S020yYdWVK8R0B4GKJzbkF;_ylu=X3oDMTBxNGR2bWdjBHBvcwM3BHNlYwNzcgR2dGlkA0kxMTBfMTMx/SIG=1hqm8chi4/EXP=1248249624/**http%3A//images.search.yahoo.com/images/view%3Fback=http%253A%252F%252Fimages.search.yahoo.com%252Fsearch%252Fimages%253Fp%253Dalgorithms%2526fr%253Dyfp-t-151%26w=389%26h=215%26imgurl=www.medical.philips.com%252Fus%252Fproducts%252Fcardiography%252Fassets%252Fimages%252Falgorithms%252Falgorithms.jpg%26rurl=http%253A%252F%252Fwww.medical.philips.com%252Fus%252Fproducts%252Fcardiography%252Falgorithms%26size=33k%26name=algorithms%2Bjpg%26p=algorithms%26oid=0a1e7ffcdd71f9ae%26fr2=%26no=7%26tt=240105%26sigr=122aqj96h%26sigi=12o3jnjo6%26sigb=1260mmrg48/11/2019 Chapter 2: Introduction to Problem Solving
17/25
8/11/2019 Chapter 2: Introduction to Problem Solving
18/25
8/11/2019 Chapter 2: Introduction to Problem Solving
19/25
Input and Output:Algorithm receives input and produces theoutput.Unambiguous:Step in algorithm must be clear as to what it issupposed to do and how many times it is
expected to be executed.Correct and Efficient:An algorithm should produce the correct and
efficient output values for each set of input values.Finite :It must execute its instruction and terminate in afinite time.
8/11/2019 Chapter 2: Introduction to Problem Solving
20/25
Algorithmic solutions is a series of actions /steps (algorithm) to solve a problem.
Heuristic solution is a solution that cannot bereached through a direct of steps and requirereasonable built on knowledge andexperience. (AI)
8/11/2019 Chapter 2: Introduction to Problem Solving
21/25
History of AlgorithmThe word algorithmis derived from the nameof the Persian mathematician Al-Khwarizmi (Abu Abdullah Muhammad Ibn Musa Al-Khwarizmi or Abu Jafar Muhammad. (A.D. 780 850))Known as Father of Aljebra because of his
extensive work in algebra.He is great muslim mathematician, astronomerand geographer.One of the his books is base 10 positionalnumbering systems that developed in IndiaThe books described formalized, step by stepprocedures for doing arithmetic operation likeaddition, subtraction and multiplication and
introduced decimal system.
http://www.historymania.com/american_history/Al-Khwarizmihttp://rds.yahoo.com/_ylt=A0S020lrEWRKR.4AftuJzbkF;_ylu=X3oDMTBydDE2OGg2BHBvcwMxOARzZWMDc3IEdnRpZANJMTEwXzEzMQ--/SIG=1he84qnl3/EXP=1248158443/**http%3A//images.search.yahoo.com/images/view%3Fback=http%253A%252F%252Fimages.search.yahoo.com%252Fsearch%252Fimages%253Fp%253Dal-khwarizmi%2526ei%253DUTF-8%2526fr%253Dfptb-msgr-151%26w=240%26h=150%26imgurl=www.uni-due.de%252Fmathematik%252Fglaubitz%252Fupload%252Fal-khwarizmi%252520.jpg%26rurl=http%253A%252F%252Fwww.uni-due.de%252Fmathematik%252Fglaubitz%252Fpages%252Fforschung2.php%26size=44k%26name=al%2Bkhwarizmi%2Bjpg%26p=al-khwarizmi%26oid=67019c486fbca13a%26fr2=%26no=18%26tt=260%26sigr=11uj85jru%26sigi=11tq4vb9j%26sigb=12labvjtdhttp://rds.yahoo.com/_ylt=A0S020lrEWRKR.4Ad9uJzbkF;_ylu=X3oDMTByNjJjZTY3BHBvcwMxMQRzZWMDc3IEdnRpZANJMTEwXzEzMQ--/SIG=1g5tmb520/EXP=1248158443/**http%3A//images.search.yahoo.com/images/view%3Fback=http%253A%252F%252Fimages.search.yahoo.com%252Fsearch%252Fimages%253Fp%253Dal-khwarizmi%2526ei%253DUTF-8%2526fr%253Dfptb-msgr-151%26w=268%26h=326%26imgurl=www.cs4fn.org%252Ffundamentals%252Fimages%252FAl-Khwarizmi.jpg%26rurl=http%253A%252F%252Fwww.cs4fn.org%252Ffundamentals%252Falgorithms.php%26size=35k%26name=Al%2BKhwarizmi%2Bjpg%26p=al-khwarizmi%26oid=15296e665f41b0f8%26fr2=%26no=11%26tt=260%26sigr=11gns9pbp%26sigi=11inj7v2c%26sigb=12labvjtdhttp://rds.yahoo.com/_ylt=A0S020lrEWRKR.4AdNuJzbkF;_ylu=X3oDMTBxdHZyM2NlBHBvcwM4BHNlYwNzcgR2dGlkA0kxMTBfMTMx/SIG=1i06ghskk/EXP=1248158443/**http%3A//images.search.yahoo.com/images/view%3Fback=http%253A%252F%252Fimages.search.yahoo.com%252Fsearch%252Fimages%253Fp%253Dal-khwarizmi%2526ei%253DUTF-8%2526fr%253Dfptb-msgr-151%26w=300%26h=401%26imgurl=www.brianzapopolare.it%252Fimmagini%252Fpersonaggi%252Fal_khwarizmi_300x401.jpg%26rurl=http%253A%252F%252Fwww.brianzapopolare.it%252Fsezioni%252Fscienza%252F20080413_islam_civilta_occidentale.htm%26size=44k%26name=al%2Bkhwarizmi%2B300...%26p=al-khwarizmi%26oid=77a66e3504a91158%26fr2=%26no=8%26tt=260%26sigr=12kv9j3do%26sigi=123su5jkd%26sigb=12labvjtdhttp://www.historymania.com/american_history/Al-Khwarizmihttp://www.historymania.com/american_history/Al-Khwarizmihttp://www.historymania.com/american_history/Al-Khwarizmi8/11/2019 Chapter 2: Introduction to Problem Solving
22/25
Linear Search
SimpleCompare with key valueUseful for small and unsorted arrays.
Binary SearchFor sorted array.Compare middle elements with key.Like find a page number from a book.If key = match found. If key < middle looks in first half of array. If key > middle looks in last half of array.
Linear Search & Binary Search
8/11/2019 Chapter 2: Introduction to Problem Solving
23/25
Searching examines 10, 4, 5 and 11.
Linear Search
10 4 5 11 2 8 25E.g.1 Searching for the value 2
Searching examines 10, 4, 5, 11, 2, 8, and 25.
10 4 5 11 2 8 25
E.g.2 Searching for the value 35
8/11/2019 Chapter 2: Introduction to Problem Solving
24/25
Searching examines 8 and stops.
Binary Search
2 4 5 8 10 11 25E.g.1 Searching for the value 8
Searching examines 8 and 4.
2 4 5 8 10 11 25E.g.2 Searching for the value 5
Searching examines 8, 11 and 25.
2 4 5 8 10 11 25E.g.3 Searching for the value 49
8/11/2019 Chapter 2: Introduction to Problem Solving
25/25
The End