Source Code for Data Structures and Problem Solving Using Java, Third Edition

LAST UPDATE: May 7, 2008

Here is the source code for Data Structures and Algorithm Analysis in Java (Third Edition), by Mark Allen Weiss. The materials here are copyrighted. I have successfully compiled and tested the programs with JDK 1.5.0.

Organization of Files

  1. Most of the general, standalone, code is in the root directory.
  2. There is an implementation of a large subset of java.util in package weiss.util. Its purpose is to illustrate how the concepts are used in an actual library implementation. This can be found in the weiss\util folder. Some of the sample code imports classes in weiss.util, but you can freely replace all occurrences of weiss.util with java.util. Needless to say, everything in weiss.util has a name clash with java.util, so you should not use wild-card import directives. These files are displayed in BOLDFACE font.
  3. The package weiss.nonstandard, in the weiss\nonstandard folder, contains nonstandard implementations of various data structures. The code is generally simpler that the code in the Java Collections API, and there are occasional name clashes (e.g. LinkedList and Stack). This package also contains priority queue implementations, since that is not part of the Java Collections API. These files are display in ITALICS font.


The code in the root directory should automatically compile if there is no CLASSPATH. Other code will be trickier to compile/run unless you use full names relative to the root directory. Otherwise, the easiest fix is to make sure that the root directory (i.e. the directory in which the weiss folder is found) is on your CLASSPATH, along with .. Let us assume you have extracted everything into the bookcode folder. Note that case-sensitivity may matter, and there is a difference between colons and semicolons.
If you are using an IDE, you will need to update the CLASSPATH using the IDE's own mechanism.

Jar files

An alternative is to install these two jar files (wutil.jar and wnonstandard.jar) in the Java extensions directory. A typical location would be C:\jdk1.5.0\jre\lib\ext. Once this is done, you can run any of the programs that require weiss.util or weiss.nonstandard from pretty much any location. (This is every program in the main distribution directory, except

Complete Bundle

Package Documentation


Chapter 1: Basic Java

Chapter 2: References

Chapter 3: Classes

Chapter 4: Inheritance

Chapter 5: Running Times

Chapter 6: The Collections API, extends java.util.Iterator

Chapter 7: Recursion

Chapter 8: Sorting

Chapter 9: Randomization

Chapter 10: Fun and Games puz.txt

Chapter 11: Applications of Stacks -- Compilers and Parsing

Chapter 12: Utilities

Chapter 13: Simulation

Chapter 14: Shortest Path Algorithms graph1.txt graph2.txt graph3.txt

Chapter 15: Inner Classes and ArrayList Implementation

Chapter 16: Stacks

Chapter 17: Linked Lists

Chapter 18: Trees

Chapter 19: Search Trees

Chapter 20: Hash Tables

Chapter 21: Heaps

Chapter 22: Splay Trees

Chapter 23: Pairing Heaps

Chapter 24: Disjoint Sets

Appendix D: Swing