Presentation is loading. Please wait.

Presentation is loading. Please wait.

Data Structure and Algorithm Analysis 2015. About the Course Objective Organize a large amount of data Algorithm: the operation on the organized data.

Similar presentations


Presentation on theme: "Data Structure and Algorithm Analysis 2015. About the Course Objective Organize a large amount of data Algorithm: the operation on the organized data."— Presentation transcript:

1 Data Structure and Algorithm Analysis 2015

2 About the Course Objective Organize a large amount of data Algorithm: the operation on the organized data Analysis the running time of the algorithms Prerequisite courses: Programming Fundamentals (C/C++ or Java) Discrete Math

3 About the Course At the end of the course Familiar with the common data structures Internal and external Fundamental algorithms Traverse, sorting, merge etc Time and space complexity of above algorithms Evaluation Final exam Assignment Textbook Mark Allen Weiss, Data Structure and Algorithm Analysis in C

4 Examination Algorithm complexity analysis Linear data structure Tree and graph Search, sorting [optional] Hash, priority queue

5 Self Introduction Name: Zhu Huiquan (Nate) Education in China and Singapore Research areas: formal method, data mining and graph algorithm Mobile:+86 131 8909 7204 Email: cszhq@outlook.com

6 Programming Fundamentals Variables and data types (struct) Control flow: sequential, conditional and loop Function Array and collection Input/output, exceptions

7 Math

8 Logarithms

9 Series

10 Recursion Base cases Making progress Ensure all recursive calls work Avoid duplicate work on the same instance

11 Recursion programming An example Questions: Does it follow the four rules in previous slide? int Fibonacci(int n) { if ( n == 0 ) return 0; else if ( n == 1 ) return 1; else return ( Fibonacci(n-1) + Fibonacci(n-2) ); }

12 Algorithm Analysis How to describe the complexity of the algorithms Typical complexity levels Analysis with an example

13 Notation

14 Complexity level FunctionName Constant Logarithmic Log-squared Linear Quadratic Cubic Exponential

15

16 Examples int A(int n) { if(n%2==0) return B(n); else return C(n); } int A(int n) { int i = 0, s = 0; while(i<n) { s = s + B(n); i++; } return s; } int B(n) { int s = 0; for(int j = 0; j < n; j++) s = s + j; return s; }

17

18 Examples void print_out(int n) { if(n<10) { printf(“%d\n”, n); } else { print_out(n/10); printf(“%d\n”, n%10); }//else }

19 Examples

20 int bsearch(int a[], int x, int n) { int low, mid, high; low = 0; high = n - 1; whle(low <= high) { mid = (low + high) / 2; if(a[mid] < x) low = mid + 1; else if (a[mid] < x) high = mid - 1; else return(mid); } //while return(NOT_FOOUND); } low highmid low highmid high'

21 Assumption The same time cost for all basic operation No complex operation, like hardware acceleration No memory constraint Random access on external storage To measure the complexity Based on the input size n Average running time and worse-case running time, in O(f(n))

22 Abstract Dada Types An abstract data type (ADT) is a set of operations. Abstract, no implementation defined Modular design Template concept in C++ Example: List: sequential Set/Collection:

23 List Typical Implementation ArrayList LinkList Typical operations: Insert Append Find Delete Concatenate/join Reverse Sum

24 ArrayList Allocated N units of space for the list of size n, n <N An integer to store the current size “n” Typical operations: Insert Append Find Delete Concatenate/join Reverse Sum

25 ArrayList After append 3,7,4,3 3743 Insert (5, 2) 35743

26 ArrayList Insert (2, 5) 35743 35743 delete (3) 3543


Download ppt "Data Structure and Algorithm Analysis 2015. About the Course Objective Organize a large amount of data Algorithm: the operation on the organized data."

Similar presentations


Ads by Google