Book Image

Hands-On Data Structures and Algorithms with Kotlin

By : Chandra Sekhar Nayak, Rivu Chakraborty
Book Image

Hands-On Data Structures and Algorithms with Kotlin

By: Chandra Sekhar Nayak, Rivu Chakraborty

Overview of this book

Data structures and algorithms are more than just theoretical concepts. They help you become familiar with computational methods for solving problems and writing logical code. Equipped with this knowledge, you can write efficient programs that run faster and use less memory. Hands-On Data Structures and Algorithms with Kotlin book starts with the basics of algorithms and data structures, helping you get to grips with the fundamentals and measure complexity. You'll then move on to exploring the basics of functional programming while getting used to thinking recursively. Packed with plenty of examples along the way, this book will help you grasp each concept easily. In addition to this, you'll get a clear understanding of how the data structures in Kotlin's collection framework work internally. By the end of this book, you will be able to apply the theory of data structures and algorithms to work out real-world problems.
Table of Contents (16 chapters)
Free Chapter
Section 1: Getting Started with Data Structures
Section 2: Efficient Grouping of Data with Various Data Structures
Section 3: Algorithms and Efficiency
Section 4: Modern and Advanced Data Structures

Jump search

Jump search is a slightly modified version of linear search. Instead of searching each index, we jump a few indexes by a fixed number of steps. There is no rule on how many steps we should skip in every iteration.

Let's consider an example to understand this better. Imagine that we've a large array of [1, 5, 7, 12, 18, 25, 37, 49, 62, 73, 89, 103, ........] and we want to search for a number (62 here). We'll perform the following steps:

  1. Check if the value at index 0 (1 here) is equal to x (62 here).
  2. If yes, the search is complete.
  3. If no, jump to index 5 (25 here) and check whether the value is equal to x (62). We skipped 5 indexes here.
  4. There might be many cases where the number might not be present in the array or list. In those cases, we need to stop the search operation as soon as possible. So repeat step 3 until we find a number equal to or greater...