Download presentation
Presentation is loading. Please wait.
Published byChristopher Hodge Modified over 8 years ago
1
1 Data Structures and Programming 資料結構與程式設計
2
2 Instructor: 顏嗣鈞 E-mail: yen@cc.ee.ntu.edu.tw Web: http://www.ee.ntu.edu.tw/~yen Time: 9:10-12:00 AM, Tuesdaay Place: BL 113 Office hours: by appointment Class web page: http://www.ee.ntu.edu.tw/~yen/courses/ds15.html
3
3 PREREQUISITES Familiarity in PASCAL, C, C++, or JAVA.
4
4 Required textbook: Data Structures & Algorithm Analysis in C++ (3 nd Ed.), Mark Weiss, Addison Wesley.
5
5 TOPICS PRELIMINARIES: Introduction. Algorithm analysis. ABSTRACT DATA TYPES: Stacks. Queues. Lists. List operations. List representations. List traversals. Doubly linked lists. TREES: Tree operations. Tree representations. Tree traversals. Threaded trees. Binary trees. AVL trees. 2-3 trees. B-trees. Red-black trees. Binomial trees. Splay trees, and more. HASHING: Chaining. Open addressing. Collision handling. PRIORITY QUEUES: Binary heaps. Binomial heaps. Fibonacci heaps. Min-max heaps. Leftist heaps. Skew heaps. SORTING: Insertion sort. Selection sort. Quicksort. Heapsort. Mergesort. Shellsort. Lower bound of sorting. INTRODUCTION TO PARALLEL PROGRAMMING DISJOINT SETS: Set operations. Set representations. Union-find. Path compression. GRAPHS: Graph operations. Graph representations. Basic graph algorithms. AMORTIZED ANALYSIS. Binomial heaps, Skew heaps. Fibonacci heaps. ADVANCED DATA STRUCTURES: Tries. Top-down splay trees, and more.
6
6 Grading Homework + Prog. Assignments: 25-30% Midterm exam.: 35-40% Final exam.: 35-40%
7
7 Academic Integrity ● With the exception of group assignments, the work (including homework, programming assignments, tests) must be the result of your individual effort. This implies that one student should never have in his/her possession a copy of all or part of another student's homework. It is your responsibility to protect your work from unauthorized access. Academic dishonesty has no place in a university, in particular, in NTUEE. It wastes our time and yours, and it is unfair to the majority of students. Any form of cheating will automatically result in a failing grade in the course and will be reported to the Dean's office.
8
8 Data Structures vs. Programming Data Structures ProgramsAlgorithms +=
9
9 Motivating Example: Minimum Spanning Tree Given an undirected graph G = (V, E) with weights on the edges, a minimum spanning tree (MST) of G is a subset T E such that –T is connected and has no cycles, –T covers (spans) all vertices in V, and –sum of the weights of all edges in T is minimum.
10
10 Prim's MST Algorithm
11
11 Another Example: Shortest Path Given a weighted graph and two vertices u and v, we want to find a path of minimum total weight between u and v. –Length of a path is the sum of the weights of its edges. Applications: Internet packet routing, Flight reservations, Driving directions ORD PVD MIA DFW SFO LAX LGA HNL 849 802 1387 1743 1843 1099 1120 1233 337 2555 142 1205
12
12 Dijkstra’s algorithm CB A E D F 0 428 4 8 71 25 2 39 C B A E D F 0 328 511 4 8 71 25 2 39 C B A E D F 0 328 58 4 8 71 25 2 39 C B A E D F 0 327 58 4 8 71 25 2 39
13
13 Example (cont.) CB A E D F 0 327 58 4 8 71 25 2 39 CB A E D F 0 327 58 4 8 71 25 2 39
14
14 Questions Operations performed? CB A D 0 428 4 8 2 Find neighbors CB E D F 4 2 8 Find/remove minimum C B E D F 328 511 71 25 39 Update neighbors
15
15 Key steps C B E D F 4 8 2 C B E D F 4 8 2 Find/remove minimum B E D F 3 8 5 11 Update
16
16 Straightforward approach BCDEF 824 Find min: scan thru the array; Remove item BDEF 83511 Update: a left-right scan again Questions: 1.Is the above efficient? 2.Can we do better?
17
17 Dijkstra/Prim 1 make-heap |V| insert |V| delete-min |E| decrease-key Priority Queues make-heap Operation insert find-min delete-min union decrease-key delete 1 Binary log N 1 N 1 Binomial log N 1 Fibonacci * 1 1 log N 1 1 1 Relaxed 1 1 log N 1 1 1 Linked List 1 N N 1 1 N is-empty11111 Heaps O(|E| + |V| log |V|)O(|E| log |V|)O(|V| 2 )
18
18 Life Cycle of Software Development
19
19 Is this program correct? —How do we know? int Find(float[] a, int m, int n, float x) { while (m < n) { int j = (m+n) / 2 ; if (a[j] < x) { m = j+ 1 ; } else if (x < a[j]) { n = j-1; } else { return j; } } return - 1 ; }
20
20 Making sense of programs Program semantics defines programming language –e.g., Hoare logic, Dijkstra's weakest preconditions Specifications record design decisions –bridge intent and code Tools amplify human effort –manage details –find inconsistencies –ensure quality
21
21 Program Correctness (Example) if (x != null) { n = x.f; } else { n = z-1; z++; } a = new char[n]; true n >= 0 z-1 >= 0 x != null && x.f >= 0 (x != null ==> x != null && x.f >= 0) && (x == null ==> z-1 >= 0)
22
22 Data “Structures” General areas include: ● Sequential storage ● Hierarchical storage ● Adjacency storage
23
23 Goal Learn to write efficient and elegant software –How to choose between two algorithms Which to use?bubble-sort, insertion-sort, merge-sort –How to choose appropriate data structures Which to use?array, vector, linked list, binary tree
24
24 Why should you care? Complex data structures and algorithms are used in every real program –Data compression uses trees: MP3, Gif, etc… –Networking uses graphs: Routers and telephone networks –Security uses complex math algorithms: GCD and large decimals –Operating systems use queues and stacks: Scheduling and recursion Many problems can only be solved using complex data structures and algorithms
25
25 In this course, we will look at: –different techniques for storing, accessing, and modifying information on a computer –algorithms which can efficiently solve problems We will see that all data structures have trade-offs – there is no ultimate data structure... The choice depends on our requirements
26
26 What this course is NOT about This course is not about C++ –Although we will use C++ to implement some of the concepts This course is not about MATH –Although we will use math to formalize many of the concepts Competency in both math and C++ is therefore welcomed. –C++: inheritance, overloading, overriding, files, linked-lists, multi- dimensional arrays –Math: polynomials, logarithms, inductive proofs, logic
27
27 The Big Idea Definition of Abstract Data Type –A collection of data along with specific operations that manipulate that data –Has nothing to do with a programming language! Two fundamental goals of algorithm analysis –Correctness: Prove that a program works as expected –Efficiency: Characterize the run-time of an algorithm
28
28 The Big Idea Alternative goals of algorithm analysis –Characterize the amount of memory required –Characterize the size of a programs code –Characterize the readability of a program –Characterize the robustness of a program
29
29 Why study data structures? Clever ways to organize information in order to enable efficient computation Systems Theory AI Graphics Applications DataStructures Databases NetworkingGames
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.