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

A tree data structure


A tree data structure looks very much like a real tree, the kind you can see in a garden or by the roadside. If we look at a tree, we will see that it has a root that makes the stem outside of the ground. The stem splits into branches, and at the end of the branches, we find leaves. In our tree data structure, we start from the root. The root is the node that does not have any parent. The children can be thought of as being attached to the stem by lines just like the branches of a real tree. At the end, we find some nodes that have no children and hence are called leaves. The following figure shows an example of a tree:

An example tree

Note that the tree is drawn upside down. The root is at the top and the leaves are below. This is just a convention that most people prefer. Think of this as the reflection of a tree on water.

A tree can be represented in many ways, but we will get started with the idea of generalization of a linked list. In the case of a linked list, a...