+ All Categories
Home > Documents > Data Structure and Algorithm Analysis 2015. About the Course Objective Organize a large amount of...

Data Structure and Algorithm Analysis 2015. About the Course Objective Organize a large amount of...

Date post: 01-Jan-2016
Category:
Upload: erick-mckenzie
View: 222 times
Download: 3 times
Share this document with a friend
26
Data Structure and Algorithm Analysis 2015
Transcript
Page 1: Data Structure and Algorithm Analysis 2015. About the Course Objective Organize a large amount of data Algorithm: the operation on the organized data.

Data Structure and Algorithm Analysis

2015

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

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

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

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

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

Examination

• Algorithm complexity analysis• Linear data structure• Tree and graph• Search, sorting

• [optional] Hash, priority queue

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

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: [email protected]

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

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

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

Math

• Exponents

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

Logarithms

• Definition:• if and only if

• In computer science, we usually use represent

• for all

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

Series

• ;

• ;

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

Recursion

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

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

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) );}

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

Algorithm Analysis

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

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

Notation

• Definitions:• if there are constants and such that when

• if there are constants and such that when

• if and only if and

• if and

• Why we need the above notations?• Computer deals with large data set, i.e. is very big

• When grows large, grows much faster than

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

Complexity level

Function Name

Constant

Logarithmic

Log-squared

Linear

Quadratic

Cubic

Exponential

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

• Rule 1:If and , thena) ,

• Rule 2:If is a polynomial of degree , then

• Rule 3: for any constant .

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

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;}

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

Examples

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

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

Examples

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

Examplesint 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'

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

Assumption

• 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))

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

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:

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

List

• Typical Implementation• ArrayList• LinkList

• Typical operations:• Insert• Append• Find• Delete• Concatenate/join• Reverse• Sum

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

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

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

ArrayList

After append 3,7,4,3

3 7 4 3

Insert (5, 2)

3 5 7 4 3

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

ArrayList

Insert (2, 5)

3 5 7 4 3

3 5 7 4 3

delete (3)

3 5 4 3


Recommended