Data structures & algorithms in Java

2nd ed.
  • 4.0 (1 rating)
  • 33 Want to read
  • 1 Currently reading
  • 1 Have read

My Reading Lists:

Create a new list

  • 4.0 (1 rating)
  • 33 Want to read
  • 1 Currently reading
  • 1 Have read

Buy this book

Last edited by Drini
September 13, 2025 | History

Data structures & algorithms in Java

2nd ed.
  • 4.0 (1 rating)
  • 33 Want to read
  • 1 Currently reading
  • 1 Have read

Data Structures and Algorithms in Java, Second Edition is designed to be easy to read and understand although the topic itself is complicated. Algorithms are the procedures that software programs use to manipulate data structures. Besides clear and simple example programs, the author includes a workshop as a small demonstration program executable on a Web browser. The programs demonstrate in graphical form what data structures look like and how they operate. In the second edition, the program is rewritten to improve operation and clarify the algorithms, the example programs are revised to work with the latest version of the Java JDK, and questions and exercises will be added at the end of each chapter making the book more useful to readers.

Publish Date
Publisher
Sams
Language
English
Pages
776

Buy this book

Previews available in: English

Edition Availability
Cover of: Data Structures and Algorithms in Java
Data Structures and Algorithms in Java
2017, Pearson Education, Limited
in English
Cover of: Data Structures and Algorithms in Java
Data Structures and Algorithms in Java
2005, Pearson Education
Electronic resource in English
Cover of: Data structures & algorithms in Java
Data structures & algorithms in Java
2003, Sams
in English - 2nd ed.

Add another edition?

Book Details


Table of Contents

