Contents
- Why Study Data Structures and AlgorithmsWhat You Need for This BookOrganization of the BookConventions Used in This BookUsing Code ExamplesSafari® Books OnlineHow to Contact UsContent UpdatesOctober 20, 2015Acknowledgments
- The JavaScript EnvironmentJavaScript Programming PracticesDeclaring and Initializing VariablesArithmetic and Math Library Functions in JavaScriptDecision ConstructsRepetition ConstructsFunctionsVariable ScopeRecursionObjects and Object-Oriented ProgrammingSummary
- JavaScript Arrays DefinedUsing ArraysCreating ArraysAccessing and Writing Array ElementsCreating Arrays from StringsAggregate Array OperationsAccessor FunctionsSearching for a ValueString Representations of ArraysCreating New Arrays from Existing ArraysMutator FunctionsAdding Elements to an ArrayRemoving Elements from an ArrayAdding and Removing Elements from the Middle of an ArrayPutting Array Elements in OrderIterator FunctionsNon–Array-Generating Iterator FunctionsIterator Functions That Return a New ArrayTwo-Dimensional and Multidimensional ArraysCreating Two-Dimensional ArraysProcessing Two-Dimensional Array ElementsJagged ArraysArrays of ObjectsArrays in ObjectsExercises
- A List ADTA List Class ImplementationAppend: Adding an Element to a ListRemove: Removing an Element from a ListFind: Finding an Element in a ListLength: Determining the Number of Elements in a ListtoString: Retrieving a List’s ElementsInsert: Inserting an Element into a ListClear: Removing All Elements from a ListContains: Determining if a Given Value Is in a ListMoving To and Retrieving a List ElementIterating Through a ListIterating Through a ListA List-Based ApplicationReading Text FilesUsing Lists to Manage a KioskExercises
- Stack OperationsA Stack ImplementationUsing the Stack ClassMultiple Base ConversionsPalindromesDemonstrating RecursionExercises
- Queue OperationsAn Array-Based Queue Class ImplementationUsing the Queue Class: Assigning Partners at a Square DanceSorting Data with QueuesPriority QueuesExercises
- Shortcomings of ArraysLinked Lists DefinedAn Object-Based Linked List DesignThe Node ClassThe Linked List ClassInserting New NodesRemoving Nodes from a Linked ListDoubly Linked ListsCircularly Linked ListsOther Linked List FunctionsExercises
- The Dictionary ClassAuxiliary Functions for the Dictionary ClassAdding Sorting to the Dictionary ClassExercises
- An Overview of HashingA Hash Table ClassChoosing a Hash FunctionA Better Hash FunctionHashing Integer KeysStoring and Retrieving Data in a Hash TableHandling CollisionsSeparate ChainingLinear ProbingExercises
- Fundamental Set Definitions, Operations, and PropertiesSet DefinitionsSet OperationsThe Set Class ImplementationMore Set OperationsExercises
- Trees DefinedBinary Trees and Binary Search TreesBuilding a Binary Search Tree ImplementationTraversing a Binary Search TreeBST SearchesSearching for the Minimum and Maximum ValueSearching for a Specific ValueRemoving Nodes from a BSTCounting OccurrencesExercises
- Graph DefinitionsReal-World Systems Modeled by GraphsThe Graph ClassRepresenting EdgesBuilding a GraphSearching a GraphDepth-First SearchBreadth-First SearchFinding the Shortest PathBreadth-First Search Leads to Shortest PathsDetermining PathsTopological SortingAn Algorithm for Topological SortingImplementing the Topological Sorting AlgorithmExercises
- An Array Test BedGenerating Random DataBasic Sorting AlgorithmsBubble SortSelection SortInsertion SortTiming Comparisons of the Basic Sorting AlgorithmsAdvanced Sorting AlgorithmsThe Shellsort AlgorithmThe Mergesort AlgorithmThe Quicksort AlgorithmExercises
- Commonly Used Functions in ExamplesSearching for Minimum and Maximum ValuesUsing Self-Organizing DataBinary SearchCounting OccurrencesSearching Textual DataExercises
- Dynamic ProgrammingA Dynamic Programming Example: Computing Fibonacci NumbersFinding the Longest Common SubstringThe Knapsack Problem: A Recursive SolutionThe Knapsack Problem: A Dynamic Programming SolutionGreedy AlgorithmsA First Greedy Algorithm Example: The Coin-Changing ProblemA Greedy Algorithm Solution to the Knapsack ProblemExercises
Overview
As an experienced JavaScript developer moving to server-side programming, you need to implement classic data structures and algorithms associated with conventional object-oriented languages like C# and Java. This practical guide shows you how to work hands-on with a variety of storage mechanisms—including linked lists, stacks, queues, and graphs—within the constraints of the JavaScript environment.
Determine which data structures and algorithms are most appropriate for the problems you’re trying to solve, and understand the tradeoffs when using them in a JavaScript program. An overview of the JavaScript features used throughout the book is also included.
This book covers:
- Arrays and lists: the most common data structures
- Stacks and queues: more complex list-like data structures
- Linked lists: how they overcome the shortcomings of arrays
- Dictionaries: storing data as key-value pairs
- Hashing: good for quick insertion and retrieval
- Sets: useful for storing unique elements that appear only once
- Binary Trees: storing data in a hierarchical manner
- Graphs and graph algorithms: ideal for modeling networks
- Algorithms: including those that help you sort or search data
- Advanced algorithms: dynamic programming and greedy algorithms