Fundamental Data Structures Contents
Total Page:16
File Type:pdf, Size:1020Kb
Fundamental Data Structures Contents 1 Introduction 1 1.1 Abstract data type ........................................... 1 1.1.1 Examples ........................................... 1 1.1.2 Introduction .......................................... 2 1.1.3 Defining an abstract data type ................................. 2 1.1.4 Advantages of abstract data typing .............................. 4 1.1.5 Typical operations ...................................... 4 1.1.6 Examples ........................................... 5 1.1.7 Implementation ........................................ 5 1.1.8 See also ............................................ 6 1.1.9 Notes ............................................. 6 1.1.10 References .......................................... 6 1.1.11 Further ............................................ 7 1.1.12 External links ......................................... 7 1.2 Data structure ............................................. 7 1.2.1 Overview ........................................... 7 1.2.2 Examples ........................................... 7 1.2.3 Language support ....................................... 8 1.2.4 See also ............................................ 8 1.2.5 References .......................................... 8 1.2.6 Further reading ........................................ 8 1.2.7 External links ......................................... 9 1.3 Analysis of algorithms ......................................... 9 1.3.1 Cost models ......................................... 9 1.3.2 Run-time analysis ....................................... 10 1.3.3 Relevance ........................................... 12 1.3.4 Constant factors ........................................ 12 1.3.5 See also ............................................ 12 1.3.6 Notes ............................................. 12 1.3.7 References .......................................... 13 1.4 Amortized analysis .......................................... 13 1.4.1 History ............................................ 13 i ii CONTENTS 1.4.2 Method ............................................ 13 1.4.3 Examples ........................................... 13 1.4.4 Common use ......................................... 14 1.4.5 References .......................................... 14 1.5 Accounting method .......................................... 14 1.5.1 The method .......................................... 14 1.5.2 Examples ........................................... 15 1.5.3 References .......................................... 15 1.6 Potential method ............................................ 15 1.6.1 Definition of amortized time ................................. 15 1.6.2 Relation between amortized and actual time ......................... 16 1.6.3 Amortized analysis of worst-case inputs ........................... 16 1.6.4 Examples ........................................... 16 1.6.5 Applications .......................................... 17 1.6.6 References .......................................... 17 2 Sequences 18 2.1 Array data type ............................................ 18 2.1.1 History ............................................ 18 2.1.2 Abstract arrays ........................................ 18 2.1.3 Implementations ....................................... 19 2.1.4 Language support ....................................... 19 2.1.5 See also ............................................ 21 2.1.6 References .......................................... 21 2.1.7 External links ......................................... 21 2.2 Array data structure .......................................... 21 2.2.1 History ............................................ 22 2.2.2 Applications .......................................... 22 2.2.3 Element identifier and addressing formulas .......................... 22 2.2.4 Efficiency ........................................... 24 2.2.5 Dimension ........................................... 25 2.2.6 See also ............................................ 25 2.2.7 References .......................................... 25 2.3 Dynamic array ............................................. 26 2.3.1 Bounded-size dynamic arrays and capacity .......................... 26 2.3.2 Geometric expansion and amortized cost ........................... 26 2.3.3 Growth factor ........................................ 27 2.3.4 Performance ......................................... 27 2.3.5 Variants ........................................... 27 2.3.6 Language support ....................................... 28 2.3.7 References .......................................... 28 2.3.8 External links ......................................... 28 CONTENTS iii 2.4 Linked list ............................................... 28 2.4.1 Advantages .......................................... 29 2.4.2 Disadvantages ......................................... 29 2.4.3 History ............................................ 29 2.4.4 Basic concepts and nomenclature ............................... 30 2.4.5 Tradeoffs ........................................... 31 2.4.6 Linked list operations ..................................... 33 2.4.7 Linked lists using arrays of nodes ............................... 34 2.4.8 Language support ....................................... 35 2.4.9 Internal and external storage ................................. 35 2.4.10 Related data structures .................................... 36 2.4.11 Notes ............................................. 37 2.4.12 Footnotes ........................................... 37 2.4.13 References .......................................... 37 2.4.14 External links ......................................... 38 2.5 Doubly linked list ........................................... 38 2.5.1 Nomenclature and implementation .............................. 38 2.5.2 Basic algorithms ....................................... 38 2.5.3 Advanced concepts ...................................... 41 2.5.4 See also ............................................ 41 2.5.5 References .......................................... 41 2.6 Stack (abstract data type) ....................................... 41 2.6.1 History ............................................ 42 2.6.2 Non-essential operations ................................... 42 2.6.3 Software stacks ........................................ 42 2.6.4 Hardware stacks ........................................ 43 2.6.5 Applications .......................................... 45 2.6.6 Security ............................................ 45 2.6.7 See also ............................................ 46 2.6.8 References .......................................... 46 2.6.9 Further reading ........................................ 46 2.6.10 External links ......................................... 46 2.7 Queue (abstract data type) ....................................... 46 2.7.1 Queue implementation .................................... 47 2.7.2 Purely functional implementation ............................... 47 2.7.3 See also ............................................ 48 2.7.4 References .......................................... 48 2.7.5 External links ......................................... 48 2.8 Double-ended queue .......................................... 48 2.8.1 Naming conventions ..................................... 49 2.8.2 Distinctions and sub-types .................................. 49 iv CONTENTS 2.8.3 Operations .......................................... 49 2.8.4 Implementations ....................................... 49 2.8.5 Language support ....................................... 50 2.8.6 Complexity .......................................... 50 2.8.7 Applications ......................................... 51 2.8.8 See also ............................................ 51 2.8.9 References .......................................... 51 2.8.10 External links ......................................... 51 2.9 Circular buffer ............................................. 51 2.9.1 Uses .............................................. 51 2.9.2 How it works ......................................... 52 2.9.3 Circular buffer mechanics ................................... 52 2.9.4 Optimization ......................................... 53 2.9.5 Fixed-length-element and contiguous-block circular buffer ................. 53 2.9.6 External links ......................................... 53 3 Dictionaries 54 3.1 Associative array ........................................... 54 3.1.1 Operations .......................................... 54 3.1.2 Example ............................................ 55 3.1.3 Implementation ........................................ 55 3.1.4 Language support ....................................... 55 3.1.5 Permanent storage ...................................... 56 3.1.6 See also ............................................ 56 3.1.7 References .......................................... 56 3.1.8 External links ......................................... 56 3.2 Association list ............................................ 57 3.2.1 Operation ........................................... 57 3.2.2 Performance ......................................... 57 3.2.3 Applications and software libraries .............................. 57 3.2.4 See also ............................................ 57 3.2.5 References .......................................... 57 3.3 Hash table ............................................... 58 3.3.1 Hashing ...........................................