Introduction
Page 1
What's New in the Second Edition
Page 1
Additional Topics
Page 1
End-of-Chapter Questions
Page 2
Experiments
Page 2
Programming Projects
Page 2
What This Book Is About
Page 2
What's Different About This Book
Page 3
Easy to Understand
Page 3
Workshop Applets
Page 4
Java Example Code
Page 5
Who This Book Is For
Page 5
What You Need to Know Before You Read This Book
Page 5
The Software You Need to Use This Book
Page 6
How This Book Is Organized
Page 6
Enjoy Yourself!
Page 8
1. Overview
Page 9
What Are Data Structures and Algorithms Good For?
Page 9
Real-World Data Storage
Page 10
Programmer's Tools
Page 11
Real-World Modeling
Page 11
Overview of Data Structures
Page 11
Overview of Algorithms
Page 12
Some Definitions
Page 13
Database
Page 13
Record
Page 13
Field
Page 13
Key
Page 14
Object-Oriented Programming
Page 14
Problems with Procedural Languages
Page 14
Objects in a Nutshell
Page 15
A Runnable Object-Oriented Program
Page 18
Inheritance and Polymorphism
Page 21
Software Engineering
Page 21
Java for C++ Programmers
Page 22
No Pointers
Page 22
Overloaded Operators
Page 25
Primitive Variable Types
Page 25
Input/Output
Page 26
Java Library Data Structures
Page 29
Summary
Page 30
Questions
Page 30
2. Arrays
Page 33
The Array Workshop Applet
Page 33
Insertion
Page 35
Searching
Page 36
Deletion
Page 36
The Duplicates Issue
Page 37
Not Too Swift
Page 39
The Basics of Arrays in Java
Page 39
Creating an Array
Page 40
Accessing Array Elements
Page 40
Initialization
Page 41
An Array Example
Page 41
Dividing a Program into Classes
Page 44
Classes LowArray and LowArrayApp
Page 46
Class Interfaces
Page 46
Not So Convenient
Page 47
Who's Responsible for What?
Page 48
The highArray.java Example
Page 48
The User's Life Made Easier
Page 52
Abstraction
Page 52
The Ordered Workshop Applet
Page 52
Linear Search
Page 53
Binary Search
Page 54
Java Code for an Ordered Array
Page 56
Binary Search with the find() Method
Page 56
The OrdArray Class
Page 58
Advantages of Ordered Arrays
Page 61
Logarithms
Page 62
The Equation
Page 63
The Opposite of Raising Two to a Power
Page 64
Storing Objects
Page 64
The Person Class
Page 65
The classDataArray.java Program
Page 65
Big O Notation
Page 70
Insertion in an Unordered Array: Constant
Page 70
Linear Search: Proportional to N
Page 70
Binary Search: Proportional to log(N)
Page 71
Don't Need the Constant
Page 71
Why Not Use Arrays for Everything?
Page 72
Summary
Page 73
Questions
Page 74
Experiments
Page 75
Programming Projects
Page 76
3. Simple Sorting
Page 77
How Would You Do It?
Page 78
Bubble Sort
Page 79
Bubble Sort on the Baseball Players
Page 79
The BubbleSort Workshop Applet
Page 81
Java Code for a Bubble Sort
Page 85
Invariants
Page 88
Efficiency of the Bubble Sort
Page 88
Selection Sort
Page 89
Selection Sort on the Baseball Players
Page 89
The SelectSort Workshop Applet
Page 90
Java Code for Selection Sort
Page 92
Invariant
Page 95
Efficiency of the Selection Sort
Page 95
Insertion Sort
Page 95
Insertion Sort on the Baseball Players
Page 95
The InsertSort Workshop Applet
Page 97
Java Code for Insertion Sort
Page 99
Invariants in the Insertion Sort
Page 103
Efficiency of the Insertion Sort
Page 103
Sorting Objects
Page 103
Java Code for Sorting Objects
Page 104
Lexicographical Comparisons
Page 107
Stability
Page 107
Comparing the Simple Sorts
Page 108
Summary
Page 108
Questions
Page 109
Experiments
Page 111
Programming Projects
Page 112
4. Stacks and Queues
Page 115
A Different Kind of Structure
Page 115
Programmer's Tools
Page 115
Restricted Access
Page 116
More Abstract
Page 116
Stacks
Page 116
The Postal Analogy
Page 117
The Stack Workshop Applet
Page 118
Java Code for a Stack
Page 120
Stack Example 1: Reversing a Word
Page 124
Stack Example 2: Delimiter Matching
Page 127
Efficiency of Stacks
Page 132
Queues
Page 132
The Queue Workshop Applet
Page 133
A Circular Queue
Page 136
Java Code for a Queue
Page 137
Efficiency of Queues
Page 142
Deques
Page 143
Priority Queues
Page 143
The PriorityQ Workshop Applet
Page 144
Java Code for a Priority Queue
Page 147
Efficiency of Priority Queues
Page 149
Parsing Arithmetic Expressions
Page 149
Postfix Notation
Page 150
Translating Infix to Postfix
Page 151
Evaluating Postfix Expressions
Page 167
Summary
Page 173
Questions
Page 174
Experiments
Page 176
Programming Projects
Page 176
5. Linked Lists
Page 179
Links
Page 179
References and Basic Types
Page 180
Relationship, Not Position
Page 182
The LinkList Workshop Applet
Page 183
The Insert Button
Page 183
The Find Button
Page 184
The Delete Button
Page 184
A Simple Linked List
Page 185
The Link Class
Page 185
The LinkList Class
Page 186
The insertFirst() Method
Page 187
The deleteFirst() Method
Page 188
The displayList() Method
Page 189
The linkList.java Program
Page 190
Finding and Deleting Specified Links
Page 193
The find() Method
Page 196
The delete() Method
Page 196
Other Methods
Page 197
Double-Ended Lists
Page 198
Linked-List Efficiency
Page 202
Abstract Data Types
Page 202
A Stack Implemented by a Linked List
Page 203
A Queue Implemented by a Linked List
Page 206
Data Types and Abstraction
Page 210
ADT Lists
Page 211
ADTs as a Design Tool
Page 212
Sorted Lists
Page 212
Java Code to Insert an Item in a Sorted List
Page 213
The sortedList.java Program
Page 215
Efficiency of Sorted Linked Lists
Page 218
List Insertion Sort
Page 218
Doubly Linked Lists
Page 221
Traversal
Page 222
Insertion
Page 223
Deletion
Page 225
The doublyLinked.java Program
Page 226
Doubly Linked List as Basis for Deques
Page 231
Iterators
Page 231
A Reference in the List Itself?
Page 232
An Iterator Class
Page 232
Additional Iterator Features
Page 233
Iterator Methods
Page 234
The interIterator.java Program
Page 235
Where Does the Iterator Point?
Page 242
The atEnd() Method
Page 242
Iterative Operations
Page 243
Other Methods
Page 244
Summary
Page 244
Questions
Page 245
Experiments
Page 247
Programming Projects
Page 248
6. Recursion
Page 251
Triangular Numbers
Page 251
Finding the nth Term Using a Loop
Page 252
Finding the nth Term Using Recursion
Page 253
The triangle.java Program
Page 255
What's Really Happening?
Page 257
Characteristics of Recursive Methods
Page 259
Is Recursion Efficient?
Page 259
Mathematical Induction
Page 259
Factorials
Page 260
Anagrams
Page 262
A Recursive Binary Search
Page 268
Recursion Replaces the Loop
Page 268
Divide-and-Conquer Algorithms
Page 272
The Towers of Hanoi
Page 273
The Towers Workshop Applet
Page 274
Moving Subtrees
Page 275
The Recursive Algorithm
Page 276
The towers.java Program
Page 277
Mergesort
Page 279
Merging Two Sorted Arrays
Page 280
Sorting by Merging
Page 283
The MergeSort Workshop Applet
Page 285
The mergeSort.java Program
Page 287
Efficiency of the Mergesort
Page 291
Eliminating Recursion
Page 294
Recursion and Stacks
Page 294
Simulating a Recursive Method
Page 294
What Does This Prove?
Page 301
Some Interesting Recursive Applications
Page 303
Raising a Number to a Power
Page 303
The Knapsack Problem
Page 305
Combinations: Picking a Team
Page 306
Summary
Page 308
Questions
Page 310
Experiments
Page 312
Programming Projects
Page 312
7. Advanced Sorting
Page 315
Shellsort
Page 315
Insertion Sort: Too Many Copies
Page 316
N-Sorting
Page 316
Diminishing Gaps
Page 317
The Shellsort Workshop Applet
Page 319
Java Code for the Shellsort
Page 321
Other Interval Sequences
Page 324
Efficiency of the Shellsort
Page 324
Partitioning
Page 325
The Partition Workshop Applet
Page 325
The partition.java Program
Page 327
The Partition Algorithm
Page 330
Efficiency of the Partition Algorithm
Page 332
Quicksort
Page 333
The Quicksort Algorithm
Page 333
Choosing a Pivot Value
Page 335
The QuickSort1 Workshop Applet
Page 340
Degenerates to O(N^2) Performance
Page 344
Median-of-Three Partitioning
Page 345
Handling Small Partitions
Page 350
Removing Recursion
Page 354
Efficiency of Quicksort
Page 355
Radix Sort
Page 357
Algorithm for the Radix Sort
Page 358
Designing a Program
Page 358
Efficiency of the Radix Sort
Page 359
Summary
Page 359
Questions
Page 361
Experiments
Page 363
Programming Projects
Page 363
8. Binary Trees
Page 365
Why Use Binary Trees?
Page 365
Slow Insertion in an Ordered Array
Page 365
Slow Searching in a Linked List
Page 366
Trees to the Rescue
Page 366
What Is a Tree?
Page 366
Tree Terminology
Page 367
Path
Page 368
Root
Page 368
Parent
Page 369
Child
Page 369
Leaf
Page 369
Subtree
Page 369
Visiting
Page 369
Traversing
Page 369
Levels
Page 369
Keys
Page 369
Binary Trees
Page 370
An Analogy
Page 370
How Do Binary Search Trees Work?
Page 371
The Binary Tree Workshop Applet
Page 371
Representing the Tree in Java Code
Page 373
Finding a Node
Page 376
Using the Workshop Applet to Find a Node
Page 376
Java Code for Finding a Node
Page 377
Tree Efficiency
Page 378
Inserting a Node
Page 378
Using the Workshop Applet to Insert a Node
Page 379
Java Code for Inserting a Node
Page 379
Traversing the Tree
Page 381
Inorder Traversal
Page 381
Java Code for Traversing
Page 382
Traversing a Three-Node Tree
Page 382
Traversing with the Workshop Applet
Page 384
Preorder and Postorder Traversals
Page 385
Finding Maximum and Minimum Values
Page 388
Deleting a Node
Page 389
Case 1: The Node Has No Children
Page 389
Case 2: The Node Has One Child
Page 391
Case 3: The Node Has Two Children
Page 393
The Efficiency of Binary Trees
Page 401
Trees Represented as Arrays
Page 403
Duplicate Keys
Page 404
The Complete tree.java Program
Page 405
The Huffman Code
Page 415
Character Codes
Page 415
Decoding with the Huffman Tree
Page 417
Creating the Huffman Tree
Page 418
Coding the Message
Page 420
Creating the Huffman Code
Page 421
Summary
Page 422
Questions
Page 423
Experiments
Page 425
Programming Projects
Page 425
9. Red-Black Trees
Page 429
Our Approach to the Discussion
Page 429
Conceptual
Page 430
Top-Down Insertion
Page 430
Balanced and Unbalanced Trees
Page 430
Degenerates to O(N)
Page 431
Balance to the Rescue
Page 432
Red-Black Tree Characteristics
Page 432
Fixing Rule Violations
Page 434
Using the RBTree Workshop Applet
Page 434
Clicking on a Node
Page 435
The Start Button
Page 435
The Ins Button
Page 435
The Del Button
Page 436
The Flip Button
Page 436
The RoL Button
Page 436
The RoR Button
Page 436
The R/B Button
Page 436
Text Messages
Page 437
Where's the Find Button?
Page 437
Experimenting with the Workshop Applet
Page 437
Experiment 1: Inserting Two Red Nodes
Page 437
Experiment 2: Rotations
Page 438
Experiment 3: Color Flips
Page 439
Experiment 4: An Unbalanced Tree
Page 439
More Experiments
Page 440
The Red-Black Rules and Balanced Trees
Page 440
Null Children
Page 441
Rotations
Page 441
Simple Rotations
Page 442
The Weird Crossover Node
Page 442
Subtrees on the Move
Page 444
Human Beings Versus Computers
Page 445
Inserting a New Node
Page 445
Preview of the Insertion Process
Page 446
Color Flips on the Way Down
Page 446
Rotations After the Node Is Inserted
Page 448
Rotations on the Way Down
Page 454
Deletion
Page 457
The Efficiency of Red-Black Trees
Page 457
Red-Black Tree Implementation
Page 458
Other Balanced Trees
Page 458
Summary
Page 459
Questions
Page 460
Experiments
Page 462
10. 2-3-4 Trees and External Storage
Page 463
Introduction to 2-3-4 Trees
Page 463
What's in a Name?
Page 464
2-3-4 Tree Organization
Page 465
Searching a 2-3-4 Tree
Page 466
Insertion
Page 466
Node Splits
Page 467
Splitting the Root
Page 468
Splitting on the Way Down
Page 469
The Tree234 Workshop Applet
Page 470
The Fill Button
Page 471
The Find Button
Page 471
The Ins Button
Page 472
The Zoom Button
Page 472
Viewing Different Nodes
Page 473
Experiments
Page 474
Java Code for a 2-3-4 Tree
Page 475
The DataItem Class
Page 475
The Node Class
Page 475
The Tree234 Class
Page 476
The Tree234App Class
Page 477
The Complete tree234.java Program
Page 478
2-3-4 Trees and Red-Black Trees
Page 486
Transformation from 2-3-4 to Red-Black
Page 486
Operational Equivalence
Page 488
Efficiency of 2-3-4 Trees
Page 491
Speed
Page 491
Storage Requirements
Page 491
2-3 Trees
Page 492
Node Splits
Page 492
Implementation
Page 494
External Storage
Page 496
Accessing External Data
Page 496
Sequential Ordering
Page 499
B-Trees
Page 500
Indexing
Page 506
Complex Search Criteria
Page 509
Sorting External Files
Page 509
Summary
Page 513
Questions
Page 514
Experiments
Page 516
Programming Projects
Page 516
11. Hash Tables
Page 519
Introduction to Hashing
Page 520
Employee Numbers as Keys
Page 520
A Dictionary
Page 521
Hashing
Page 525
Collisions
Page 527
Open Addressing
Page 528
Linear Probing
Page 528
Java Code for a Linear Probe Hash Table
Page 533
Quadratic Probing
Page 542
Double Hashing
Page 544
Separate Chaining
Page 552
The HashChain Workshop Applet
Page 552
Java Code for Separate Chaining
Page 555
Hash Functions
Page 561
Quick Computation
Page 561
Random Keys
Page 562
Non-Random Keys
Page 562
Hashing Strings
Page 563
Folding
Page 566
Hashing Efficiency
Page 566
Open Addressing
Page 566
Separate Chaining
Page 568
Open Addressing Versus Separate Chaining
Page 570
Hashing and External Storage
Page 571
Table of File Pointers
Page 571
Non-Full Blocks
Page 571
Full Blocks
Page 572
Summary
Page 573
Questions
Page 574
Experiments
Page 576
Programming Projects
Page 577
12. Heaps
Page 579
Introduction to Heaps
Page 580
Priority Queues, Heaps, and ADTs
Page 581
Weakly Ordered
Page 582
Removal
Page 583
Insertion
Page 585
Not Really Swapped
Page 586
The Heap Workshop Applet
Page 587
The Fill Button
Page 587
The Change Button
Page 588
The Remove Button
Page 588
The Insert Button
Page 588
Java Code for Heaps
Page 588
Insertion
Page 589
Removal
Page 590
Key Change
Page 591
The Array Size
Page 592
The heap.java Program
Page 592
Expanding the Heap Array
Page 599
Efficiency of Heap Operations
Page 599
A Tree-based Heap
Page 600
Heapsort
Page 601
Trickling Down in Place
Page 602
Using the Same Array
Page 604
The heapSort.java Program
Page 605
The Efficiency of Heapsort
Page 610
Summary
Page 610
Questions
Page 611
Experiments
Page 612
Programming Projects
Page 612
13. Graphs
Page 615
Introduction to Graphs
Page 615
Definitions
Page 616
Historical Note
Page 618
Representing a Graph in a Program
Page 619
Adding Vertices and Edges to a Graph
Page 622
The Graph Class
Page 622
Searches
Page 623
Depth-First Search
Page 625
Breadth-First Search
Page 636
Minimum Spanning Trees
Page 643
GraphN Workshop Applet
Page 644
Java Code for the Minimum Spanning Tree
Page 644
The mst.java Program
Page 645
Topological Sorting with Directed Graphs
Page 649
An Example: Course Prerequisites
Page 649
Directed Graphs
Page 650
Topological Sorting
Page 651
The GraphD Workshop Applet
Page 652
Cycles and Trees
Page 653
Java Code
Page 654
Connectivity in Directed Graphs
Page 661
The Connectivity Table
Page 662
Warshall's Algorithm
Page 662
Implementation of Warshall's Algorithm
Page 664
Summary
Page 665
Questions
Page 665
Experiments
Page 667
Programming Projects
Page 667
14. Weighted Graphs
Page 669
Minimum Spanning Tree with Weighted Graphs
Page 669
An Example: Cable TV in the Jungle
Page 670
The GraphW Workshop Applet
Page 670
Send Out the Surveyors
Page 672
Creating the Algorithm
Page 676
Java Code
Page 678
The mstw.java Program
Page 681
The Shortest-Path Problem
Page 687
The Railroad Line
Page 687
Dijkstra's Algorithm
Page 689
Agents and Train Rides
Page 689
Using the GraphDW Workshop Applet
Page 694
Java Code
Page 698
The path.java Program
Page 703
The All-Pairs Shortest-Path Problem
Page 708
Efficiency
Page 710
Intractable Problems
Page 710
The Knight's Tour
Page 711
The Traveling Salesman Problem
Page 711
Hamiltonian Cycles
Page 712
Summary
Page 713
Questions
Page 713
Experiments
Page 715
Programming Projects
Page 715
15. When to Use What
Page 717
General-Purpose Data Structures
Page 717
Speed and Algorithms
Page 718
Libraries
Page 719
Arrays
Page 720
Linked Lists
Page 720
Binary Search Trees
Page 720
Balanced Trees
Page 721
Hash Tables
Page 721
Comparing the General-Purpose Storage Structures
Page 722
Special-Purpose Data Structures
Page 722
Stack
Page 723
Queue
Page 723
Priority Queue
Page 723
Comparison of Special-Purpose Structures
Page 724
Sorting
Page 724
Graphs
Page 725
External Storage
Page 725
Sequential Storage
Page 726
Indexed Files
Page 726
B-Trees
Page 726
Hashing
Page 727
Virtual Memory
Page 727
Onward
Page 728
Appendixes
A. Running the Workshop Applets and Example Programs
Page 729
The Workshop Applets
Page 729
The Example Programs
Page 730
The Sun Microsystem's Software Development Kit
Page 730
Command-line Programs
Page 731
Setting the Path
Page 731
Viewing the Workshop Applets
Page 731
Operating the Workshop Applets
Page 732
Running the Example Programs
Page 732
Compiling the Example Programs
Page 733
Editing the Source Code
Page 733
Terminating the Example Programs
Page 733
Multiple Class Files
Page 733
Other Development Systems
Page 734
B. Further Reading
Page 735
Data Structures and Algorithms
Page 735
Object-Oriented Programming Languages
Page 736
Object-Oriented Design and Software Engineering
Page 736
C. Answers to Questions
Page 739
Chapter 1, Overview — Answers to Questions
Page 739
Chapter 2, Arrays — Answers to Questions
Page 739
Chapter 3, Simple Sorting — Answers to Questions
Page 740
Chapter 4, Stacks and Queues — Answers to Questions
Page 741
Chapter 5, Linked Lists — Answers to Questions
Page 741
Chapter 6, Recursion — Answers to Questions
Page 742
Chapter 7, Advanced Sorting — Answers to Questions
Page 743
Chapter 8, Binary Trees — Answers to Questions
Page 743
Chapter 9, Red-Black Trees — Answers to Questions
Page 744
Chapter 10, 2-3-4 Trees and External Storage — Answers to Questions
Page 745
Chapter 11, Hash Tables — Answers to Questions
Page 745
Chapter 12, Heaps — Answers to Questions
Page 746
Chapter 13, Graphs — Answers to Questions
Page 746
Chapter 14, Weighted Graphs — Answers to Questions
Page 747

Edition Notes

Includes bibliographical references (p. [735]-737) and index.
Rev. ed. of Sams teach yourself data structures and algorithms in 24 hours, 1999.

Published in
Indianapolis, Ind

Classifications

Dewey Decimal Class
005.7/3
Library of Congress
QA76.9.D35 L355 2003, QA76.9.D35L34 2002

The Physical Object

Pagination
xix, 776 p. :
Number of pages
776

Edition Identifiers

Open Library
OL3573553M
ISBN 10
0672324539
LCCN
2002106907
OCLC/WorldCat
51256595
LibraryThing
1415923
Goodreads
300092

Work Identifiers

Work ID
OL2036110W

Community Reviews (0)

No community reviews have been submitted for this work.

Lists

History

Download catalog record: RDF / JSON / OPDS | Wikipedia citation
September 13, 2025 Edited by Drini Add TOC from Tocky
September 13, 2025 Edited by Drini Add TOC from Tocky
December 8, 2024 Edited by MARC Bot import existing book
December 19, 2023 Edited by ImportBot import existing book
April 1, 2008 Created by an anonymous user Imported from Scriblio MARC record