## 展开查看详情

1.intro Data Structure

2.2 about The computer program development process requires us to represent data in an effective way develop a suitable step-by-step procedure ( algorithm ), which can be implemented as a computer program Effective data representation ⇒ data structures Development of a suitable step-by-step procedure ⇒ algorithm design methods The study of data structures and algorithms is fundamental to computer science.

3.Clever ways to organize information in order to enable efficient computation What do we mean by clever? What do we mean by efficient?

4.Clever? Efficient? Lists, Stacks, Queues Heaps Binary Search Trees AVL Trees Hash Tables Graphs Disjoint Sets Insert Delete Find Merge Shortest Paths Union Data Structures Algorithms

5.The Need for Data Structures Data structures organize data more efficient programs. More powerful computers more complex applications. More complex applications demand more calculations. Complex computing tasks are unlike our everyday experience.

6.Organizing Data Any organization for a collection of records can be searched, processed in any order, or modified. The choice of data structure and algorithm can make the difference between a program running in a few seconds or many days.

7.Efficiency A solution is said to be efficient if it solves the problem within its resource constraints . Space Time The cost of a solution is the amount of resources that the solution consumes.

8.Memory usage versus run times As well as determining run times, we are also interested in memory usage In general, there is an interesting relationship between memory and time efficiency For a data structure/algorithm: Improving the run time usually requires more memory Reducing the required memory usually requires more run time

9.Memory usage versus run times Warning: programmers often mistake this to suggest that given any solution to a problem, any solution which may be faster must require more memory This guideline not true in general: there may be different data structures and/or algorithms which are both faster and require less memory This requires thought and research

10.Selecting a Data Structure Select a data structure as follows: Analyze the problem to determine the basic operations that must be supported. Quantify the resource constraints for each operation. Select the data structure that best meets these requirements.

11.Some Questions to Ask Are all data inserted into the data structure at the beginning, or are insertions interspersed with other operations? Can data be deleted? Are all data processed in some well-defined order, or is random access allowed?

12.Costs and Benefits Each data structure has costs and benefits. Rarely is one data structure better than another in all situations. Any data structure requires: space for each data item it stores, time to perform each basic operation, programming effort.

13.Costs and Benefits (cont) Each problem has constraints on available space and time. Only after a careful analysis of problem characteristics can we know the best data structure for the task. Bank example: Start account: a few minutes Transactions: a few seconds Close account: overnight

14.Asymptotic Complexity Our notion of efficiency: How the running time of an algorithm scales with the size of its input several ways to further refine: worst case average case amortized over a series of runs

15.C/C ++ Data Structures One of the all time great books in computer science: The Art of Computer Programming (1968-1973) by Donald Knuth Examples in assembly language (and English)! American Scientist says: in top 12 books of the CENTURY! Very little about C/C ++ in class.

16.16 ALGORITHM A set of logical steps to accomplish a task. A “recipe of action”. A way of describing behavior.

17.17 Correct Algorithm It must correctly solve the problem for any valid input data. For the same input data, it must always give the same answer. Invalid input data should produce an error message or some other indication that the algorithm cannot correctly solve the problem. It should not produce an answer when given incorrect data since the user will think that the answer is valid.

18.18 Abstraction Idea : Define/implement the general idea, isolate the details. The steps in the algorithm should be grouped into related modules or blocks. You may use one module inside another module. You may refer to other algorithms by name instead of including all of their steps in the current algorithm.

19.19 Levels of Abstraction Well-designed algorithms will be organized in terms of abstraction. The simple instructions that make up each major logical step are hidden inside modules . By hiding the details inside appropriate modules, we can understand the main ideas without being distracted.

20.20 Computational Abstractions Problem : Calculating a letter grade for the course, based on a student’s various numerical scores (exam, quiz, and hw) and on the weights assigned to each Inputs : Student’s name, hw average, quiz average, exam score, their respective weights Output : Letter grade for the student

21.21 Software Development Problem Understanding Read the problem carefully and try to understand what is required for its solution. Analysis Identify problem inputs and outputs. Design (Top-down design) Map out the modular structure of your algorithm. Give a descriptive identifier for each module. Refine your modular design. Does each module do only one logical task? Subdivide any module that does not, as many times as necessary. Define the interface of each module before writing any code. Begin the bottom-up work of constructing each module.

22.22 Implementation Implement the algorithm as a (C) program. Convert steps of the algorithm into programming language statements. Testing and Verification Test the completed program, and verify that it works as expected. Use different test cases (not one) including critical test cases.

23.23 Algorithm Components Data structures to hold data. Data manipulation instructions to change data values. Conditional expressions to make decisions Control structures to act on decisions. Modules to make the abstraction manageable by abstraction.

24.Queue operations create destroy enqueue dequeue is_empty Queue property : if x is enQed before y is enQed, then x will be deQed before y is deQed FIFO: First In First Out First Example: Queue ADT F E D C B enqueue dequeue G A

25.Applications of the Q Hold jobs for a printer Store packets on network routers Make waitlists fair Breadth first search

26.Linked List Q Data Structure b c d e f front back enqueue(Object x) { back->next = new Node(x); back = back->next; } dequeue() { saved = front->data; temp = front; front = front->next; delete temp ; return saved;} What are tradeoffs? simplicity speed robustness memory usage

27.Course Objectives: To introduce abstract concepts for data organization and manipulation, to show how these concepts are useful in problem solving. Prerequisite : C programming References Data Structure using C, Schaum’s Series Data Structures and Algorithm Analysis in C, by Mark Allen Weiss, Addison-Wesley. Donald E. Knuth, The Art of Computer Programming, Volume 1: Fundamental Algorithms , 3 rd Ed., Addison Wesley, 1997 Problem Solving and Program Design in C, 3rd edition Hanly and Koffman , Addison-Wesley. Data Structures, Algorithms & Software Principles in C, by T.A. Standish, Addison Wesley, 1995 .

28.Courtesy: Alon Halevy Clifford A. Shaffer, Yang Cao; Virginia Tech Nihan Kesim Ç i ç ekli , Department of Computer Engineering, Middle East Technical University