Understanding Algorithms and Problem Solving: Part 2 - Algorithms, Study notes of Computer Science

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

2020/2021

Uploaded on 11/27/2021

saeed-abdullahi
saeed-abdullahi 🇳🇬

2 documents

1 / 12

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
INTRODUCTIONTOPROBLEM SOLVING PART2NOTE.
ALGORITHMS
Incomputerprogrammingterm,analgorithmisusefulforyoutosolvethe
problem inthemostefficientway;Computerprogrammingcontainsan
enormouspart,ofgeneratingunambiguous,sequence-wiseproceduresfor
thecomputertofollowinordertoproduceparticularresults.Algorithms
areconsideredtobethefoundationofcomputerprogramming.
Therearemanyalgorithmsavailabletoday,eachwithitsownadvantages
anddisadvantages.Eachalgorithmhasitsownbestcase,worstcase,and
averagerunningtime.Youralgorithmdetermineshowefficientcanyour
systemsolvetheproblem.
Algorithmcanbedefineasastepbystepproceduretosolveagiven
problem.YouCanappliedtheconceptofalgorithminourdailyactivities,
notjustincomputeralone.Arecipeinacookbookisanexcellentexample
ofanalgorithm.Therecipeincludestherequirementsforthecookingor
ingredientsandthemethodofcookingthemuntilyouendupwithanice
cookeddish.
Inthesameway,algorithmsexecutedbyacomputercancombinemillions
of elementary steps,such as additions and subtractions,into a
complicatedmathematicalcalculation.Alsobymeansofalgorithms,a
computercan controla manufacturing process orco-ordinate the
reservationsofanairlineastheyarereceivedfrom theticketofficesall
overthecountry.Algorithmsforsuchlarge-scaleprocessesare,ofcourse,
verycomplex,buttheyarebuiltupfrom pieces.
Oneoftheobstaclestoovercomeinusing acomputertosolveyour
problemsisthatoftranslatingtheideaofthealgorithm tocomputercode
(program).Peoplecannotnormallyunderstandtheactualmachinecode
thatthecomputerneedstorunaprogram,soprogramsarewrittenina
programminglanguagesuchasCorPascal,whichisthenconvertedinto
machinecodeforthecomputertorun.
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Understanding Algorithms and Problem Solving: Part 2 - Algorithms and more Study notes Computer Science in PDF only on Docsity!

INTRODUCTIONTOPROBLEM SOLVING PART 2 NOTE.

ALGORITHMS

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.

  1. AllflowchartsstartwithaTerminalorPredefinedProcess(for interruptprogramsorsubroutines)symbol.
  2. Allflowchartsendwithaterminaloracontentiousloop. FlowchartExamples, ( 1 )flowchartusingtheabovefacebookloginalgorithm. Solution.

( 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