Book Image

Sorting and Searching Algorithms in Scala

By : James Cutajar
Book Image

Sorting and Searching Algorithms in Scala

By: James Cutajar

Overview of this book

Scala's functional programming features are a boon when it comes to designing easy-to-reason-about systems to curb growing software complexities. In this course, we will learn about many concepts and tools available in the Scala language by implementing, in a functional manner, some sorting and searching algorithms. Most algorithms are traditionally defined in an imperative manner, typically consisting of repetitions in the form of conditional looping and altering states. Writing these in a functional manner is not always a trivial process. In this course, we will do just that. We will also show how to implement search data structures in a functional and immutable manner. We will look at number sorting, substring searches, hash tables, red black binary trees, and the closest pair algorithm. Along the way, we will talk about bubble sort, merge sort, Knuth-Morris-Pratt string searching, structural sharing in functional data structures, and various problems with immutable data structures. Further, we will explore the classic closest pair algorithm and show how we can solve the problem efficiently in a functional manner. By the end of the course, you will have gained a thorough knowledge of many functional Scala concepts and will understand these algorithms and data structures. All the code and supporting files for this course are available at https://github.com/PacktPublishing/Sorting-and-Searching-Algorithms-in-Scala.
Table of Contents (5 chapters)
Chapter 4
Binary Trees
Content Locked
Section 2
Immutable Binary Trees
Here we show how the traditional mutable binary tree operations can be adapted into an immutable manner. We do this by maximizing structural sharing. - Understand the difficulty of implementing immutable binary trees - Find out how we use structural sharing to improve performance - Follow how we change the insert and search functions