Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learning Functional Data Structures and Algorithms

You're reading from   Learning Functional Data Structures and Algorithms Learn functional data structures and algorithms for your applications and bring their benefits to your work now

Arrow left icon
Product type Paperback
Published in Feb 2017
Publisher Packt
ISBN-13 9781785888731
Length 318 pages
Edition 1st Edition
Languages
Arrow right icon
Authors (2):
Arrow left icon
Raju Kumar Mishra Raju Kumar Mishra
Author Profile Icon Raju Kumar Mishra
Raju Kumar Mishra
Atul S. Khot Atul S. Khot
Author Profile Icon Atul S. Khot
Atul S. Khot
Arrow right icon
View More author details
Toc

Table of Contents (14) Chapters Close

Preface 1. Why Functional Programming? 2. Building Blocks FREE CHAPTER 3. Lists 4. Binary Trees 5. More List Algorithms 6. Graph Algorithms 7. Random Access Lists 8. Queues 9. Streams, Laziness, and Algorithms 10. Being Lazy - Queues and Deques 11. Red-Black Trees 12. Binomial Heaps 13. Sorting

Binary Search Trees


A Binary Search Tree (BST) is a binary tree with the following additional property. The value at the root node is greater (or equal) than all the values in the left subtree. Likewise, the value is lesser than (or equal) all the values in the right subtree.

We keep things simple and don't consider the multiple equal values case. Rather, we implement dictionaries using binary trees.

A dictionary is a list of (key, value) pairs. A key can occur only once, that is, the key is unique. For example, we could use dictionaries to compute the count of words in a given text input.

The word count algorithm is simple:

words[] = split a string on space characters. 
for each word, search the dictionary if it is already present. 
if not in dictionary, insert (word, 1) 
if found in dictionary, take associated count, cnt 
update (word, cnt+1) 

The following figure shows an abstract dictionary on the left-hand side. The right-hand side of the diagram shows how we could realize it using a BST...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime