Date post: | 13-Dec-2015 |
Category: |
Documents |
Upload: | stewart-hudson |
View: | 221 times |
Download: | 2 times |
CSCI 6212Design and Analysis of
Algorithms
Dr. Juman ByunThe George Washington University
Please drop this course if you have not taken the following prerequisite.
Sometimes enthusiasm alone is not enough.
• CSci 1311: Discrete Structures I (3)• CSci 1112: Algorithms and Data Structures
(3)
Official Course Description
• http://www.cs.gwu.edu/academics/courses/graduate/csci-6212
• Design and analysis of algorithms. Turing machines; NP-Complete theory. Algorithmic techniques: divide-and-conquer, greedy, dynamic programming, graph traversal, backtracking, and branch-and-bound. Applications include sorting and searching, graph algorithms, and optimization. Prerequisite: CSci 1311, 1112. (Fall andspring)
• Textbook: Introduction to Algorithms, Cormen, Leiserson, Rivest, and Stein.
Basic Principles of Algorithm Design and
Analysis
Algorithm Design
How to Start the Design ?
• Understand the problem. What are we trying to achieve ?
• Get a rough idea how to solve the problem using your intuition and imagination
Example: Sorting an Array of integers
55 22 44 66 11 33
Example: Sorting an Array of integers
55
22 44 66 11 33
Example: Sorting an Array of integers
5522
44 66 11 33
Example: Sorting an Array of integers
5522
44 66 11 33
Example: Sorting an Array of integers
552244
66 11 33
Example: Sorting an Array of integers
5522 44
66 11 33
Example: Sorting an Array of integers
5522 4466
11 33
Example: Sorting an Array of integers
5522 44 66
11 33
Example: Sorting an Array of integers
5522 44 6611
33
Example: Sorting an Array of integers
5522 44 6611
33
Example: Sorting an Array of integers
5522 44 6611
33
Example: Sorting an Array of integers
5522 44 6611
33
Example: Sorting an Array of integers
5522 44 6611
33
Example: Sorting an Array of integers
5522 44 6611
33
Example: Sorting an Array of integers
5522 44 661133
Example: Sorting an Array of integers
5522 44 661133
Example: Sorting an Array of integers
5522 44 661133
Example: Sorting an Array of integers
5522 44 661133
Example: Sorting an Array of integers
5522 44 6611 33
Accept Concise Notation
• The previous colorful animation was pretty but it took me a some time to create it.
• In order for a human being to perceive the entire problem, you need to compress the problem or commit it into the long-term storage of your brain.
• Algorithmic notation is an excellent way of compressing a problem so that it is easier to remember and handle.
Accept Concise Notation
55 22 44 66 11 33
Accept Concise Notation
5 2 4 6 1 3
Disambiguate it
5 2 4 6 1 3, , , , ,
Abstract it
5 2 4 6 1 3, , , , ,A = { }
Denote it
Insertion Sort (A)1 for j = 2 to A.length2 key = A[j]3 // Insert A[j] into the sorted sequence A[1..j-1]4 i = j - 15 while i > 0 and A[i] > key6 A[i +1] = A[i]7 i = i - 18 A[i + 1] = key
Pascal NotationInsertion Sort (A)1 for j = 2 to A.length2 begin3 key = A[j]4 // Insert A[j] into the sorted sequence A[1..j-1]5 i = j - 16 while i > 0 and A[i] > key7 begin8 A[i +1] = A[i]9 i = i - 110 end11 A[i + 1] = key12 end
C NotationInsertion Sort (A)1 for j = 2 to A.length2 {3 key = A[j]4 // Insert A[j] into the sorted sequence A[1..j-1]5 i = j - 16 while i > 0 and A[i] > key7 {8 A[i +1] = A[i]9 i = i - 110 }11 A[i + 1] = key12 }
Algorithm Analysis
Example: Running (Execution) Time Analysis
Insertion Sort (A)1 for j = 2 to A.length2 key = A[j]3 // Insert A[j] into the sorted sequence A[1..j-1]4 i = j - 15 while i > 0 and A[i] > key6 A[i +1] = A[i]7 i = i - 18 A[i + 1] = key
How many times does each statement execute ?
Insertion Sort (A)1 for j = 2 to A.length2 key = A[j]3 // Insert A[j] into the sorted sequence A[1..j-1]4 i = j - 15 while i > 0 and A[i] > key6 A[i +1] = A[i]7 i = i - 18 A[i + 1] = key
Factors to Consider• Input Size
• Running Time
• Worst-Case
• Best-Case
• Average
• Rate of Growth
Assumptions
• Technologies
• Memory Model: RAM (Random Access Machine/Memory)
• Processor: Single Processor