0% found this document useful (0 votes)
156 views

Useful Algorithms Concepts

The document discusses several common algorithm concepts: 1. Greedy algorithms make locally optimal choices at each step in the hopes of finding a global optimum. Examples include making change with bills and shortest path algorithms. 2. Divide and conquer algorithms break problems into smaller subproblems, solve the subproblems recursively, and combine the solutions. Examples are sorting and tree traversal. 3. Dynamic programming improves on naive recursive solutions by storing results of subproblems to avoid recomputing them. Examples include matrix chain multiplication and longest common subsequence. 4. Backtracking algorithms use pruning to iteratively eliminate invalid partial solutions and find all valid ones, such as reconstructing a point set from distances.

Uploaded by

Ahmad Alhour
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
156 views

Useful Algorithms Concepts

The document discusses several common algorithm concepts: 1. Greedy algorithms make locally optimal choices at each step in the hopes of finding a global optimum. Examples include making change with bills and shortest path algorithms. 2. Divide and conquer algorithms break problems into smaller subproblems, solve the subproblems recursively, and combine the solutions. Examples are sorting and tree traversal. 3. Dynamic programming improves on naive recursive solutions by storing results of subproblems to avoid recomputing them. Examples include matrix chain multiplication and longest common subsequence. 4. Backtracking algorithms use pruning to iteratively eliminate invalid partial solutions and find all valid ones, such as reconstructing a point set from distances.

Uploaded by

Ahmad Alhour
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

UsefulAlgorithmConcepts KaiserMd.

Nahiduzzaman Feb2010

#A.Greedyalgorithm Somelocaloptimumischosen;whenthealgorithmterminates,wehopethatthelocaloptimumisequaltotheglobal optimum. ExamplesofPopularGreedyAlgorithms:Dijkstra,Prim,Kruskalalgorithm. ACMUvaExamples:10020,10340,10440 Reallifeexample: Tomakechangeincurrency,repeatedlydispensethelargestdenomination.Togiveoutsixtyninedollarswegiveouta fiftydollarbill,atendollarbill,afivedollarbill,twotwodollarbills.Inthisway,weareguranteedtominimizethe numberofbills.Thatis,firstconsiderthelargestdenominatorin69whichis50andtherestis19.Nowconsiderthe largestdenominatorin19whichis10andtherestis9.Doitrepeatedly. #B.DivideandConquer Divide:Smallerproblemsaresolvedrecursively(exceptthebasecases). Conquer:Solutiontotheoriginalproblemisformedfromthesolutionstothesubproblems. Thesubproblemsshouldbedisjoint(nonoverlapping). Examples:maximumsubsequencesumproblem,lineartimetreetraversalstrategies,mergesort,quicksort. RunningTime:T(N)=2T(N/2)+O(N) i.e O(NlogN) #C.DynamicProgramming Aproblemthatcanbemathematicallyexpressedrecursivelycanalsobeexpressedasarecursivealgorithm,yieldinga significantperformanceimprovementoveranaivesearch. Anyrecursivemathematicalformulacouldbedirectlytranslatedtoarecursivealgorithm,buttheunderlyingrealityis thatoftenthecompilerwillnotdojusticetotherecursivealgorithm,andaninefficientprogramresults.Whenwe suspectthatthisislikelytobethecase,wemustprovidealittlemorehelptothecompiler,byrewritingtherecursive algorithm as anonrecursive algorithmthat systematicallyrecords theanswers tothesubproblems inatable.One techniquethatmakesuseofthisapproachisknownasdynamicprogramming. Examples:Matrixmultiplication,allpairsshortestpath,optimalbinarysearchtree,longestcommonsubsequence ACMUvaExamples:10131,10069,10154,116,10003,10261,10271,10201 #D.BacktrackingAlgorithms It'sacleverimplementationofexhaustivesearch.Inthisalgorithm,alargegroupofpossiblitiesareeliminatedinone stepwhichisknownaspruning. Example: SupposewearegivenNpoints,locatedonthexaxis.Letusassumethatthefirstpoint'sxcoordinateis0andthe pointsaregivenfromlefttoright. Ifwearegivenasetofpoints,itiseasytoconstructthesetofdistancesbetweeneverypairofpoints. Buttheturnpikereconstructionproblemistoreconstructapointsetfromthedistances. SupposewearegiventhedistancesetD={1,2,2,2,3,3,3,4,5,5,5,6,7,8,10}. WeknowthatN=6.Thefirstnumberis0andthelast(6th)numberis10. Weremove10fromD.Nextthelargestremainingdistanceis8,whichmeansthateitherthesecondelementis2orthe 5thelementis8.Weconstructatreeforthesolutionsandafterpropagatingacertainpath,wewillconcludethatone pathisnotthecorrectpathandwewillbacktracktolastcorrectposition.Weneedtodothesepruningsalloverthetree

togetthecorrectresult. ACMUvaExamples:861,10181,10128,10160,10032,10001,704,10270 #E.Appendix: IMPORTANTWEBSITES/FORACM/ICPCPROGRAMMERS: ACMonlinesite:http://onlinejudge.uva.es/ and http://ciijudge.baylor.edu/ Helpingsite:http://www.comp.nus.edu.sg/~stevenha/programming/acmoj.html Onlinebook:http://acm.uva.es/p/Art_of_Programming_Contest_SE_for_uva.pdf References 1.DataStructuresandAlgorithmAnalysisMarkAllenWeiss 2.ProgrammingChallengesStevenS.Skiena,MiguelA.Revilla 3.ArtofProgrammingContestAhmedShamsulArefin

You might also like