C ontents
1 INTRODUCTION 1
What Are Data Structures and Algorithms?....................................................................1
Structure of the Book.......................................................................................................3
The Ruby Programming Language..................................................................................3
Review Questions............................................................................................................3
Exercises..........................................................................................................................4
Review Question Answers...............................................................................................4
2 BUILT-IN TYPES 5
Simple and Structured Types...........................................................................................5
Types in Ruby..................................................................................................................5
Symbol: A Simple Type in Ruby.....................................................................................5
Review Questions............................................................................................................9
Exercises..........................................................................................................................9
Review Question Answers...............................................................................................9
3 ARRAYS 10
Introduction....................................................................................................................10
Varieties of Arrays.........................................................................................................10
Arrays in Ruby...............................................................................................................11
Review Questions..........................................................................................................12
Exercises........................................................................................................................12
Review Question Answers.............................................................................................13
4 ASSERTIONS 14
Introduction....................................................................................................................14
Types of Assertions.......................................................................................................14
Assertions and Abstract Data Types..............................................................................15
Using Assertions............................................................................................................15
Assertions in Ruby.........................................................................................................16
Review Questions..........................................................................................................17
Exercises........................................................................................................................17
Review Question Answers.............................................................................................19
5 CONTAINERS 20
Introduction....................................................................................................................20
Varieties of Containers..................................................................................................20
A Container Taxonomy.................................................................................................20
, Interfaces in Ruby..........................................................................................................21
Exercises........................................................................................................................22
Review Question Answers.............................................................................................23
6 STACKS 24
Introduction....................................................................................................................24
The Stack ADT..............................................................................................................24
The Stack Interface........................................................................................................25
Using Stacks—An Example..........................................................................................25
Contiguous Implementation of the Stack ADT.............................................................26
Linked Implementation of the Stack ADT.....................................................................27
Summary and Conclusion..............................................................................................28
Review Questions..........................................................................................................28
Exercises........................................................................................................................29
Review Question Answers.............................................................................................29
7 QUEUES 31
Introduction....................................................................................................................31
The Queue ADT.............................................................................................................31
The Queue Interface.......................................................................................................31
Using Queues—An Example.........................................................................................32
Contiguous Implementation of the Queue ADT............................................................32
Linked Implementation of the Queue ADT...................................................................34
Summary and Conclusion..............................................................................................35
Review Questions..........................................................................................................35
Exercises........................................................................................................................35
Review Question Answers.............................................................................................36
8 STACKS AND RECURSION 37
Introduction....................................................................................................................37
Balanced Brackets..........................................................................................................38
Infix, Prefix, and Postfix Expressions...........................................................................39
Tail Recursive Algorithms.............................................................................................44
Summary and Conclusion..............................................................................................44
Review Questions..........................................................................................................45
Exercises........................................................................................................................45
Review Question Answers.............................................................................................45
9 COLLECTIONS 47
Introduction....................................................................................................................47
Iteration Design Alternatives.........................................................................................47
The Iterator Design Pattern............................................................................................48
Iteration in Ruby............................................................................................................49
, Collections, Iterators, and Containers............................................................................50
Summary and Conclusion..............................................................................................51
Review Questions..........................................................................................................52
Exercises........................................................................................................................52
Review Question Answers.............................................................................................52
10 LISTS 54
Introduction....................................................................................................................54
The List ADT.................................................................................................................54
The List Interface...........................................................................................................55
Using Lists—An Example.............................................................................................55
Contiguous Implementation of the List ADT................................................................56
Linked Implementation of the List ADT.......................................................................56
Implementing Lists in Ruby..........................................................................................58
Summary and Conclusion..............................................................................................58
Review Questions..........................................................................................................58
Exercises........................................................................................................................58
Review Question Answers.............................................................................................59
11 ANALYZING ALGORITHMS 61
Introduction....................................................................................................................61
Measuring the Amount of Work Done..........................................................................61
Which Operations to Count...........................................................................................62
Best, Worst, and Average Case Complexity..................................................................63
Review Questions..........................................................................................................65
Exercises........................................................................................................................66
Review Question Answers.............................................................................................66
12 FUNCTION GROWTH RATES 68
Introduction....................................................................................................................68
Definitions and Notation................................................................................................68
Establishing the Order of Growth of a Function............................................................69
Applying Orders of Growth...........................................................................................70
Summary and Conclusion..............................................................................................70
Review Questions..........................................................................................................70
Exercises........................................................................................................................70
Review Question Answers.............................................................................................71
17 BINARY TREES 99
Introduction....................................................................................................................99
The Binary Tree ADT....................................................................................................99
The Binary Tree Class.................................................................................................100
Contiguous Implementation of Binary Trees...............................................................102
Linked Implementation of Binary Trees......................................................................102
Summary and Conclusion............................................................................................103
Review Questions........................................................................................................103
Voordelen van het kopen van samenvattingen bij Stuvia op een rij:
Verzekerd van kwaliteit door reviews
Stuvia-klanten hebben meer dan 700.000 samenvattingen beoordeeld. Zo weet je zeker dat je de beste documenten koopt!
Snel en makkelijk kopen
Je betaalt supersnel en eenmalig met iDeal, creditcard of Stuvia-tegoed voor de samenvatting. Zonder lidmaatschap.
Focus op de essentie
Samenvattingen worden geschreven voor en door anderen. Daarom zijn de samenvattingen altijd betrouwbaar en actueel. Zo kom je snel tot de kern!
Veelgestelde vragen
Wat krijg ik als ik dit document koop?
Je krijgt een PDF, die direct beschikbaar is na je aankoop. Het gekochte document is altijd, overal en oneindig toegankelijk via je profiel.
Tevredenheidsgarantie: hoe werkt dat?
Onze tevredenheidsgarantie zorgt ervoor dat je altijd een studiedocument vindt dat goed bij je past. Je vult een formulier in en onze klantenservice regelt de rest.
Van wie koop ik deze samenvatting?
Stuvia is een marktplaats, je koop dit document dus niet van ons, maar van verkoper Knowledgekings. Stuvia faciliteert de betaling aan de verkoper.
Zit ik meteen vast aan een abonnement?
Nee, je koopt alleen deze samenvatting voor €4,93. Je zit daarna nergens aan vast.