1 / 92

Unit I Problem Solving Concepts

Learn about problem-solving concepts, decision-making, and strategies in everyday life with Prof. A.R. Bramhecha. Discover six essential steps for making the best decisions, types of problems and approaches, algorithmic vs. heuristic solutions, problem-solving with computers, and difficult aspects in problem-solving. Explore key problem-solving concepts for computers, constants, variables, data types, and rules for data types. Enhance your problem-solving skills with practical examples and insights provided by Prof. A.R. Bramhecha.

isaacj
Download Presentation

Unit I Problem Solving Concepts

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Unit IProblem Solving Concepts PROF.A.R.BRAMHECHA

  2. Problem Faced in Everyday in Life • People make decisions everyday • Examples: • Should I wear casual or formal today? • Should I watch TV or go out to cinema? • what career? • what course? • What shoes? • Everything needs a DECISION AS A SOLUTION TO THE PROBLEM • What happens when bad decisions are made? • WASTAGE OF TIME AND RESOURCES PROF.A.R.BRAMHECHA

  3. Six steps to ensure a Best decision in PROBLEM SOLVING • Identify the problem • Understand the problem • Identify alternative ways to solve the problem • List instructions that enable you to solve the problem using selected solution • Select the best way to solve the problem from the list of alternative solutions • Evaluate the solution PROF.A.R.BRAMHECHA

  4. What makes a good decision? • Well identified problem • All alternatives considered • Information overloaded – appropriate alternatives • Can the person carry out steps/instructions PROF.A.R.BRAMHECHA

  5. Types of Problem • Approaches to solve a problem: • Algorithmic • Heuristic • Solutions that can be solved with a series of known actions are called Algorithmic Solutions. • Employing a self-learning approach to the solution of a problems is known as Heuristic Solutions . PROF.A.R.BRAMHECHA

  6. Examples Algorithmic solution: • To make a cup of coffee • To find largest of three numbers Heuristic solutions: • how to buy the best stock? • How to play chess? PROF.A.R.BRAMHECHA

  7. Problem solving with computers Computers use algorithmic solutions • Solution- set of instructions that make up solution to a problem • Program– set of instructions that make up solution after coding in a computer language • Results– outcome of running the program • Testing– Are the outcomes what you expected and correct People are better at developing heuristic solutions Artificial Intelligence: Computer deals with heuristic problems PROF.A.R.BRAMHECHA

  8. Difficulties with Problem Solving • Some have not been taught how to solve problem • Afraid to make decision • Complete steps inadequately: • Not define problem correctly • Not generate a sufficient list of alternatives • Not able to fine good alternative or list pros & cons • Focus on details before framework for solution is in place • Writing Instructions PROF.A.R.BRAMHECHA

  9. The Problem Solving Aspects 1. Problem definition phase -Workout what must be done rather than how to do 2. Getting started on a problem -Workout on implementation independent solution 3. The use of specific examples -Use props & heuristics(i.e. rules of thumb) -Workout the mechanism -Ex. To find maximum in the set of no. 4. Similarities among problems -Independently solve the problem PROF.A.R.BRAMHECHA

  10. 5. Working backwards from the solution 6. General problem solving strategies -Divide & conquer -Dynamic Programming greedy search ,backtracking, branch & bound 21/06/2018 PROF.A.R.BRAMHECHA 10

  11. Problem solving concepts for computers • Constants • Variables • Operators • Hierarchy of operations • Data types • Equations • Functions • Expressions PROF.A.R.BRAMHECHA

  12. Constant: • A variable whose value is determined when a program description is written and doesn’t change from that value during program execution. • It can be any data type – numeric , alphabetic or special symbols • Memory location & name is given • Ex:PI=3.142857 Rules: Constant cannot be changed after it is initially given a value PROF.A.R.BRAMHECHA

  13. Variable or Identifier: • Named location in memory for storing data. • Variables are values that can change as much as needed during the execution of a program. Ex: ShoeCost = 250 , city=“chennai” • Referred by name in the instructions. • Naming Conventions for Variables Rules PROF.A.R.BRAMHECHA

  14. OUTPUT INPUT Information PROCESS Data Data vs. Information Processed meaningful report Unorganized facts PROF.A.R.BRAMHECHA

  15. Data Types: • A type is the “kind” of data that variable is allowed to hold. • Data Types and Their Data Sets PROF.A.R.BRAMHECHA

  16. Character Data - Alphanumeric Data -Single digit number,letter & special characters eg. ‘a’ , ‘A’, ‘Z’, ‘4’, ‘#’ ,’*’ - String – collection of characters eg. “A”, “Sinhgad” , “123” • Logical Data - Two Values : True and False. • Other Data Type - date data type -User defined data type PROF.A.R.BRAMHECHA

  17. Rules for Data Types • value of a variable or a constant -data types: numeric, character (including character string), or logical. • Designates the data type during the programming process. • Data types cannot be mixed. • Each of the data types uses a data set - Numeric data : base 10 , the plus sign (+), and negative sign (-) - Character data: Characters - Logical data : True and False.. • Any numeric item that must be used in calculations resulting in a numeric result PROF.A.R.BRAMHECHA

  18. What is wrong with these variables names? The name of a city -> City Name A Client name -> Client-name City and state-> City/State A last name -> LN A Quantity -> Q A Street address -> Street Address Student Roll Number -> Roll No. Accept two Numbers -> Num 1 Num 2 PROF.A.R.BRAMHECHA

  19. Functions • Small sets of instructions that perform specific tasks and return values • Specify the basic tasks that are used repeatedly in the problem-solving process thus reducing time and improve the readability of the solution. • Function name(data) • Data used by the function are called parameters • Ex:sqrt(n),max(n1,n2,n3) • Divided into classes Types of Functions • Mathematical function: sqrt(n) ,abs(n),sign(n) • String function: Left(S,n),right(S,n),Length(S) • Conversion function: String(N),Value(S) • Statistical function: Average(list), Max(list), Sum(list) • Utility function: Date,Time,Error PROF.A.R.BRAMHECHA

  20. Operators • Operators are symbols that indicate some kind of action is to be performed. • Data connectors within expressions and equations • Tell the computer how to process the data • What type of processing needs to be done • OPERANDS- data that the operator connects and processes • RESULTANT-answer of the operation. PROF.A.R.BRAMHECHA

  21. Mathematical Operators PROF.A.R.BRAMHECHA

  22. Relational Operators Logical Operators PROF.A.R.BRAMHECHA

  23. Hierarchy of operations • Functions • Power • %,*,/ • +,- • =,<,>,<=,>=.<> • NOT • AND • OR Examples: (Hours – 40) * Wage * 1.5 F = 6 * 2 \ 6 + 2 F = 6 * 2 \ (6 + 2) F = 6 * (2 \ (6 + 2)) PROF.A.R.BRAMHECHA

  24. EXPRESSION: • An expression is a code segment that can be evaluated to produce a single value. • Processes the data, the operands through the use of operators. ex: A + B , A>B, A<=B EQUATIONS: • stores the result of an expression in a memory location in the computer through the = sign. ex: C=A + B , C=A>B , C=A<=B PROF.A.R.BRAMHECHA

  25. Examples: 1: Setting Up a Numeric Expression =>X * (3 * Y + 4) - 4 * Y / (X + 6) 2: Setting Up a Mathematical Equation Y + 3 = X (Z + 5) => Y = X * (Z + 5) – 3 3: Setting Up a Relational Expression X is less than Y + 5 => X < Y + 5 4: Setting Up a Logical Expression customer must have a driver’s license (A) or a check-cashing card (B) on file at the store => A|| B PROF.A.R.BRAMHECHA

  26. 5: Evaluating a Mathematical Expression x = 4 and b = 3 Area = x2 + x/2 * b 4 4 1: 42 = 16 1 3 2: 4/2 = 2 2 3: 2*3 = 6 16 4: 16 + 6 = 22 2 3 4 6 22 PROF.A.R.BRAMHECHA

  27. 6:Evaluating a Relational Expression A - 2 > B A = 6 B = 8 6 8 1:6 – 2 = 4 1 2:4 > 8 False 4 2 False PROF.A.R.BRAMHECHA

  28. 7: Evaluating a Logical Expression A && B || C && A A = True B = False C = True 1:True && False = False False True True True 1 2 2:True && True = True False True 3: Result1 || Result2 = True 3 True PROF.A.R.BRAMHECHA

  29. 8:Evaluating an Equation That Uses Both Relational and Logical Operators F = !(A < B) AND (C OR D) A = 4 B = 2 C = True D = False 4 2 True False 1:4 < 2 False 1 2 True 2: True OR False True False 3: ! Result 1 True 3 True 4: Result 2 AND Result3 True True Result 4 store F 4 22 PROF.A.R.BRAMHECHA

  30. Evaluate the following Equations given A = 5, B = 4 , C = 3 , D = 12a. E = A * B + D / Cb. E = D % A * B c. E = 5 * A % D * ( B + 1)d. E = D / B * ((A + 4 ) MOD ( C + 1)) Evaluate the following Equations given A = False , B = True , C = False, D = Truea. R = A AND B OR C AND Db. R = NOT ( A AND B) OR NOT(D AND C)c. R = (A OR B) AND (D OR C)d. R = NOT (A AND B OR C) AND (A OR B AND D) E. R = C OR NOT (A AND D) AND (A OR B) OR NOT (A OR C) PROF.A.R.BRAMHECHA

  31. Developing a Logical Expression from a Given Problem Problem: A large department store has its own charge card. The policy for a customer to charge an item is that the customer must have a valid charge card and either a balance of less than $500 or a charge of less than $50. Solution: If ChargeCard AND (Balance < 500 OR Amount < 50) Then Print “Okay to charge” Else Print “Not Okay to charge” PROF.A.R.BRAMHECHA

  32. Set up logical Expression to check data using following criteria . The data are assumed correct when: a. number is less than 100 b. number is positive c. number is divisible by 2 • number < 100 • number > 0 • number %2 == 0 • If(number < 100 && number > 0 && number %2==0) Then print number PROF.A.R.BRAMHECHA

  33. Set up logical expression for the following conditions. A company gives a bonus at the end of each fiscal year. For an employee to get bonus ,the any one condition of following must be true: a. The employee has been working at the company for more than six months with out negative report b. The employee has earned more than $5000 during the fiscal year • a. Work_exp > 6 AND ! Negative_report • b. Earning > 5000 If( (Work_exp > 6 AND !Negative_report) OR Earning >5000) Then Employee get the Bonus Else Employee not eligible for Bonus PROF.A.R.BRAMHECHA

  34. How Computer store Data • Each variable name is given a memory location which can hold one and only one value at a time. • Internal memory is volatile • The data, information and programs are stored in external medium as FILES–program files and data files. • BUFFER -Temporary memory while transfering files from external to internal storage. PROF.A.R.BRAMHECHA

  35. Communicating with computer What is a program? • A set of step-by-step instructions that directs the computer to perform tasks and produce results. What is a Programming Language? • A programming language is a set of rules that instructs a computer what operations to perform. Syntax: • Rules governing the computer operating system, the language and the application BUG: • It is an error Debugging: • The process of locating and correcting an error. PROF.A.R.BRAMHECHA

  36. Organising Problems Certain organisational tools can help us to solve problems :- • Problem Analysis Charts – shows a beginning analysis of the problem • Structure/Interactivity Charts – shows the overall layout or structure of the solution • IPO Chart – shows the input, the processing and the output • Algorithm – show the sequence of instructions comprising the solution • Flowcharts – graphic representations of the algorithms PROF.A.R.BRAMHECHA

  37. Problem Analysis Chart (PAC)separates the problem in 4 parts PROF.A.R.BRAMHECHA

  38. Create a Problem Analysis chart for calculating the Gross pay , given the formula GrossPay = Hours * PayRate PROF.A.R.BRAMHECHA

  39. Interactivity(Structure) Chart • This breakdowns a complex problem into simpler tasks. • This divides your solution in modules – subtasks. Interactivity chart connect modules together to show the interaction of processing between the modules • Each module should contain the tasks to finish/accomplish one function - e.g calculating results, reading input • The control/main module controls the flow to other modules PROF.A.R.BRAMHECHA

  40. Interactivity(Structure) Chart • KEY • Circle – iteration • Diagonal line – same module used twice • Diamond – selection PROF.A.R.BRAMHECHA

  41. Top-down method, here the program was executed form beginning to end. The user did not control the order of execution of the modules. The program was in control Control Module 2 Module 4 Module 5 Module 3 Module 1 Module 6 Module 7 Module 3 PROF.A.R.BRAMHECHA

  42. The Calculate module is duplicated in two places as indicated by the shaded in corner; the Salaried and Hourly modules are part of a decision as indicated by the diamond; and the Read module, the Calculate module, and the Print module are repeated until the NoMoreEmpolyees (when there are no more employees to process) as indicated by the filled-in circle. Control NoMoreEmpolyees Read Calculate Print Initialize Salaried Hourly Calculate The Completed Interactivity chart PROF.A.R.BRAMHECHA

  43. PayrollControl Until no more emp Read Calc Print Interactivity chart for payroll problem(top-down method) PROF.A.R.BRAMHECHA

  44. object-oriented programming – which is event driven – the user is in control. Modules are still used, within each module the execution is procedural Module6 Module7 Module3 Module2 Module1 Module3 Control Module4 Module5 PROF.A.R.BRAMHECHA

  45. Interactivity chart for payroll problem(Object-oriented solution) Payroll Control Print Read Calc PROF.A.R.BRAMHECHA

  46. The IPO Chart. • This extends and organises the information in the problem analysis chart. • It shows in more detail what data items are input, what processing takes place on the data and what information will be the end result, the output. • In the IPO chart the output is the first to be completed and then the input and then the processing eg. Planning a trip 1) Destination (o/p) 2)Transportation(i/p) 3) plan a route (processing) PROF.A.R.BRAMHECHA

  47. IPO chart PROF.A.R.BRAMHECHA

  48. IPO chart PROF.A.R.BRAMHECHA

  49. Writing Algorithms After using the Interactivity chart and the IPO chart the next step in organising the solution is to for the programmer to develop a set of instructions for the computer – called algorithms or Psuedocode. Algorithm: Systematic procedure that produces - in a finite number of steps - the answer to a question or the solution of a problem. Sequence of instructions which can be used to solve a given problem PROF.A.R.BRAMHECHA

  50. Control Module Instruction Instruction … .. .. ---end Name of Module (list of Parameters) Instruction Instruction .. .. .. ……..exit Form of an Algorithm Note: Uses End indicating end of processing Note: Uses Exit bcos processing continues PROF.A.R.BRAMHECHA

More Related