Write My Paper Button

WhatsApp Widget

Computational problem solution | My Assignment Tutor

02/10/20171ALGORITHMS &PSEUDOCODEComputational problem solution■ Mastery of a language syntax is not sufficient■ You must fully understand the problem and design asolution before any code– Develop the algorithms first (e.g. usingpseudocode, flow charts)■ Experienced programmers spend most of the timedeveloping algorithms than coding.02/10/20172Problem solution steps■ Problem definition: Understand the problem clearly first beforeformulating a solution■ Problem … Continue reading “Computational problem solution | My Assignment Tutor”

02/10/20171ALGORITHMS &PSEUDOCODEComputational problem solution■ Mastery of a language syntax is not sufficient■ You must fully understand the problem and design asolution before any code– Develop the algorithms first (e.g. usingpseudocode, flow charts)■ Experienced programmers spend most of the timedeveloping algorithms than coding.02/10/20172Problem solution steps■ Problem definition: Understand the problem clearly first beforeformulating a solution■ Problem analysis: Develop mathematical formulation, define inputs,outputs and their relationships, state any assumptions■ Algorithm design: Formulate a series of step by step instructions forsolving the problem (pseudocode or flow charts)■ Program development: Conversion of the algorithm into the desiredprogramming language■ Testing and verification: Does the program perform its intendedfunction, debugging, verificationWhat is an algorithm■ Algorithm is a step by step procedure for solving a problem in a finiteamount of time.■ Typically, algorithms go with the data structures to manipulate thedata (e.g., the methods of a class).■ Most algorithms transform input objects into output objects.– Input – An algorithm has input values from a specified set– Output – From each set of input values an algorithm producesoutput values from a specified set. The output values are thesolution to the problem.02/10/20173Properties of algorithms■ Algorithms must:• Be definite – the algorithms must have a defined steps• Be correct: always give a correct solution• Terminate: must terminate in a finite time• Be complete: always gives a solution when one exists• Generic- The algorithm should be applicable for allproblems of the desired form, not just for a particular set ofinput values.Designing algorithms■ A general approach is:• Understand the problem• Select an algorithm (e.g., brute force, divide and conqueretc.…)• Select appropriate data structures• Prove the algorithm terminates, that it is complete and correct02/10/20174Pseudocode andFlow chartsPseudocode■ Pseudocode is an English like presentation of the steps needed tosolve a problem.■ Should make sense when read (though not necessarilygrammatically correct)■ It allows the programmer to solve the problem at a level that hidesthe detail while concentrating on the problem requirements, i.e.concentrate on the big picture.■ Pseudocode is language independent.■ Pseudocode will be used to write the algorithm once the datastructure is fully understood.■ Pseudocode is indented like code■ Pseudocode is followed by implementation with the appropriatelanguage such as Python, C, C#, Java etc.02/10/20175Program componentsEvery program is only a combination of these structures: Sequence,Selection & Repetition• Sequence – statements executed one after the othere.g. sum = sum+i;i=i+1;• Condition/decision – evaluation of a logical expression and executionof different parts of the program, depending on the results of theevaluatione.g if…else statement & switch statement• Repetition – implements looping processinge.g. for statementwhile statementdo…while statementPseudo code – example■ Simple programming problem: Convert a price from British poundsinto Dollars.■ PseudocodeCompute the price of the item in dollarsInput: Price in poundsOutput: Price in dollarsBEGINSet DollarPrice = (3 /2) * PoundPricePrint DollarPriceEND02/10/20176Pseudo code – exampleBEGINget coordinates of measuring devicerecord measurementcheck measurement for being within rangeIF measurement is within range THENload measurement in databaseELSE ask another measurementEND IFENDReading data from a sensorInput: base and exponentOutput: resultBEGINCheck base and exponent are legalresult = 1While exponent >0result = result*baseexponent = exponent -1End WhilePrint resultENDPseudo code – exampleRaising a number to a power02/10/20177Flow chartBasic components:• Boxes – contain processing step(instructions to be executed)• Diamonds – contain logical conditions• Arrows – show the flow of the control– one direction only• Boxes with round corners – indicate the start and endpointsum=sum+ii=i+1F TStartEndFlow chart – sequenceSequence – two (or more) processing boxes connectedby an arrowFirst taskNext taskMore statements can be included in each box)Fahrenheit = int(raw_input(“Enter atemperature in Fahrenheit: “))Celsius = (Fahrenheit – 32) *5.0/9.0print “Temperature:”, Fahrenheit, “F= “, Celsius, ” C”02/10/20178Programming constructs: Sequencestructureinstruction 1;instruction 2;instruction 3;…Examples:■ Getting ready in the morning to go to work■ Recipe to make your favorite food■ Assembly instructions for a toyWhat is common about these activities?SequenceProgramming constructs: Conditionalstatements■ Go to movie or study?■ Eat salad or sandwich?■ Go to job or go for higher studies?What is the common thing here? Selection.IF condition is true THENdo this;ELSEdo that;ENDIF02/10/20179Programming constructs: Loops■ Eat chips from a packet■ Go on a shopping spree with lot of cash!■ Take an exam that has several questionsWhat is the common thing here?Repetition / LoopsWHILE (more items to process)process the next item;ENDWHILEFOR month = 1 to 12do monthly processingENDFORNEXT TOPIC…INTRODUCTION TOPROGRAMMING INPYTHON

Don`t copy text!
WeCreativez WhatsApp Support
Our customer support team is here to answer your questions. Ask us anything!
???? Hi, how can I help?