Presentation is loading. Please wait.

Presentation is loading. Please wait.

Data Structures and Algorithm Analysis Introduction Lecturer: Ligang Dong, egan Tel: 28877721 , 13306517055 Office: SIEE Building.

Similar presentations


Presentation on theme: "Data Structures and Algorithm Analysis Introduction Lecturer: Ligang Dong, egan Tel: 28877721 , 13306517055 Office: SIEE Building."— Presentation transcript:

1 Data Structures and Algorithm Analysis Introduction Lecturer: Ligang Dong, egan Email: donglg@zjgsu.edu.cn Tel: 28877721 , 13306517055 Office: SIEE Building 305

2 Textbook Mark Allen Weiss, Data Structures and Algorithm Analysis in C, China Machine Press. E-book is available. http://netcom.zjsu.edu.cn/person/dlg/d ata_structure.htm

3 Scheduling Instruction Lectures: Tuesday 8:05am Programming Practices: Friday 9:50am

4 Grading Final exam: 55% Weekly Homeworks:45%(15*3%) Posted every Tuesday Due Next Tuesday before class (solution posted after class) If you have difficulties in solving the homework, please ask for help during Programming Practices in Friday. No late submission accepted

5 Why Learn Data Structures and Algorithms? One of the basic rules concerning programming is to break the program down into modules. Each module is a logical unit and does a specific job. Its size is kept small by calling other modules. Two types of modules “data” module ------ data structure “procedure” module ------ algorithm

6 Why Learn Data Structures and Algorithms? Modularity has several advantages. It is much easier to debug small routines than large routines; It is easier for several people to work on a modular program simultaneously; A well-written modular program places certain dependencies in only one routing, making changes easier.

7 What are Data Structures and Algorithms? Data Structures are methods of organizing large amounts of data. An algorithm is a procedure that consists of finite set of instructions which, given an input from some set of possible inputs, enables us to obtain an output through a systematic execution of the instructions.

8 ADT(Abstract Data Types) Data Structure Algorithms Software Programs Software Engineering Programming Languages

9 Abstract Data Types (ADTs) An abstract data type (ADT) is a set of objects such as lists, sets, and graphs, along with their operations (e.g., insert, delete) Integers, reals, and booleans are data types. Integers, reals, and booleans have operations associated with them, and so do ADTs. Nowhere in an ADT ’ s definition is there any mention of how the set of operations is implemented.

10 Example Problem: Given 10 test results (80, 85, 77, 56, 68, 83, 90, 92, 80, 98) of C language programming of Tom, what is the average score?

11 Example Solution main() { int sum , average; int t1,t2,t3,t4,t5,t6,t7,t8,t9,t10; t1=80;t2=85;t3=77;t4=56;t5=68; t6=83;t7=90;t8=92;t9=80;t10=98; sum= t1+t2+t3+t4+t5+t6+t7+t8+t9+t10; average=sum/10; printf(“Sum=%d\n”,sum); printf(“Average=%d\n”, average); }

12 Example Better Solution main() { int sum , average ; int i; int t[10] =80 , 85 , 77 , 56 , 68 , 83 , 90 , 92 , 80 , 98} sum=0; for(i=0; i<10; i++) sum=sum+t[i]; average=sum/10; printf(“Sum=%d\n”,sum); printf(“Average=%d\n”, average); } By using an array instead of n variables, with a loop instead of n assignments, the program is simpler.

13 Contents Chapter 1 Introduction ( 0.5 Week ) C Review ( 1.5 Week ) Chapter 2 Algorithm Analysis ( 1 Week ) Chapter 3 Lists, Stacks, and Queues ( 1 Week ) Chapter 4 Trees ( 2 Weeks ) Chapter 5 Hashing ( 1 Week ) Chapter 6 Priority Queues (Heaps) ( 1 Week ) Chapter 7 Sorting ( 2 Weeks ) Chapter 8 Disjoint Set ADT ( 1 Week ) Chapter 9 Graph Algorithms ( 2 Weeks ) Chapter 10 Algorithm Design Techniques ( 2 Weeks )

14 Mathematical Foundation Series and summation: 1 + 2 + 3 + ……. N = N(N+1)/2 (arithmetic series) 1 + r 2 + r 3 +………r N-1 = (1- r N )/(1-r), (geometric series)  1/(1-r), r < 1, large N Sum of squares: 1 + 2 2 + 3 2 +………N 2 = N(N + 1)(2N + 1)/6

15 Mathematical Foundation log x a = b if x b = a we will use base 2 mostly, but may use other bases occasionally Will encounter log functions again and again! log (ab ) = log a + log b log (a/b ) = log a - log b log a b = b log a log b a = log c a/ log c b a log n = n log a a mn = (a m ) n = (a n ) m a m+n = a m a n (2  n) 0.5 (n/e) n  n   (2  n) 0.5 (n/e) n + (1/12n)

16 Mathematical Foundation Proof Method1: Proof By Induction Prove that a property holds for input size 1 Assume that the property holds for input size n. Show that the property holds for input size n+1. Then, the property holds for all input sizes, n.

17 Mathematical Foundation Example of Proof By Induction: Prove that the sum of 1+2+…..+n = n(n+1)/2 Holds for n = 1 Let it hold for n 1+2+….+n = n(n+1)/2 When n+1 1+2+….+n+(n+1) = n(n+1)/2 + (n+1) = (n+1)(n+2)/2.

18 Mathematical Foundation Proof Method2: Proof By Counter Example Want to prove something is not true! Give an example to show that it does not hold!

19 Mathematical Foundation Proof Method3: Proof By Contradiction Suppose, you want to prove something. Assume that what you want to prove does not hold. Then show that you arrive at an impossiblity.

20 Mathematical Foundation Example of Proof By Contradiction:The number of prime numbers is not finite! Suppose there are finite number of primes, k primes. (we do not include 1 in primes here) We know k  2. Let the primes be P 1, P 2, ……… P k Z = P 1 P 2 ……… P k + 1 Z is not divisible by P 1, P 2, ……… P k Z is greater than P 1, P 2, ……… P k Thus Z is not a prime. We know that a number is either prime or divisible by primes. Hence contradiction. So our assumption that there are finite number of primes is not true.

21 Homework #1 At least complete two of the following: 1.1 Prove the following formulas 1.2 Write a program to solve the selection problem. (Suppose you have a group of n numbers and would like to determine the kth largest.) 1.3 Based on 1.2, let k = n/2, show the original location of kth largest. And draw a table showing the running time of your program for various values of n (4<=n<=20).

22 Hint You should submit the homework using the WS Word file through email. Your program must be submitted with output. DO NOT write any code until you understand what the program does, the design of the program, and the output that it produces. Writing code before understanding the program will simply be a waste of your time, and will result in a program that does not work!! As with any large program, it is probably a good idea to finish the easy parts first and then slowly complete the harder parts. Develop your code in small pieces, and test each part of your code as you write it. Your program is graded according to correctness, readability, robustness, efficiency.


Download ppt "Data Structures and Algorithm Analysis Introduction Lecturer: Ligang Dong, egan Tel: 28877721 , 13306517055 Office: SIEE Building."

Similar presentations


Ads by Google