Fundamental Data Structures Zuyd Hogeschool, ICT Contents
Total Page:16
File Type:pdf, Size:1020Kb
Fundamental Data Structures Zuyd Hogeschool, ICT 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 .............................. 5 1.1.5 Typical operations ...................................... 5 1.1.6 Examples ........................................... 6 1.1.7 Implementation ........................................ 7 1.1.8 See also ............................................ 8 1.1.9 Notes ............................................. 8 1.1.10 References .......................................... 8 1.1.11 Further ............................................ 9 1.1.12 External links ......................................... 9 1.2 Data structure ............................................. 9 1.2.1 Overview ........................................... 10 1.2.2 Examples ........................................... 10 1.2.3 Language support ....................................... 11 1.2.4 See also ............................................ 11 1.2.5 References .......................................... 11 1.2.6 Further reading ........................................ 11 1.2.7 External links ......................................... 12 2 Sequences 13 2.1 Array data type ............................................ 13 2.1.1 History ............................................ 13 2.1.2 Abstract arrays ........................................ 14 2.1.3 Implementations ....................................... 14 2.1.4 Language support ....................................... 14 2.1.5 See also ............................................ 17 2.1.6 References .......................................... 17 2.1.7 External links ......................................... 18 2.2 Array data structure .......................................... 18 i ii CONTENTS 2.2.1 History ............................................ 18 2.2.2 Applications .......................................... 19 2.2.3 Element identifier and addressing formulas .......................... 19 2.2.4 Efficiency ........................................... 21 2.2.5 Dimension ........................................... 22 2.2.6 See also ............................................ 23 2.2.7 References .......................................... 23 2.3 Dynamic array ............................................. 24 2.3.1 Bounded-size dynamic arrays and capacity .......................... 25 2.3.2 Geometric expansion and amortized cost ........................... 25 2.3.3 Growth factor ........................................ 25 2.3.4 Performance ......................................... 25 2.3.5 Variants ........................................... 26 2.3.6 Language support ....................................... 26 2.3.7 References .......................................... 26 2.3.8 External links ......................................... 27 2.4 Linked list ............................................... 27 2.4.1 Advantages .......................................... 28 2.4.2 Disadvantages ......................................... 28 2.4.3 History ............................................ 28 2.4.4 Basic concepts and nomenclature ............................... 29 2.4.5 Tradeoffs ........................................... 31 2.4.6 Linked list operations ..................................... 33 2.4.7 Linked lists using arrays of nodes ............................... 35 2.4.8 Language support ....................................... 36 2.4.9 Internal and external storage ................................. 36 2.4.10 Related data structures .................................... 37 2.4.11 Notes ............................................. 38 2.4.12 Footnotes ........................................... 38 2.4.13 References .......................................... 38 2.4.14 External links ......................................... 39 2.5 Doubly linked list ........................................... 39 2.5.1 Nomenclature and implementation .............................. 40 2.5.2 Basic algorithms ....................................... 40 2.5.3 Advanced concepts ...................................... 43 2.5.4 See also ............................................ 43 2.5.5 References .......................................... 43 2.6 Stack (abstract data type) ....................................... 43 2.6.1 History ............................................ 44 2.6.2 Non-essential operations ................................... 44 2.6.3 Software stacks ........................................ 44 CONTENTS iii 2.6.4 Hardware stacks ........................................ 46 2.6.5 Applications .......................................... 48 2.6.6 Security ............................................ 49 2.6.7 See also ............................................ 50 2.6.8 References .......................................... 50 2.6.9 Further reading ........................................ 51 2.6.10 External links ......................................... 51 2.7 Queue (abstract data type) ....................................... 51 2.7.1 Queue implementation .................................... 52 2.7.2 Purely functional implementation ............................... 53 2.7.3 See also ............................................ 53 2.7.4 References .......................................... 53 2.7.5 External links ......................................... 54 2.8 Double-ended queue .......................................... 54 2.8.1 Naming conventions ..................................... 54 2.8.2 Distinctions and sub-types .................................. 54 2.8.3 Operations .......................................... 55 2.8.4 Implementations ....................................... 55 2.8.5 Language support ....................................... 56 2.8.6 Complexity .......................................... 56 2.8.7 Applications ......................................... 57 2.8.8 See also ............................................ 57 2.8.9 References .......................................... 57 2.8.10 External links ......................................... 57 2.9 Circular buffer ............................................. 57 2.9.1 Uses .............................................. 58 2.9.2 How it works ......................................... 59 2.9.3 Circular buffer mechanics ................................... 60 2.9.4 Optimization ......................................... 61 2.9.5 Fixed-length-element and contiguous-block circular buffer ................. 61 2.9.6 External links ......................................... 61 3 Dictionaries 62 3.1 Associative array ........................................... 62 3.1.1 Operations .......................................... 62 3.1.2 Example ............................................ 63 3.1.3 Implementation ........................................ 63 3.1.4 Language support ....................................... 65 3.1.5 Permanent storage ...................................... 65 3.1.6 See also ............................................ 66 3.1.7 References .......................................... 66 3.1.8 External links ......................................... 66 iv CONTENTS 3.2 Association list ............................................ 66 3.2.1 Operation ........................................... 67 3.2.2 Performance ......................................... 67 3.2.3 Applications and software libraries .............................. 67 3.2.4 See also ............................................ 67 3.2.5 References .......................................... 67 3.3 Hash table ............................................... 68 3.3.1 Hashing ............................................ 69 3.3.2 Key statistics ......................................... 70 3.3.3 Collision resolution ...................................... 70 3.3.4 Dynamic resizing ....................................... 75 3.3.5 Performance analysis ..................................... 77 3.3.6 Features ............................................ 77 3.3.7 Uses .............................................. 78 3.3.8 Implementations ....................................... 79 3.3.9 History ............................................ 80 3.3.10 See also ............................................ 80 3.3.11 References .......................................... 80 3.3.12 Further reading ........................................ 81 3.3.13 External links ......................................... 82 3.4 Hash function ............................................. 82 3.4.1 Uses ............................................. 82 3.4.2 Properties .......................................... 85 3.4.3 Hash function algorithms ................................... 87 3.4.4 Locality-sensitive hashing .................................. 91 3.4.5 Origins of the term ...................................... 91 3.4.6 List of hash functions ..................................... 91 3.4.7 See also ............................................ 92 3.4.8 References .......................................... 93 3.4.9 External links ......................................... 93 4 Sets 94 4.1 Set (abstract data type) ........................................ 94 4.1.1 Type theory .......................................... 94 4.1.2 Operations