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

What is a graph?


A graph is a collection of vertices and edges that connect the vertices. Figure 1 gives a visual representation of an example of a graph. There are a few features to note here, which we will discuss next:

Figure 1: Example of an undirected graph

  • Undirected graph: An undirected graph is a graph in which the edges have no direction, as shown in Figure 1.

  • Directed graph: This is a graph in which the edges have a direction.

  • Path: A path is a sequence of edges that connects a set of vertices that are distinct from one another, except the first and the last vertices as they may be the same. For example, in Figure 1, the edges AB, BD, and DE represent a path. It can also be described as the ABDE path, which does not repeat its vertices. In the case of a directed graph, the edges must traverse only in the specified direction to form the sequence of edges required to make a path.

  • Cycle: A cycle is a path with at least two vertices involved; it starts and ends on the same vertex. For...