Book Image

Java 9 Data Structures and Algorithms

By : Debasish Ray Chawdhuri
Book Image

Java 9 Data Structures and Algorithms

By: Debasish Ray Chawdhuri

Overview of this book

Java 9 Data Structures and Algorithms covers classical, functional, and reactive data structures, giving you the ability to understand computational complexity, solve problems, and write efficient code. This book is based on the Zero Bug Bounce milestone of Java 9. We start off with the basics of algorithms and data structures, helping you understand the fundamentals and measure complexity. From here, we introduce you to concepts such as arrays, linked lists, as well as abstract data types such as stacks and queues. Next, we’ll take you through the basics of functional programming while making sure you get used to thinking recursively. We provide plenty of examples along the way to help you understand each concept. You will also get a clear picture of reactive programming, binary searches, sorting, search trees, undirected graphs, and a whole lot more!
Table of Contents (19 chapters)
Java 9 Data Structures and Algorithms
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface
Index

The graph ADT


We will now define what a data structure representing a graph should do. Later, we will discuss the different implementations of this ADT. A graph must support the following operations:

  • Add Vertex: This adds a new vertex

  • Remove Vertex: This removes a vertex

  • Add edge: This adds a new edge; in our graph, we will allow a maximum of one edge between two vertices for simplicity

  • Remove edge: This removes an edge

  • Adjacent: This checks whether the two given vertices are adjacent to each other, that is, whether there is an edge between the given nodes

  • Neighbors: This returns a list of vertices that are adjacent to the given vertex

  • Get Vertex Value: This gets the value stored in a vertex

  • Set Vertex Value: This stores a value in a vertex

  • Get Edge Value: This gets the value stored in an edge

  • Set Edge Value: This sets the value stored in an edge

  • Is undirected: This returns whether the graph is undirected

  • Get all vertices: This returns a self-balancing binary search tree containing all the...