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

Binary search tree


You already know what binary search is. Let's go back to the sorted array from an earlier chapter and study it again. If you think about binary search, you know you need to start from the middle of the sorted array. Depending on the value to be searched, either we return if the middle element is the search item, or move to the left or right based on whether the search value is greater than or less than the middle value. After this, we continue the same process recursively. This means the landing points in each step are quite fixed; they are the middle values. We can draw all the search paths as in the next figure. In each step, the arrows connect to the mid points of both the right half and left half, considering the current position. In the bottom part, we disassemble the array and spread out the elements while keeping the sources and targets of the arrows similar. As one can see, this gives us a binary tree. Since each edge in this tree moves from the midpoint of one...