






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An introduction to algorithms, their role in problem solving, and how they are used in computer programming. Learn about the properties of algorithms, the main stages involved in creating them, and the advantages and disadvantages of using algorithms. Additionally, discover the concept of flowcharts and their role in representing algorithms.
Typology: Study notes
1 / 12
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