1 / 20

TECHNICAL UNIVERSITY OF CRETE DEPT OF ELECTRONIC AND COMPUTER ENGINEERING

TECHNICAL UNIVERSITY OF CRETE DEPT OF ELECTRONIC AND COMPUTER ENGINEERING. DATA STRUCTURES AND FILE STRUCTURES Euripides G.M. Petrakis http://www.intelligence.tuc.gr/~petrakis Chania, 2007. Introduction. We study data structures and we learn how to write efficient programs

halia
Download Presentation

TECHNICAL UNIVERSITY OF CRETE DEPT OF ELECTRONIC AND COMPUTER ENGINEERING

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. TECHNICAL UNIVERSITY OF CRETEDEPT OF ELECTRONIC AND COMPUTER ENGINEERING DATA STRUCTURES AND FILE STRUCTURES Euripides G.M. Petrakis http://www.intelligence.tuc.gr/~petrakis Chania, 2007 Abstract Data Types (ADT)

  2. Introduction • We study data structures and we learn how to write efficient programs • this hasn’t to do with programming tricks but rather with • good organization of information and good algorithms that save • computer memory and running time Abstract Data Types (ADT)

  3. Data Structures • Representation of data in the memory • file structure: representation of data on the disk • e.g., collection of records (list, tree, etc) • Efficient programs require efficient data structures • a problem has to be solved within the given time and space constraints Abstract Data Types (ADT)

  4. Problem Constraints • Each problem puts constraints on time and space • e.g., bank example: • start account: a few minutes • transactions: a few seconds • close account: overnight • A solution is efficient if it solves the problem within its space and time constraints • Cost of solution: amount of resources consumed Abstract Data Types (ADT)

  5. Goals of this course • Teach data structures for main memory and disk • Teach algorithms for different tasks and data structures • Teach the idea of trade-offs • there are costs and benefits associated with each data structure and each algorithm • Teach how to measure effectiveness of each algorithm and data structure Abstract Data Types (ADT)

  6. Selecting Data Structures • Analyze the problem to determine the resource constraints a solution must meet • Determine the operations that must be supported • e.g., record search, insertion, deletion etc. • Quantify the constraints for each operation • e.g., search operations must be very fast • Select data structure that best meet these requirements Abstract Data Types (ADT)

  7. Costs & Benefits • Each data structure requires: • space for each data item it stores • time to perform each operation • programming effort to implement it • Each data structure has costs and benefits • rarely one data structure is better than another in all situations • one may permit faster search (or insertion or deletion) operations than another • are all operations the same important? Abstract Data Types (ADT)

  8. Abstract Data Type (ADT) • ADT: definition of a data type in terms of • a set of values and • a set of operations allowed on that data type. • Each ADT operation is defined by its inputs and outputs • ADTs hide implementation details • A data structure is the implementation of an ADT • operations associated with the ADT are implemented by one or more functions Abstract Data Types (ADT)

  9. Logical and Physical forms • Data items have both a logical and a physical form • Logical form: definition of the data item within an ADT • e.g., integers in mathematical sense: +, - • Physical form: implementation of the data item • e.g., 16 or 32 bit integers Abstract Data Types (ADT)

  10. Data Type • ADT:Type + • Operations Data Items: Logical Form • Data Structure: • Storage Space + • functions Data Items: Physical Form Abstract Data Types (ADT)

  11. ADT String: Sequence of chars • ADT function length(s: string): integer; post condition : length = len(s); • ADT function concat(s1,s2: string): string; post condition: concat = s1 + s2; • ADT function substr(s: string, i, j: integer): string; precondition: 0 < i < len(s), 0 < j < len(s) – i + 1 post condition: substr(s, i, j); • ADT function pos(s1, s2): integer; precondition … post condition … Abstract Data Types (ADT)

  12. Definition of an ADT • Depends on the application • Different definitions for the same application • An ADT hides implementation details • different implementations for the same ADT • When the ADT is given, its data type can be used by the programmer • e.g., string, math libraries in C • when the implementation changes the programs need not be changed Abstract Data Types (ADT)

  13. Algorithms • The method that solves a problem • An algorithm takes the input to a problem and transforms it to the output • a mapping of input to output • a problem can have many algorithms • A program is the implementation of an algorithm in some programming language Abstract Data Types (ADT)

  14. Properties of Algorithms • Effectiveness: the algorithm can be written as a program • there are problems for which no algorithm exists • Correctness: finds the correct solution for every input • Termination: terminates after a finite number of steps • each step requires a finite amount of time • Efficiency: makes efficient use of the computer’s resources • Complexity: it must be easy to implement, code and debug Abstract Data Types (ADT)

  15. Tiling Problem • The algorithm inputs a finite set T of tiles • it is assumed that an unlimited number of cards of each type is available • asks whether any finite area, of any size, can be covered using tiles in T so that • the colors in any two touching edges are the same • For any algorithm there can be inputs T for which the algorithm never terminates or finds a wrong answer Abstract Data Types (ADT)

  16. Tile tile types that can tile any area Tile tile types that cannot tile any area From “Algorithmics”, David Harel, Abstract Data Types (ADT)

  17. A Termination Problem • An algorithm must terminate with the correct solution for any input • No one has been able to prove that the algorithm terminates for any positive n although most people believe that it does!! int OddEven( int n ) { while ( n > 1 ) if (( n % 2 ) == 0) n = n / 2; else n = 3n + 1; return n; } Abstract Data Types (ADT)

  18. Taxonomy of Algorithms • An algorithmic problem that admits no algorithm is termed “non-computable” • If it is a decision problem it is termed “undecidable” Abstract Data Types (ADT)

  19. Disk Model • T = Taccess + Trotation + Tread • Block: unit memory size for disk • size of data transferred in main memory per disk access • In most cases page=block=track • e.g., 1, 2, 4, 8Kbytes Abstract Data Types (ADT)

  20. time distance covered by disk head Disk Model (cont.) • Taccess > Trotation > Tread  increase the amount of data which is transferred to the main memory per disk access • large blocks, compression, data in memory • in multi-user systems, the disk head can be anywhere Abstract Data Types (ADT)

More Related