problem solving concept by meetendra sir(unit 5)

Upload: meetendra-singh

Post on 02-Jun-2018

218 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/10/2019 Problem Solving Concept by Meetendra Sir(Unit 5)

    1/41

    Problem Solving Concepts

    UNIT-5

    1

    Meetendra Singh Chahar

    Astt. Professor

    R.B.S.M.T.C, Agra

    MEETENDRA SINGH CHAHAR

  • 8/10/2019 Problem Solving Concept by Meetendra Sir(Unit 5)

    2/41

    INTRODUCTION

    A problem obstructs and hinders the progress or movementin achieving of an objective.

    The nature of the problem depends on the situation.

    In problem solving each individual may have his or her ownunique way.

    2MEETENDRA SINGH CHAHAR

  • 8/10/2019 Problem Solving Concept by Meetendra Sir(Unit 5)

    3/41

    PROBLEM DEFINITION

    Problem definition is the first and most important step indetermining information needs.

    Information needs of software can be determined by:

    1. Studying the existing system2. Using questionnaires

    3. Stating the tentative information needs

    4. Suggesting interpretation of information needs with

    users.

    3MEETENDRA SINGH CHAHAR

  • 8/10/2019 Problem Solving Concept by Meetendra Sir(Unit 5)

    4/41

    PROBLEM SOLVING TECHNIQUES

    For solving a problem there are many techniques available,some of popular techniques are:

    1. Trail & Error Method

    2. Brain Storming Method3. Divide & Conquer Method

    4MEETENDRA SINGH CHAHAR

  • 8/10/2019 Problem Solving Concept by Meetendra Sir(Unit 5)

    5/41

    1. TRAIL & ERROR METHOD

    This is an iterative method.

    It is based on the idea of successive approximation.

    Starting with initial approximation to the root.

    It is the most natural technique because in this sequenceof steps is repeated over and over again.

    5MEETENDRA SINGH CHAHAR

  • 8/10/2019 Problem Solving Concept by Meetendra Sir(Unit 5)

    6/41

    2. BRAINSTORMING METHOD

    Brainstorming is a group activity designed to increase thequantity of fresh ideas.

    or

    Brainstorming is a group method for obtaining new ideas andbusiness solutions.

    The groups are organized for sitting together and stimulategreater creativity by exchange of mutual experiences andparticipating in the discussions.

    The brainstorming ideas are canalized to a particular

    segment of product line or services.

    6MEETENDRA SINGH CHAHAR

  • 8/10/2019 Problem Solving Concept by Meetendra Sir(Unit 5)

    7/41

    Method of Conducting Brainstorming Sessions

    The group should be informed of the broad areas of thesubject or area of discussions.

    The group should consist of people drawn from differentstreams of knowledge such as marketing, production, qualitycontrol, planning, finance, costing, stores, handling, taxationand the like. The group also should consist of differentlevels of officers, supervisors from the organization.

    The brainstorming session should be held in a good placewith ambience. So, that the group comes open with their

    ideas.

    To be continued

    7MEETENDRA SINGH CHAHAR

  • 8/10/2019 Problem Solving Concept by Meetendra Sir(Unit 5)

    8/41

    The member should have no inhibitions about their status inthe organization or department where they serve. The

    session should be frank and be fun. The brainstormingsessions are held where no individual or group dominate thediscussions and no boss-subordinate relationships.

    Day dreaming or wild ideas to be encouraged.

    There should not be any negative comments or criticismsagainst any particular individuals or groups or departments.

    The ideas of one can be improved by others but norepetition of ideas. Each individual may be given a chance tothree ideas and these ideas being recorded on a flip chart

    or black board. All the ideas are recorded on the flip charteven if one idea is not practical or ill-logical.

    8MEETENDRA SINGH CHAHAR

  • 8/10/2019 Problem Solving Concept by Meetendra Sir(Unit 5)

    9/41

    3. DIVIDE & CONQUER METHOD

    9

    Steps in Divide and Conquer Algorithm

    Divide Step: In this step of the algorithm, the input ispartitioned into p 1 parts, each of size strictly less than n,the size of the original instance. The most common value ofp is 2, although other small constants greater than 2 arenot uncommon.

    Conquer Step:This step consists of performing p recursive

    call(s) if the problem size is greater than some pre-definedthreshold n0 . This threshold is derived by mathematicalanalysis of the algorithm. Once it is found, it can beincreased by any constant amount without affecting thetime complexity of the algorithm.

    Combine Step: In this step, the solutions to the p recursivecall(s) are combined to obtain the desired output. Thecombine step in a divide-and-conquer algorithm may consistof merging, sorting, searching, finding the maximum orminimum, matrix addition, etc.

    MEETENDRA SINGH CHAHAR 9

  • 8/10/2019 Problem Solving Concept by Meetendra Sir(Unit 5)

    10/41

    10

    Divide-and-conquer algorithm consists of

    following major phases:1. Breaking the problem into several sub-problems that

    are similar to the original problem but smaller in size.

    2. Solve the sub-problem recursively (successively and

    independently), and then,3. Combine these solutions to sub-problems to create a

    solution to the original problem.

    MEETENDRA SINGH CHAHAR

  • 8/10/2019 Problem Solving Concept by Meetendra Sir(Unit 5)

    11/41

    11

    A Problem of Sizen (Instance)

    Subproblem 1 ofSize n/2

    Subproblem 2 ofSize n/2

    A Solution toSubproblem 1

    A Solution toSubproblem 2

    A Solution to theOriginal Problem

    Divide-and-Conquer StrategyMEETENDRA SINGH CHAHAR

  • 8/10/2019 Problem Solving Concept by Meetendra Sir(Unit 5)

    12/41

    STEPS IN PROBLEM SOLVING

    12

    There are mainly three steps to solving a problem-

    1. Defining the Problem

    2. Analyze the Problem

    3. Explore Solution

    MEETENDRA SINGH CHAHAR

  • 8/10/2019 Problem Solving Concept by Meetendra Sir(Unit 5)

    13/41

    13

    1. DEFINING THE PROBLEM

    When a problem is to be solved, two question arise,1. What to do ?

    2. How to do ?

    This phase answer the first question.

    Here, the programmer has to defined the taskprecisely(correctly) and check for completeness.

    There should not be any ambiguity(confusion).

    The imprecisely or arbitrarily defined problem may result in

    wrong analysis and design.

    To be continued

    MEETENDRA SINGH CHAHAR

  • 8/10/2019 Problem Solving Concept by Meetendra Sir(Unit 5)

    14/41

    14

    Different programmers may program this problem as peer

    their understanding. The problem definition skill is directly proportional to the

    depth of understanding of the programmer.

    In the problem definition phase, the programmer has toreflect all the possibilities that need decision-making.

    MEETENDRA SINGH CHAHAR

  • 8/10/2019 Problem Solving Concept by Meetendra Sir(Unit 5)

    15/41

    15

    2. ANALYZE THE PROBLEM

    This is the programmers talent-testing phase.

    A good analysis may result in good designing and coding.

    In this phase, the programmer has to answer the secondquestion, How to do?

    This is the initial investigation of the problem.

    The programmer has to declare the computationalstrategies to analyze the defined problem with the help ofavailable tools.

    Programming techniques like sequence, selection and

    iteration can be used to develop the logic for analysis.

    To be continued

    MEETENDRA SINGH CHAHAR

  • 8/10/2019 Problem Solving Concept by Meetendra Sir(Unit 5)

    16/41

    16

    The primary operations that are performed on data are

    arithmetic, logical and relational. The mostly used database operations are searching, sorting,

    inserting, merging, etc.

    Once we analyze the problem, the next phase is to designthe program.

    MEETENDRA SINGH CHAHAR

  • 8/10/2019 Problem Solving Concept by Meetendra Sir(Unit 5)

    17/41

    17

    3. EXPLORE SOLUTION

    When programmer complete the analysis then he/she willexplore (or design) the different solution of the problemand the best or optimum solution is chooses by thedevelopment team.

    Once the problem is defined and the idea of how to solve it

    is developed, the programmer can begin designing algorithm. Before starting designing, the problem must be refined

    step-wise. This is known as the top-down design.

    It is a strategy where the problem is divided into ahierarchical structure.

    To be continued

    MEETENDRA SINGH CHAHAR

  • 8/10/2019 Problem Solving Concept by Meetendra Sir(Unit 5)

    18/41

    18

    A separate sub-program may be designed for each module.

    The top-down approach provides a method of handling theinherent logical complexity.

    This allows the programmer to build solution in a step-wisemanner.

    MEETENDRA SINGH CHAHAR

  • 8/10/2019 Problem Solving Concept by Meetendra Sir(Unit 5)

    19/41

    19

    Steps of using a Computer as a Problem-Solving Tool

    Develop an Algorithm and a Flowchart.

    Write the program in a computer language. (i.e. C, C++, etc.)

    Enter the program into the computer.

    Test and debug the program.

    Run the program, input data and get the results from thecomputer.

    MEETENDRA SINGH CHAHAR

  • 8/10/2019 Problem Solving Concept by Meetendra Sir(Unit 5)

    20/41

    20

    ALGORITHMS An algorithmis any well-defined computational procedure

    that takes some value, or set of values, as input

    andproduces some value, or set of values, as output.

    An algorithm is thus a sequence of computational stepsthat transform the input into the output.

    or An algorithm is a sequence of unambiguous instructions for

    solving a problem.

    Obtaining a required output for any valid input in afinite amount of time.

    Procedural solutions to problems.

    To be continued

    MEETENDRA SINGH CHAHAR

  • 8/10/2019 Problem Solving Concept by Meetendra Sir(Unit 5)

    21/41

    21

    Computer is capable of understanding and following theinstructions given.

    An input specifies an instance of the problem, the algorithm

    solves.

    Problem

    Algorithm

    ComputerInput Output

    Notion of AlgorithmMEETENDRA SINGH CHAHAR

  • 8/10/2019 Problem Solving Concept by Meetendra Sir(Unit 5)

    22/41

    22

    The word algorithm comes from the name of the 9thcentury Persian Muslim mathematician Abu Abdullah

    Muhammad ibn Musa Al Khwarizmi. An algorithm is an effective method for solving a problem

    using a finite sequence of instructions.

    The computational complexity and efficient implementation

    of the algorithm are important in computing and thisdepends on suitable data structure.

    Each algorithm is a list of well-defined instructions forcompleting a task.

    MEETENDRA SINGH CHAHAR

  • 8/10/2019 Problem Solving Concept by Meetendra Sir(Unit 5)

    23/41

    23

    Format of an Algorithm

    Input: Step 1:

    Step 2:

    Step 3:

    ..

    ..

    ..

    Step n:

    Output:

    MEETENDRA SINGH CHAHAR

  • 8/10/2019 Problem Solving Concept by Meetendra Sir(Unit 5)

    24/41

    24

    Characteristics of an Algorithm

    Finiteness:Terminates after a finite number of steps. Definiteness:Rigorously and unambiguously specified.

    Input:Valid inputs are clearly specified.

    Output:Can be proved to produce the correct output given

    a valid input. Effectiveness:Steps are sufficiently simple and basic.

    MEETENDRA SINGH CHAHAR

  • 8/10/2019 Problem Solving Concept by Meetendra Sir(Unit 5)

    25/41

    25

    Advantages of an Algorithm

    Provides step by step procedure to understand easily.

    Algorithm is easy to write.

    Solves those problems which are complex and not solve bysimple methods.

    Algorithm in general, can be directly coded in aprogramming language.

    MEETENDRA SINGH CHAHAR

  • 8/10/2019 Problem Solving Concept by Meetendra Sir(Unit 5)

    26/41

    26

    Example- Addition of two numbers.

    AlgorithmStep 1: START

    Step 2: Initialize x, y and z

    Step 3: Read x, y

    Step 4: Calculate z = x + y

    Step 5: Print Sum of two numbers, z

    Step 6: STOP

    MEETENDRA SINGH CHAHAR

  • 8/10/2019 Problem Solving Concept by Meetendra Sir(Unit 5)

    27/41

    27

    FLOWCHARTS

    A flowchart is a graphical representation of an algorithm.or

    A flowchart is a diagram that is prepared by theprogrammer which represents the sequence of stepsinvolved in solving a problem.

    It is an aid to solve a complex problem easily andefficiently.

    It is also used to correct and debug a program flow afterthe coding part is completed.

    To be continued

    MEETENDRA SINGH CHAHAR

  • 8/10/2019 Problem Solving Concept by Meetendra Sir(Unit 5)

    28/41

    28

    It is one of the best tool for testing and maintaining asoftware.

    A flowchart is sometimes called as a logic diagramin aprogramming parlance.

    Its diagrammatic representation can give a step-by-stepsolution to a given problem.

    It provides not only a detailed view of a program flow butalso used as a blueprint of the software project that showsthe general plan, architecture and essential details of theproposed software structure.

    MEETENDRA SINGH CHAHAR

  • 8/10/2019 Problem Solving Concept by Meetendra Sir(Unit 5)

    29/41

    29

    Flowchart Symbols

    In constructing flowcharts, standard symbols are used.

    The American National Standard Institute(ANSI) symbolsare normally used.

    Some important flowchart symbols are given here:

    MEETENDRA SINGH CHAHAR

  • 8/10/2019 Problem Solving Concept by Meetendra Sir(Unit 5)

    30/41

    30

    Symbols Name(Attribute) Description

    Process An operation or action step.

    Terminator A start or stop point in a process.

    Decision A question or branch in the process.

    Delay A waiting period.

    Data(I/O)Indicates data inputs and outputs toand from a process.

    Alternate

    Process

    An alternate to the normal process

    step.

    Flow LineIndicates the direction of flow formaterials and/or information

    Flowchart SymbolsMEETENDRA SINGH CHAHAR

  • 8/10/2019 Problem Solving Concept by Meetendra Sir(Unit 5)

    31/41

    31

    Symbols Name(Attribute) Description

    PredefinedProcess

    A formally defined sub-process

    Document A document or report

    Multi-DocumentSame as Document, except, well,multiple documents

    PreparationA preparation or set-up processstep

    Display A machine display

    Manual Input Manually input into a system

    Stored DataA general data storage flowchartsymbol

    Flowchart SymbolsMEETENDRA SINGH CHAHAR

  • 8/10/2019 Problem Solving Concept by Meetendra Sir(Unit 5)

    32/41

    32

    Symbols Name(Attribute) Description

    Punched Tape An old computer punched tape input

    Merge (Storage) Merge multiple processes into one.

    Extract(Measurement)

    Extract(split process) or morecommonly a measurement

    Magnetic Disk(Database) A database

    Direct AccessStorage

    Storage on a hard disk

    Internal Storage Data stored in memory

    SequentialAccess Storage

    An old reel of tape

    Flowchart SymbolsMEETENDRA SINGH CHAHAR

  • 8/10/2019 Problem Solving Concept by Meetendra Sir(Unit 5)

    33/41

  • 8/10/2019 Problem Solving Concept by Meetendra Sir(Unit 5)

    34/41

    34

    PSEUDO CODE Pseudo code is an artificial and informal language that helps

    programmers to develop algorithms.

    Pseudo code is a text-based detail (algorithmic) designtool.

    It is a compact and informal high-level description of a

    computer programming algorithm that uses the structuralconventions of a programming language, but is intended forhuman reading rather than machine reading.

    Pseudo code typically omits details that are not essentialfor human understanding of the algorithm, such as variable

    declaration, etc.

    To be continued

    MEETENDRA SINGH CHAHAR

  • 8/10/2019 Problem Solving Concept by Meetendra Sir(Unit 5)

    35/41

    35

    The purpose of using pseudo code is that it is easier for

    humans to understand than conventional programminglanguage code.

    It is commonly used in textbooks and scientific publicationsthat are documenting various algorithms and also in planningof computer program development, for sketching out the

    structure of the program before the actual coding takesplace.

    MEETENDRA SINGH CHAHAR

  • 8/10/2019 Problem Solving Concept by Meetendra Sir(Unit 5)

    36/41

    36

    Conventions for Pseudo Code

    Pseudo code should be clear and easy to understand.

    Give a valid name for the pseudo code procedure.

    Use the line numbers for each line of code.

    Use proper indentation for every statement in a blockstructure.

    For a flow control statements use if-else. Always end an if

    statement with an end-if. Both if-else and end-if should bealigned vertically in same line.

    For example,

    if(condition expression)

    statements

    else statements

    end-if

    To be continuedMEETENDRA SINGH CHAHAR

  • 8/10/2019 Problem Solving Concept by Meetendra Sir(Unit 5)

    37/41

    37

    Use = or operator for assignment statements.

    For example

    i = j or i j

    Array elements can be represented by specifying the arrayname followed by the index in square brackets.

    For ex., A[i] indicates the ith element of the array A.

    MEETENDRA SINGH CHAHAR

  • 8/10/2019 Problem Solving Concept by Meetendra Sir(Unit 5)

    38/41

    38

    Loops in pseudo code

    For looping or iteration use for or while statements.Always end a for loop with end-for and a while with end-while.

    The conditional expression of for or while can be written.

    We can separate two or more conditions with an and.

    MEETENDRA SINGH CHAHAR

  • 8/10/2019 Problem Solving Concept by Meetendra Sir(Unit 5)

    39/41

    39

    Example- Finding maximum no.

    Algorithm: arrayMax(a[1...n], n)Step 1: max = a[1]

    Step 2: For i = 2 to n do

    Step 3: If a[i] > max, then

    Step 4: max = a[i]

    Step 5: Endif

    Step 6: Endfor

    Step 7: Return max

    MEETENDRA SINGH CHAHAR

  • 8/10/2019 Problem Solving Concept by Meetendra Sir(Unit 5)

    40/41

    40

    TIME COMPLEXITY

    Time Complexity of an algorithm is the amount of computertime it needs to run to completion.

    This is the sum of compile time and run time.

    Some of the reasons for studying time complexity are:

    1. We may be interested to know in advance that whetheran algorithm/program will provide a satisfactory realtime response.

    2. There may be several possible solutions with differenttime requirements.

    To be continued

    MEETENDRA SINGH CHAHAR

  • 8/10/2019 Problem Solving Concept by Meetendra Sir(Unit 5)

    41/41

    41

    We can found complexity of any algorithm using followingnotation:

    Big-Oh notation:Big-Oh is the formal method ofexpressing the upper bound of an algorithms runningtime. It is the measure of the longest amount of time itcould possibly take for the algorithm to complete. Moreformally, for non-negative functions, f(n) and g(n), ifthere exists an integer n

    0

    and a constant c > 0 such thatfor all integers n > n0

    f(n) c.g(n)

    Then f(n) is Big-Oh of g(n). This is denoted as

    f(n) O(g(n))

    MEETENDRA SINGH CHAHAR