4. Algorithms and Data Structures
Overview.
In this chapter we describe and implement some of the most important algorithms and data structures in use on computers today. We begin by considering a powerful framework for measuring and analyzing the efficiency of our programs. This enables us to compare algorithms and accurately predict performance. Next, we consider several novel algorithms for the classic problem of sorting. Then, we build the most important higher level data structures, including stacks, queues, and symbol tables.- 4.1 Performance outlines a scientific method and powerful theory for understanding the performance and resource consumption of the program that we write.
- 4.2 Sorting and Searching describes two classical algorithms - mergesort and binary search - along with several applications where their efficiency plays a critical role.
- 4.3 Stacks and Queues introduces two closely related data structures for manipulating arbitrary large collections of data.
- 4.4 Symbol Tables considers a quintessential data structure known as the symbol table for storing information, and an efficient implementation known as the binary search tree.
- 4.5 Small World Phenomenon presents a case study to investigate the small world phenomenon - the principle that we are all linked by short chains of acquaintances.
Java programs in this chapter.
Below is a list of Java programs in this chapter. Click on the program name to access the Java code; click on the reference number for a brief description; read the textbook for a full discussion.
REF PROGRAM DESCRIPTION 4.1.1 ThreeSum.java 3-sum problem 4.1.2 DoublingTest.java Validating a doubling hypothesis 4.2.1 TwentyQuestions.java Binary search (20 questions) 4.2.2 Gaussian.java Bisection search (function inversion) 4.2.3 BinarySearch.java Binary search (sorted array) 4.2.4 Insertion.java Insertion sort 4.2.5 InsertionTest.java Doubling test for insertion sort 4.2.6 Merge.java Mergesort 4.2.7 FrequencyCount.java Frequency counts 4.2.8 LRS.java Longest repeated substring 4.3.1 ArrayStackOfStrings.java Stack of strings (array) 4.3.2 LinkedStackOfStrings.java Stack of strings (linked list) 4.3.3 DoublingStackOfStrings.java Stack of strings (array doubling) 4.3.4 Stack.java Generic stack 4.3.5 Evaluate.java Expression evaluation 4.3.6 Queue.java Generic FIFO queue (linked list) 4.3.7 MD1Queue.java M/D/1 queue simulation 4.3.8 LoadBalance.java Load balancing simulation 4.4.1 Lookup.java Dictionary lookup 4.4.2 Index.java Indexing 4.4.3 BST.java BST symbol table 4.4.4 DeDup.java Dedup filter 4.5.1 Graph.java Graph data type 4.5.2 IndexGraph.java Using a graph to invert an index 4.5.3 PathFinder.java Shortest-paths client 4.5.4 PathFinder.java Shortest-paths implementation 4.5.5 SmallWorld.java Small-world test