170 likes | 179 Views
Learn the fundamentals of computer science, including understanding algorithms, problem-solving techniques, and the programming process.
E N D
King Fahd University of Petroleum & Minerals College of Computer Science & Engineering Information & Computer Science Department ICS102: Introduction To Computing Problem Solving 1
Today’s Class • What’s Computer Science? • What’s an Algorithm? • Problem solving techniques • Overview of computer programming process • Problem solving techniques
What is Computer Science? • It is the discipline that seeks to build a scientificfoundation for such topics as computer design, computer programming, information processing, and algorithmic solutions of problems. • A computer is a machine that stores data, interact with devices, execute programs, and provides computing capabilities to its users). • Computingis the execution of an “algorithm”. What is an Algorithm? A set of steps that define how a task is performed. In other words, it is an ordered set of unambiguous, executable steps that define a terminating activity. • Examples: • Make a list of all positive integers • Extract the first integer from the list
Algorithm • An algorithm can be represented using some sort of language, such as the flowcharts pseudocode (precisely defined textual structures) • An algorithm is abstract and it can be represented in many ways. • EXAMPLE: • Algorithm for converting from Celsius to Fahrenheit can be represented as • 1. F = (9/5) C + 32 (algebraic equation) • 2. “ Multiply the temperature reading in Celsius by 9/5 and then add 32 to the product”
Example: An algorithm for starting the car • To run the car, we follow the following steps: • Insert the key in ignition • Make sure transmission is in Park (or Neutral) • Depress the gas pedal • Turn key to start position • If engine starts within six seconds, release key to ignition position • If engine does not start in six seconds, release key and gas pedal, wait ten seconds, and repeat steps 3 through 6, but not more than five times • If the car does not start, call the garage
Programming Process • Computer program is a sequence of instructions to be performed by a computer. • Computer programming is the process of planning a sequence of steps for a computer to follow • Programming Process has the following three phases: • Problem-solving phase • Implementation phase • Maintenance phase
Programming Process • Problem-solving phase • Analysis and specification ( understand and define problem, and what is expected of solution) • General solution (algorithm: a logical sequence of steps that solves the problem) • Verification (Follow steps to make sure solution solves the problem) • Implementation phase • Concrete solution (Program in a Programming language) • Testing (make sure the program produces the desired results) • Maintenance phase • Use Program • Maintain Program (meet changing requirements)
Programming Process Analysis and Specification Concrete solution (Program) General solution (algorithm) Testing Verification Maintenance Phase Documentation: writing program documentation, and user manuals
Problem Solving • The purpose of writing a program is to solve a problem • The general steps in problem solving are: • Understand the problem • Dissect the problem into manageable pieces • Design a solution • Analyze the complexity of the algorithm • Consider alternatives to the solution and refine it • Implement the solution • Test the solution and fix any problems that exist
Problem Solving • Many software projects fail because the developer didn't really understand the problem to be solved • We must avoid assumptions and clarify ambiguities • As problems and their solutions become larger, we must organize our development into manageable pieces • This technique is fundamental to software development • In java, we will dissect our solutions into pieces called classes and objects, taking an object-oriented approach
Problem Solving Techniques • You follow algorithms every day in your life. So, we need to learn how to design algorithms not simply follow them. • So, what is Problem Solving Process? • 1. Analysis 2. Design • 3. Implementation 4. Testing • Some Strategies to solve problems • Ask questions • Look for things that are familiar • Means-Ends Analysis • Divide and Conquer
Strategies: Ask Questions • When you are given a problem, you ask questions (What, Why, When, and Where?) • In the context of programming • What do I have to work with (What is my data)? • What do the data items look like? • How much data is there? • How will I know when I have processed all the data? • What should my output look like? • How many times is the process going to be repeated? • What special error conditions might come up?
Strategies: Look for Familiar Things • Never reinvent the wheel • If a solution exists USE IT • Finding the daily high and low temperatures • is really the same problem as • Finding the highest and lowest grades on a test • Both problems can be abstracted as being • Find largest and smallest values in a set of numbers
Strategies: Means-Ends Analysis • Beginning state and End state are often given • You need to define a set of actions that can be used to get from one to the other • Once you have a set of actions, you need to work out the details • Translated to computer programming • Begin by writing down what the input is? (Beginning state) • What the output should be? (End state) • What actions can be performed to obtain results from input data?
Strategies: Divide and Conquer Break up large problems into smaller problems that are easier to handle (Top-Down approach) Hard problem Easy subproblem Hard subproblem Easy subproblem Easy subproblem Easy subproblem
An Example • Compute the area of a circle • Problem statement • We need an interactive program (user will input data) that computes the area of a circle. Given the circle radius, the circle area should be displayed on the screen • Input/Output description • Input Circle radius • Output Circle area • Algorithm development (set of steps, decomposition outline) • Read value of circle radius (r) • Compute circle area as pi* r2 • Print the value of circle area • How do we represent more complex algorithms • Pseudocode, flowcharts
Circle area Read radius Compute area Print circle area An Example (continued) A divide and conquer block diagram of our problem • Pseudocode • Prompt the user for the circle radius (put a message on the screen) • Read radius • Assign Circle area the value pi * radius2 • Write Circle area on the screen • Stop