1 / 10

Design and Analysis of Algorithms & Computational Complexity

Design and Analysis of Algorithms & Computational Complexity. CS490 Koji Tajii. Designing a program means…. 1. Specify what you exactly want to do. What kind of input and output? What is the Precondition and Post condition? 2. Design the Algorithm Pseudocode

oriana
Download Presentation

Design and Analysis of Algorithms & Computational Complexity

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Design and Analysis of Algorithms & Computational Complexity CS490 Koji Tajii

  2. Designing a program means… • 1. Specify what you exactly want to do. • What kind of input and output? • What is the Precondition and Post condition? • 2. Design the Algorithm • Pseudocode • What kind of Data structures are needed? • 3. Translate the program into a programming language • C++ JAVA, etc… • 4. Test and Debug • Does it actually work?

  3. Algorithmic Design Techniques • Divide and Conquer • Decomposing tasks into smaller subtasks • Dynamic Programming • Break down problems into stages • Keep track of what’s going on at each stage as states • Determine the best solution by taking into consideration the states of the previous stage • Greedy • Always choosing the best local solution at the time to eventually get to the final solution.

  4. Example - Traversing a Weighted Graph

  5. Time and Space Complexity • Efficiency of program is determined by its speed and amount of memory space it takes. • Faster and smaller is better but…

  6. Big-O Notation • Order of an algorithm • Rough approximation of number of operations a program will execute to determine its speed 2

  7. Worst, Average, Best Case Scenario • Worst Case • Maximum Number of Operations • Average Case • Average Number of Operations • Best Case • Fewest Number of Operations • Probability of occurrence? • Unless the best-case behavior occurs with high probability, it is generally not used • The worst case occurs often

  8. Example 1 void search(const int a[], int first, int size, int target, bool& found, int& location) { int middle; if(size == 0) found = false; else { middle = first + size/2; if (target == a[middle]) { location = middle; found = true; } else if (target < a[middle]) search(a, first, size/2, target, found, location); else search(a, middle+1, (size-1)/2, target, found, location); } }

  9. Example 2 Void Sort(int A[], int N) { bool sorted = false’ for(int Pass = 1; (Pass < N) && !sorted; ++Pass) { Sorted = true; for(int Index = 0; Index < N-Pass; ++Index) { int NextIndex = Index + 1; if(A[Index] > A[NextIndex]) { swap(A[Index], A[NextIndex]); Sorted = false; } } } }

  10. References • Main Michael & Savitch Walter. Data Structures and Other Objects using C++. Addison-Wesley. 1997. • Walls & Millors. Data Abstraction and Problem Solving with C++. 2nd ed. Addison-Wesley. 1998 • http://mat.gsia.cmu.edu/classes/dynamic/dynamic.html

More Related