
























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Algorithms in C,some examples and notes and interesting stuff
Typology: Lecture notes
1 / 32
This page cannot be seen from the preview
Don't miss anything!
Lecture 01: Problem Solving
◼ A new situation that presents some difficulty that one whishes to address ◼ “Whenever there is a gap between where you are now and where you want to be, and you don’t know how to find a way to cross that gap, you have a problem.”
◼ Read the problem completely ◼ Try out examples ◼ Ask questions
▪ What would the result look like? ▪ What are the assumptions and constraints? ◼ Use diagrams and notations ◼ Restate the problem ◼ Avoid assumptions
◼ Establish subgoals ◼ Try to recognize something familiar
▪ Recognize patterns ▪ Use analogy ▪ Apply existing strategies ◼ Introduce external elements ◼ Take cases (validate the plan)
◼ Be critical of your result ◼ Look for flaws in your solutions ◼ No deficiencies
▪ Use good test cases
◼ Work backwards ◼ Use existing models ◼ Solve by elimination ◼ Divide and conquer ◼ Recursion
◼ Most problems are just variations of existing problems ◼ Examples:
▪ Get the sum of all numbers from 1 to 100 ▪ Get the sum of all even numbers from 2 to 100
◼ Remove invalid options ◼ Example:
▪ What is the largest prime number less than 100?
◼ Find patterns that can be repeated
◼ Computers follow instructions exactly
▪ Consistently applies the steps provided to it ▪ Can repeat as many times without getting tired ▪ Can perform tasks with speed and accuracy ◼ Limitations of Computers
▪ Limited input ▪ Processes digital data only ▪ Instructions have to be clear and concise
Pseudocodes and Flowcharts
◼ A problem solving method suitable for implementation as computer program* ◼ Procedures or formulas to solve a problem ◼ Key properties:
▪ Interpretable ▪ Finite set of instructions ▪ Recognizable end-state, end-point or result
*R. Sedgewick, Algorithms in C , 3 rd^. Ed., Addison-Wesley Publishing Company, Inc., 1998
◼ Text-based representation of algorithms ◼ Notations from popular programming languages are used ◼ D0ne for human reading, not for machines ◼ No universal standard
◼ Graphical representation ◼ Different shapes mean different things ◼ Flow of the algorithm is shown by arrows
Input/Output
Process
Decision
Start/Stop