






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







Incomputerprogrammingterm,analgorithm isusefulforyoutosolvethe problem inthemostefficientway;Computerprogrammingcontainsan enormouspart,ofgeneratingunambiguous,sequence-wiseproceduresfor thecomputertofollowinordertoproduceparticularresults.Algorithms areconsideredtobethefoundationofcomputerprogramming. Therearemanyalgorithmsavailabletoday,eachwithitsownadvantages anddisadvantages.Eachalgorithm hasitsownbestcase,worstcase,and averagerunningtime.Youralgorithm determineshowefficientcanyour system solvetheproblem. Algorithm canbedefineasastepbystepproceduretosolveagiven problem.YouCanappliedtheconceptofalgorithm inourdailyactivities, notjustincomputeralone.Arecipeinacookbookisanexcellentexample ofanalgorithm.Therecipeincludestherequirementsforthecookingor ingredientsandthemethodofcookingthem untilyouendupwithanice cookeddish. Inthesameway,algorithmsexecutedbyacomputercancombinemillions of elementary steps,such as additions and subtractions,into a complicatedmathematicalcalculation.Also bymeansofalgorithms,a computercan controla manufacturing process orco-ordinate the reservationsofanairlineastheyarereceivedfrom theticketofficesall overthecountry.Algorithmsforsuchlarge-scaleprocessesare,ofcourse, verycomplex,buttheyarebuiltupfrom pieces. Oneoftheobstaclesto overcomeinusingacomputerto solveyour problemsisthatoftranslatingtheideaofthealgorithm tocomputercode (program).Peoplecannotnormallyunderstandtheactualmachinecode thatthecomputerneedstorunaprogram,soprogramsarewrittenina programminglanguagesuchasCorPascal,whichisthenconvertedinto machinecodeforthecomputertorun.
In the problem-solving phase ofcomputerprogramming,you willbe designingalgorithms.Thismeansthatyouwillhavetobeconsciousofthe strategies you use to solve problems in order to apply them to programmingproblems.Thesealgorithmscanbedesignedthroughthe useofflowchartsorpseudocode. Whatistheroleofalgorithm inproblem solving? Thestepstakentosolveaproblem iscalledasalgorithm.Incomputer programmingterm,analgorithm isusefulforyoutosolvetheproblem in themostefficientway.Averysimpleexampleofalgorithm is sortingalgorithm. Analgorithm mustsatisfythefollowingproperties: Input:Thealgorithm musthaveinputvaluesfrom aspecifiedset. Output:Thealgorithm mustproducetheoutputvaluesfrom aspecifiedset of inputvalues.... Effectiveness:Itmustbepossibletoperform eachstepof thealgorithm correctlyandinafiniteamountoftime. Definiteness:Allstepsofthealgorithm mustbepreciselydefined. Finiteness:Foranyinput,algorithm mustterminateafteralimitednumber ofsteps. MainStagesinvolvedincreatinganAlgorithm. Themainstagesinvolvedincreatinganalgorithm: DataInput DataProcessing ResultOutput.
N:BProgrammerandUserscanbedifferentinsomecases. Example( 1 )WriteanAlgorithm tologintoyourFacebookaccount. Solution: Step 1 :Start Step 2 :ConnecttoInternet Step 3 :Gotowww.facebookcom Step 4 :EnterUserID&Password Step 5 :ClickLoginbutton Step 6 :Stop Example( 2 )WriteanAlgorithm foraverageof 3 Integer Solution: Step 1 :Start Step 2 :OutputāAverageof 3 Integerā Step 3 :OutputāInputof 3 Integerā Step 4 :Inputx,y,z Step 5 :Ave<(x+y+z)/ 3 Step 6 :OutputāAverageāAve Step 7 :Stop. Example( 3 )WriteanAlgorithm forthelargestof 2 Integers. Solution. Step 1 :Start Step 2 :OutputāLargestof 2 Integersā
Step 3 :OutputāInput 2 Integersā Step 4 :Inputx,y Step 5 :If(x> 9 y) Step 6 :Outputālargestisāx Step 7 :Else Step 8 :Outputālargestisāy Step 9 :Stop AdvantagesoftheAlgorithm ļ· Itidentifiesthesolutionprocess,decisionpointsandvariables requiredtosolvetheproblem. ļ· Ithelpsindividingahugeproblem intosmallermanageablestepsof thesolution. ļ· Theanalysisandspecificationoftheprocessleadtotheefficiency. ļ· Separationofthestepsdivideslabouranddevelopmentexpertise. DisadvantagesoftheAlgorithm ļ· Ataspecificpoint,thealgorithm terminates. ļ· Inabilitytosolveproblemsthatgeneratenon-computationalresults. ļ· Consumesalotoftime. Flowchart Flowchartisatypeofdiagram thatrepresentanalgorithms.Aninformation diagram madeupofdifferentshapesshowsthedataflow. Flowchartisatooldevelopedinthecomputerindustry,forshowingthe stepsinvolvedinaprocess.Thearrowsshowtheorderinwhichtheyoccur. Flowchartingcombinessymbolsandflow lines,toshow figurativelythe operationofanalgorithm. Incomputing,therearedozensofdifferentsymbolsusedinflowcharting (thereareevennationalandinternationalflowchartingsymbolstandards).
GeneralRulesforflowcharting 1 .AllboxesoftheflowchartareconnectedwithArrows.(Notlines) 2 .Flowchartsymbolshaveanentrypointonthetopofthesymbolwith nootherentrypoints.Theexitpointforallflowchartsymbolsison thebottom exceptfortheDecisionsymbol. 3 .TheDecisionsymbolhastwoexitpoints;thesecanbeonthesidesor thebottom andoneside. 4 .Generallyaflowchartwillflow from top to bottom.However,an upwardflowcanbeshownaslongasitdoesnotexceed 3 symbols. 5 .Connectorsareusedtoconnectbreaksintheflowchart.Examples are:
6 .From onepagetoanotherpage. 7 .From thebottom ofthepagetothetopofthesamepage. 8 .Anupwardflowofmorethen 3 symbols 9 .SubroutinesandInterruptprogramshavetheirownandindependent flowcharts.
( 3 )Flowchartforlargestof 2 Integers. āāAverageof 3 Integerāā āāInput 3 Integerā Stop āInputx,y,zā Ave (x+y+z)/ 3 OutputāAveis āAve
AdvantagesoftheFlowChart Start āāLargestof 2 Integersāā āāInput 2 Integerā Stop OutputāLargestisā Y OutputāLargest isāx Inputx,y x>y