Unit I Problem Solving Concepts 632021 PROF A
Unit I Problem Solving Concepts 6/3/2021 PROF. A. R. BRAMHECHA 1
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 6/3/2021 PROF. A. R. BRAMHECHA 2
Six steps to ensure a Best decision in PROBLEM SOLVING 1. Identify the problem 2. Understand the problem 3. Identify alternative ways to solve the problem 4. List instructions that enable you to solve the problem using selected solution 5. Select the best way to solve the problem from the list of alternative solutions 6. 6/3/2021 Evaluate the solution PROF. A. R. BRAMHECHA 3
What makes a good decision? Ø Well identified problem Ø All alternatives considered Ø Information overloaded – appropriate alternatives Ø Can the person carry out steps/instructions 6/3/2021 PROF. A. R. BRAMHECHA 4
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. 6/3/2021 PROF. A. R. BRAMHECHA 5
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? 6/3/2021 PROF. A. R. BRAMHECHA 6
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 6/3/2021 PROF. A. R. BRAMHECHA 7
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 6/3/2021 PROF. A. R. BRAMHECHA 8
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 6/3/2021 PROF. A. R. BRAMHECHA 9
5. Working backwards from the solution 6. General problem solving strategies -Divide & conquer -Dynamic Programming greedy search , backtracking, branch & bound 6/3/2021 PROF. A. R. BRAMHECHA 10
Problem solving concepts for computers • Constants • Variables • Operators • Hierarchy of operations • Data types • Equations • Functions • Expressions 6/3/2021 PROF. A. R. BRAMHECHA 11
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 6/3/2021 PROF. A. R. BRAMHECHA 12
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: Shoe. Cost = 250 , city=“chennai” Ø Referred by name in the instructions. Ø Naming Conventions for Variables Rules 6/3/2021 PROF. A. R. BRAMHECHA 13
Data vs. Information O U T P U T I N P U T Data Unorganized facts 6/3/2021 P R O C E S S Information Processed meaningful report PROF. A. R. BRAMHECHA 14
Data Types: Ø A type is the “kind” of data that variable is allowed to hold. Ø Data Types and Their Data Sets 6/3/2021 PROF. A. R. BRAMHECHA 15
Ø 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 6/3/2021 PROF. A. R. BRAMHECHA 16
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 6/3/2021 PROF. A. R. BRAMHECHA 17
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 6/3/2021 PROF. A. R. BRAMHECHA 18
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(n 1, n 2, n 3) • 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 6/3/2021 PROF. A. R. BRAMHECHA 19
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. 6/3/2021 PROF. A. R. BRAMHECHA 20
Mathematical Operators 6/3/2021 Operator Symbol Example Addition + 3. 0 + 5. 2= 8. 2 Subtraction - 7. 5 - 4. 0 =3. 5 Multiplication * 8. 0 * 5. 0 = 40. 0 Division / 9. 0/4. 0= 2. 25 9 /4=2 Modulo division % 9%4=1 Power ^ 3^2= 9 Increment ++ ++2 = 3 Decrement -- - -2 = 1 PROF. A. R. BRAMHECHA 21
Relational Operators Operator Symbol Example Equal to == 5 = =7 False Less than < 6<5 False 6<7 True Greater than > 6>5 True 6>7 False Less than or equal to <= 5<=7 True Greater than or equal to >= 5>=7 False Not Equal(<>) != 5!=7 True Logical Operators Operator Symbol Example Not ! !True False And && True Or || True 6/3/2021 PROF. A. R. BRAMHECHA 22
Hierarchy of operations 1. Functions 2. Power 3. %, *, / 4. +, - 5. =, <, >, <=, >=. <> 6. NOT 7. AND 8. OR Examples: (Hours – 40) * Wage * 1. 5 F=6*2 6+2 F = 6 * 2 (6 + 2) F = 6 * (2 (6 + 2)) 6/3/2021 PROF. A. R. BRAMHECHA 23
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 6/3/2021 PROF. A. R. BRAMHECHA 24
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 6/3/2021 PROF. A. R. BRAMHECHA 25
5: Evaluating a Mathematical Expression Area = x 2 + 4 x = 4 and b = 3 x/2 * b 4 3 1 2 16 42 = 16 2: 4/2 = 2 3: 2*3 = 6 4: 16 + 6 = 22 2 3 6 4 6/3/2021 1: 22 PROF. A. R. BRAMHECHA 26
6: Evaluating a Relational Expression A - 2 > B 6 A=6 B=8 8 1 1: 6– 2=4 2: 4 > 8 False 4 2 False 6/3/2021 PROF. A. R. BRAMHECHA 27
7: Evaluating a Logical Expression A && B || C && A False True A = True B = False C = True 1: True && False = False 1 2 2: True && True = True False True 3: Result 1 || Result 2 = True 3 True 6/3/2021 PROF. A. R. BRAMHECHA 28
8: Evaluating an Equation That Uses Both Relational and Logical Operators F = !(A < B) AND (C OR D) 4 True 2 1 True False 2 False 3 A = 4 B = 2 C = True D = False 1: 4<2 False 2: True OR False True 3: ! Result 1 4: Result 2 AND Result 3 True Result 4 store F 4 6/3/2021 22 PROF. A. R. BRAMHECHA 29
Evaluate the following Equations given A = 5, B = 4 , C = 3 , D = 12 a. E = A * B + D / C b. 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 = True a. R = A AND B OR C AND D b. 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) 6/3/2021 PROF. A. R. BRAMHECHA 30
Developing a Logical Expression from a Given 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 Charge. Card AND (Balance < 500 OR Amount < 50) Then Print “Okay to charge” Else Print “Not Okay to charge” 6/3/2021 PROF. A. R. BRAMHECHA 31
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 1. 2. 3. 4. number < 100 number > 0 number %2 == 0 If(number < 100 && number > 0 && number %2==0) Then print number 6/3/2021 PROF. A. R. BRAMHECHA 32
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 6/3/2021 PROF. A. R. BRAMHECHA 33
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. 6/3/2021 PROF. A. R. BRAMHECHA 34
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. 6/3/2021 PROF. A. R. BRAMHECHA 35
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 6/3/2021 PROF. A. R. BRAMHECHA 36
Problem Analysis Chart (PAC) separates the problem in 4 parts Given Data Required Results Section 1: Data given in the problem or provided by user-Data, constants, variables Section 2: Requirements to produce the output-information and format required Processing required Solution alternatives Section 3: List of processing required – equations, or searching or sorting techniques Section 4: List of ideas for the solution. 6/3/2021 PROF. A. R. BRAMHECHA 37
Create a Problem Analysis chart for calculating the Gross pay , given the formula Gross. Pay = Hours * Pay. Rate Given Data Required Results Hours Pay Rate Gross Pay Processing required Solution alternatives Gross. Pay = Hours * Pay. Rate 1. Define the hours worked And pay rate as constants 2. Define the hours worked and pay rate as input values 6/3/2021 PROF. A. R. BRAMHECHA 38
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 6/3/2021 PROF. A. R. BRAMHECHA 39
Interactivity(Structure) Chart • KEY • Circle – iteration • Diagonal line – same module used twice • Diamond – selection 6/3/2021 PROF. A. R. BRAMHECHA 40
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 1 Module 3 6/3/2021 Module 2 Module 6 Module 3 Module 4 Module 5 Module 7 PROF. A. R. BRAMHECHA 41
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 No. More. Empolyees (when there are no more employees to process) as indicated by the filled -in circle. Control No. More. Empolyees Initialize Calculate 6/3/2021 Read Salaried Calculate Print Hourly The Completed Interactivity chart PROF. A. R. BRAMHECHA 42
Payroll. Control Read Calc Until no more emp Print Interactivity chart for payroll problem(top-down method) 6/3/2021 PROF. A. R. BRAMHECHA 43
object-oriented programming – which is event driven – the user is in control. Modules are still used, within each module the execution is procedural Module 6 Module 7 Module 3 Module 2 Module 1 Control Module 4 Module 5 6/3/2021 Module 3 PROF. A. R. BRAMHECHA 44
Interactivity chart for payroll problem(Object-oriented solution) Read Payroll Control Print Calc 6/3/2021 PROF. A. R. BRAMHECHA 45
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) 6/3/2021 PROF. A. R. BRAMHECHA 46
IPO chart Input Processing Module Reference Output All input data (from section 1 of the Problem Analysis chart) All processing in steps (from Sections 3 and 4 of the problem analysis chart) Module reference from the Interactivity chart All output requirements (from sections 1 and 2 of the problem analysis chart) 6/3/2021 PROF. A. R. BRAMHECHA 47
IPO chart Input Processing Module Reference Output TASK : - 1) Construct an IPO Chart for the Average Problem Enter 3 numbers 1. Enter three numbers 2. calculate the average of the three numbers 3. print the average 4. end Read first number Read second number Read third number Calculate the average of the three numbers Print the average Average TASK : - 2)For the Gross Pay problem Hours worked Pay rate Enter Hours worked 1. Enter Pay rate 2. Calculate Pay 3. Print pay 4. End Read Calc Print Payroll. Control Grosspay 6/3/2021 PROF. A. R. BRAMHECHA 48
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 6/3/2021 PROF. A. R. BRAMHECHA 49
Form of an Algorithm Control Module 1. Instruction 2. Instruction 3. … 4. . . ---end Note: Uses End indicating end of processing 6/3/2021 Name of Module (list of Parameters) 1. Instruction 2. Instruction 3. . . 4. . . ……. . exit Note: Uses Exit bcos processing continues PROF. A. R. BRAMHECHA 50
Examples • Addition of Digits of Number • Conversion from decimal to binary • The process of boiling an egg • The process of mailing a letter • Sorting • Searching Let us write down the algorithm for a problem that is familiar to us. Converting a decimal number into binary 6/3/2021 PROF. A. R. BRAMHECHA 51
2 2 2 2 Convert 75 to Binary 75 37 18 9 4 2 1 0 remainder 1 1 0 0 1 1001011 6/3/2021 PROF. A. R. BRAMHECHA 52
Algorithm for Decimal-to-Binary Conversion 1. Start 2. Write the decimal number 3. Divide by 2; Write quotient and remainder 4. Repeat step 2 on the quotient; keep on repeating until the quotient becomes zero 5. Write all remainder digits in the reverse order (last remainder first) to form the final result 6. Stop 6/3/2021 PROF. A. R. BRAMHECHA 53
Algorithm for Addition of Digits of Number 1. Start 2. Accept the integer number 3. number mod by 10 4. Perform addition of remainder 5. number divide by 10 6. Repeat steps 2 to 4 ; keep on repeating until the number becomes zero 7. Print final result; sum of digits 8. Stop 6/3/2021 PROF. A. R. BRAMHECHA 54
Points to Note 1. The process consists of repeated application of simple steps 2. All steps are unambiguous (clearly defined) 3. We are capable of doing all those steps 4. Only a limited no. of steps needs to be taken 5. Once all those steps are taken according to the prescribed sequence, the required result will be found 6. Moreover, the process will stop at that point 6/3/2021 PROF. A. R. BRAMHECHA 55
Three Requirements 1. 2. 3. 6/3/2021 Sequence is: a. Precise b. Consists of a limited number of steps Each step is: a. Unambiguous b. Executable The sequence of steps terminates in the form of a solution PROF. A. R. BRAMHECHA 56
Pseudo Code • Language that is typically used for writing algorithms • Similar to a programming language, but not as rigid • The method of expression most suitable for a given situation is used: – At times, plain English – At others, a programming language like syntax 6/3/2021 PROF. A. R. BRAMHECHA 57
Computer operations in Pseudocode 1. Input Data • Read – Read student name • Get – Get student name 6/3/2021 PROF. A. R. BRAMHECHA 58
Computer operations in Pseudocode 2. Output Information 6/3/2021 • Print – Print ‘Program Complete’ • Write – Write record to file • Output – Output total. Amount • Display – Display ‘Program Complete’ PROF. A. R. BRAMHECHA 59
Computer operations in Pseudocode 3. Perform Arithmetic 6/3/2021 • Add – Add num 1 to num 2 • Subtract – Subtract num 1 from num 2 • Multiply – Multiply num 1 by num 2 • Divide – Divide num 1 by num 2 PROF. A. R. BRAMHECHA 60
Computer operations in Pseudocode 4. Assign Values 6/3/2021 • Initialise – Initialise total. Price to zero • Set – Set total. Price to zero • Store – Store zero in total. Price PROF. A. R. BRAMHECHA 61
Computer operations in Pseudocode 5. Compare Values • IF…THEN…ELSE – IF num 1 > num 2 THEN ADD num 1 to toal ELSE ADD num 2 to total ENDIF 6/3/2021 PROF. A. R. BRAMHECHA 62
Computer operations in Pseudocode 6. Repeat Actions • DOWHILE – DOWHILE Num 1 > Num 2 ADD num 1 to total Multiply total by 3 Subtract Num 2 by 3 ENDDO 6/3/2021 PROF. A. R. BRAMHECHA 63
Write pseudo code • 1. 2. 3. 4. • 1. 2. 3. Addition of two nos. Read A Read B C : = A + B Print C Find Maximum of Three Nos. Read A Read B Read C 6/3/2021 4. IF A>B 5. THEN If A > C 6. THEN Print A is maximum 7. ELSE Print B is maximum 8. End. IF 9. ELSE IF B > C 10. THEN Print B is maximum 11. ELSE Print C is maximum 12. ENDIF 13. ENDIF PROF. A. R. BRAMHECHA 64
• 1. 2. 3. 4. 5. 6. 7. • Print Color name RED, BLACK & Addition of digits of No. GREEN wrt to character R or r, B or b Sum : = 0 & G or g Read Number 1. Read Ch Do steps 2 to 6 WHILE 2. IF Ch==‘R’ || Ch==‘r’ Number > 0 3. THEN Print “RED” Digit : = Number % 10 4. ELSE IF Ch==‘B’ || Ch==‘b’ Sum : =Sum + Digit 5. THEN Print “BLACK” Number : = Number / 10 6. ELSE IF Ch==‘G’ || Ch==‘g’ Print Addition of Digits Sum 7. THEN Print “GREEN” 8. ELSE Print Invalid Input 9. ENDIF 10. ENDIF 11. ENDIF 6/3/2021 PROF. A. R. BRAMHECHA 65
Flowchart • A graphical representation of a process (e. g. an algorithm), in which graphic objects are used to indicate the steps & decisions that are taken as the process moves along from start to finish. • Individual steps are represented by boxes and other shapes on the flowchart, with arrows between those shapes indicating the order in which the steps are taken. 6/3/2021 PROF. A. R. BRAMHECHA 66
Start or stop Process Input or output Flowchart Symbols Decision Flow line Connector Off-page connector 6/3/2021 PROF. A. R. BRAMHECHA 67
Process Module Flowchart Symbols 6/3/2021 Automaticcounter loop PROF. A. R. BRAMHECHA counter A B S 68
Four Flowchart Structures Decision Structure • A new symbol, the diamond, indicates a yes/no question. If the answer to the question is yes, the flow follows one path. If the answer is no, the flow follows another path NO 6/3/2021 PROF. A. R. BRAMHECHA YES 69
Decision Structure • A new symbol, the diamond, indicates a yes/no question. If the answer to the question is yes, the flow follows one path. If the answer is no, the flow follows another path NO 6/3/2021 PROF. A. R. BRAMHECHA YES 70
Repetition Structure • A repetition structure represents part of the program that repeats. This type of structure is commonly known as a loop. 6/3/2021 PROF. A. R. BRAMHECHA 71
In the flowchart segment, the question “is x < y? ” is asked. If the answer is yes, then Process A is performed. The question “is x < y? ” is asked again. Process A is repeated as long as x is less than y. When x is no longer less than y, the repetition stops and the structure is exited Code: YES x < y? 6/3/2021 while (x < y) x++; YES Process A x < y? PROF. A. R. BRAMHECHA Add 1 to x 72
Case Structure One of several possible actions is taken, depending on the contents of a variable. 6/3/2021 PROF. A. R. BRAMHECHA 73
Case Structure • The structure below indicates actions to perform depending on the value in years_employed. CASE years_employed 6/3/2021 1 2 3 bonus = 100 bonus = 200 bonus = 400 PROF. A. R. BRAMHECHA Other bonus = 800 74
Draw Flowchart 1. 2. 3. 4. Addition of two Nos. Find maximum of three Nos. Addition of Digits of No. Print Color name RED, BLACK & GREEN wrt to character R or r, B or b & G or g 6/3/2021 PROF. A. R. BRAMHECHA 75
Developing Short Programs 1. Read, understand the problem 5. 2. Do you have all the required data? Write the code on a piece of paper 6. Hand-check it No: Get it 7. Type it in Else assume it. State it explicitly 8. Run & check it on test cases 3. Do the design 9. Errors? fix & redo 9 4. Write test cases 6/3/2021 Done! PROF. A. R. BRAMHECHA 76
DOCUMENTATION Internal Documentation: Ø Remarks written with the instructions to explain what is being done in the program External Documentation: Ø Manuals/Help Menus written about the solution. 6/3/2021 PROF. A. R. BRAMHECHA 77
Testing the Solution Ø to make sure it meets the requirements of the user Ø to check for errors in logic or in the setup of the expressions and equations. Ø selects test data, a set of values for the input data, works them through every step in the solution Coding the Solution Ø writing the solution of the problem into a computer language—that is, coding the solution. 6/3/2021 PROF. A. R. BRAMHECHA 78
Top Down Design 1. start with a clear statement of the problem or concept – a single big idea. 2. Next, break it down into several parts. 6/3/2021 PROF. A. R. BRAMHECHA 79 79
Top Down Design 3. Next, break it down into several parts. If any of those parts can be further broken down, then the process continues… 6/3/2021 PROF. A. R. BRAMHECHA 80 80
Top Down Design 4. … and so on. 6/3/2021 PROF. A. R. BRAMHECHA 81 81
Top Down Design 5… and so on. The final design might look something like this organizational chart, showing the overall structure of separate units that form a single complex entity. 6/3/2021 PROF. A. R. BRAMHECHA 82 82
Top Down Design 6. An organizational chart is like an upside down tree, with nodes representing each process. 6/3/2021 PROF. A. R. BRAMHECHA 83 83
Top Down Design 7. An organizational chart is like an upside down tree, with nodes representing each process. The leaf nodes are those at the end of each branch of the tree. 6/3/2021 PROF. A. R. BRAMHECHA 84 84
Top Down Design 8. The leaf nodes represent modules that need to be developed and then recombined to create the overall solution tothe original problem. Top-down design leads to modular development. 6/3/2021 PROF. A. R. BRAMHECHA 85 85
Multiple choice Questions 1. 2. The field of computers that deals with heuristic types of problems a)DBMS b)DS c)CO d)AI Definition of heuristic solution: a)Series of action b) Series of steps c) process of trial and error c)none of these 3. Definition of Algorithmic solution: a)Series of action b) understanding the problem c) process of trial and error c)none of these 4. Which term is not used while problem solving with computers? a)Solution b)Result c)Page d)Program 5. Which solutions require reasoning built on knowledge and experience, a)Algorithmic b) heuristic c) a&b both c)None of these 6/3/2021 PROF. A. R. BRAMHECHA Answer d c a c b 86
Multiple choice Questions 6. Which is knowledge based problem? a)Driving a car b) Make a cup of cocoa. c)Sharpen a pencil. d)Start a car 7. Which is Algorithmic problem? a)Driving a car b) Make a cup of cocoa. c) Balancing your checkbook d) Building a house 8. Which is right variable name: a)Roll No b)1 Emp c)Car# d) _Hours 9. Which is wrong variable name: a)Roll_No b)Emp 1 c)Car No d) _Hours 10. Logical data consist of two values in the data set: a)True & False b)Right & wrong c)left & right d)none of these 6/3/2021 PROF. A. R. BRAMHECHA Answer a b d c a 87
Multiple choice Questions 11. What is the value of F if F = 2 + 6 * 2 % 6 a)1. 5 b) 4 c)2. 66 d)none of these 12. Resultant value of following expression 5* (X +Y ) - 4*Y / (Z + 6) x=2 y=3 z=6 a)24 b)5. 33 c)5. 25 d) none of these 13. Which is not in a order of hierarchy a)* + AND b)% - ! c) ! / + d)! + < Answer d a c 14. Computer error is called as… a)Syntax b)debug c)Bug d)Constant c 15. Which flowchart symbol indicates processing block a) Flattened ellipses b) rectangle c) parallelogram d) diamond b 6/3/2021 PROF. A. R. BRAMHECHA 88
Multiple choice Questions Answer 16. Which flowchart symbol indicates decisions a)Flattened ellipses b) rectangle c) parallelogram d) diamond d 17. Which flowchart symbol indicates input to and output from computer a)Flattened ellipses b) rectangle c) parallelogram d) diamond c 18. Which flowchart symbol indicates the start and end of the module a)Flattened ellipses b) rectangle c) parallelogram d) diamond a 19. Indicates a loop with counter a)Polygon b) rectangle c) parallelogram d) diamond 20. Which is not a part of software development cycle? a)analysis b)design c) coding d)none of these 6/3/2021 PROF. A. R. BRAMHECHA a d 89
Multiple choice Questions Answer 21. Bug find out at run time called as… a)Syntax error b)logical error c)problem d)only error b 22. Compile time error called as… a)Syntax error b)logical error c)Exception d)only error a 23. Which of the following is language dependant a)Program b)Algorithm c) pseudocode d)Flowchart a 24. Which is not a variation of dynamic programming: a)greedy search b)back tracking c)branch &bound d)none of these d 25 Resultant value of following expression F=( C *( B + 3 * A ) + 5 * A ) A = 6 B = 4 C = 2 a)74 b)294 c)588 d)2520 6/3/2021 PROF. A. R. BRAMHECHA a 90
Multiple choice Questions 26. Evaluate the following for the values A = 5 B = 5 C = True D = False R = NOT C OR D OR A – 3 <= B a)True b)False c) Error d) None of these Answer a 27. Which tool shows the overall structure of the solution a)IPO b)PAC c)Interactivity chart d) Flowchart c 28. The output is the first to be completed in an ……. . a)IPO b)Algorithm c)Interactivity chart d) Flowchart a 6/3/2021 PROF. A. R. BRAMHECHA 91
UNIT I: Problem Solving Concepts Ø General Problem Solving Concepts-Types of problems, problems solving with computers, difficulties with problem solving : Maureen Sprankle, Chapter 1 Ø Problem Solving Aspects : R G Dromey Chapter 1 section 1. 2 Ø Problem Solving Concepts for computer- constants and variables, data types, functions, operators, expressions and equations : Maureen Sprankle, Chapter 2 Ø Programming Concepts – communicating with computers, organizing the problem, using the tools, testing the solution, coding the program : Maureen Sprankle, Chapter 3 Ø Top down design : R G Dromey Chapter 1 section 1. 2 6/3/2021 PROF. A. R. BRAMHECHA 92
- Slides: 92