Presentation on theme: "The Design and Analysis of Algorithms"— Presentation transcript:
1 The Design and Analysis of Algorithms by Anany LevitinLecture notes prepared by Lydia Sinapova, Simpson College
2 CHAPTER 1: INTRODUCTION What is an AlgorithmSteps in Designing and Implementing an AlgorithmImportant Problem TypesFundamental Data Structures
3 ALGORITHMA sequence of unambiguous instructions for solving a problem, i.e. for obtaining the required output for any legitimate input ina finite amount of time
4 Important points Non-ambiguity Range of inputs The same algorithm can be represented in different waysSeveral algorithms for solving the same problem
5 gcd(m,n) while n ≠0 do t ← min (m ,n) r ← m mod n m ← n return mt ← min (m ,n)if m % t = 0 goto 3,else goto 43. if n % t = 0 return t,4. t ← t - 15. goto 2
6 Understand the problem Decide on computational meansExact vs approximate solutionData structuresAlgorithm design techniqueDesign an algorithmProve correctnessAnalyze the algorithmCode the algorithm
7 What does it mean to understand the problem? What are the problem objects?What are the operations applied to the objects?Deciding on computational meansHow the objects would be represented?How the operations would be implemented?
8 Design an algorithm Prove correctness Build a computational model of the solving processProve correctnessCorrect output for every legitimate input in finite timeBased on correct math formulaBy induction
9 Analyze the algorithm Coding Efficiency: time and space Simplicity Generality: range of inputs, special casesOptimality:no other algorithm can do betterCodingHow the objects and operations in thealgorithm are represented in the chosen programming language?
10 Important problem types SortingSearchingString processingGraph problemsCombinatorial problemsGeometric problemsNumerical problems
11 Fundamental data structures Linear data structuresArrayLinked listStackQueueOperations: search, delete, insertImplementation: static, dynamic
12 Fundamental data structures Non-linear data structuresGraphsTrees : connected graph without cyclesRooted treesOrdered treesBinary treesGraph representation: adjacency lists,adjacency matrixTree representation: as graphs; binary nodes
13 Fundamental data structures Sets, Bags, DictionariesSet: unordered collection of distinct elementsOperations: membership, union, intersectionRepresentation: bit string; linear structureBag: unordered collection,elements may be repeatedDictionary: a bag with operations search, add, delete
14 Conclusion Algorithm classification Design techniques By types of problemsBy design techniqueDesign techniquesa general approach to solving problems