PDF Learning functional data structures and algorithms learn functional data structures and algorithms for your applications and bring their benefits to your work now Khot download
PDF Learning functional data structures and algorithms learn functional data structures and algorithms for your applications and bring their benefits to your work now Khot download
com
https://textbookfull.com/product/probabilistic-data-structures-and-
algorithms-for-big-data-applications-gakhov/
textbookfull.com
https://textbookfull.com/product/data-structures-and-algorithms-in-
swift-kevin-lau/
textbookfull.com
https://textbookfull.com/product/narratives-of-fear-and-safety-kaisa-
kaukiainen/
textbookfull.com
Logic and Philosophy of Time Further Themes from Prior 1st
Edition Blackburn
https://textbookfull.com/product/logic-and-philosophy-of-time-further-
themes-from-prior-1st-edition-blackburn/
textbookfull.com
https://textbookfull.com/product/muslim-women-and-power-political-and-
civic-engagement-in-west-european-societies-1st-edition-daniele-joly/
textbookfull.com
Maulid Ad Daiba i 4th Edition Ash-Shaykh Al-Wali Al-
Muhaddith Abdur-Rahman Ad-Daiba‘I
https://textbookfull.com/product/maulid-ad-daiba-i-4th-edition-ash-
shaykh-al-wali-al-muhaddith-abdur-rahman-ad-daibai/
textbookfull.com
Learning Functional Data
Structures and Algorithms
Table of Contents
Learning Functional Data Structures and Algorithms
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Why subscribe?
Customer Feedback
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
1. Why Functional Programming?
The imperative way
Higher level of abstraction
Functional programming is declarative
No boilerplate
Higher order functions
Eschewing null checks
Controlling state changes
Recursion aids immutability
Copy-on-write
Laziness and deferred execution
Composing functions
Summary
2. Building Blocks
The Big O notation
Space/time trade-off
A word frequency counter
Matching string subsets
Referential transparency
Vectors versus lists
Updating an element
Not enough nodes
Complexities and collections
The sliding window
Maps
Persistent stacks
Persistent FIFO queues
Sets
Sorted set
Summary
3. Lists
First steps
List head and tail
Drop elements
Concatenating lists
Persistent data structures
Tail call optimization
List append
List prepend
Getting value at index
Modifying a list value
Summary
4. Binary Trees
Node definitions
Building the tree
Size and depth
Complete binary trees
Comparing trees
Flipping a binary tree
Binary tree traversal
The accumulator idiom
Binary Search Trees
Node insertion
Searching a key
Updating a value
Exercising it
Summary
5. More List Algorithms
Binary numbers
Addition
Multiplication
Greedy algorithms and backtracking
An example of a greedy algorithm
The backtracking jig
Summary
6. Graph Algorithms
Reversing a list
Graph algorithms
Graph traversal
Avoiding list appending
Topological sorting
Cycle detection
Printing the cycle
Summary
7. Random Access Lists
Incrementing a binary number
Adding two binary numbers
List of tree roots
Insertion
Lookup
Removal, head, and tail
Update
Summary
8. Queues
Understanding FIFO queues
Functional FIFO queues
Invariants
Implementing a priority queue
Understanding priority queues/heaps
Leftist trees
Functional heaps
Summary
9. Streams, Laziness, and Algorithms
Program evaluation
Eager evaluation
Argument evaluation
Lazy evaluation
Lazy evaluation in Scala
Lazy evaluation in Clojure
Memoization - remembering past results
Memoization in Scala
Memoization in Clojure
Memoizing simpleFactFun
Streams
Stream in Scala
Indexing the elements of a stream
Creation of an infinite length stream
Stream is immutable
Creating a stream from another
Stream to list
Appending one stream to another
Length of a stream
Some mathematical functions of the stream class
Some more methods of the stream class
Streams (lazy sequence) in Clojure
Creating a memoized function of lazy sequences in Clojure
Some algorithms on stream
Arithmetic progression
Arithmetic progression in Scala
Arithmetic progression in Clojure
Standard Brownian motion
Standard Brownian motion in Scala
Standard Brownian motion in Clojure
Fibonacci series
First form of Fibonacci series
Second form of Fibonacci series
Fibonacci series in Scala
Fibonacci series in Clojure
Summary
10. Being Lazy - Queues and Deques
Imperative implementations
Amortization
Problem with queues
Strict versus lazy
Streams
Streams meet queues
A sense of balance
Amortized deques
Summary
11. Red-Black Trees
Terminology
Almost balanced trees
The concept of rotation
Red-Black trees
Inserting a node
The Black-Red-Red path
Left, left - red child and grand child
Left child, right grand child
Right child, right grand child
Right, left
Verifying the transformation
Complexity
Summary
12. Binomial Heaps
Binomial trees
Left child, right sibling
A binomial heap
Linking up
Inserting a value
Binary number equivalence
Merging
Find the minimum
Deleting the minimum
Exercising the code
Complexity
Summary
13. Sorting
Stable and unstable sorting
Stable sorting
Unstable sorting
Bubble sort
Scala implementation of bubble sort
Complexity of bubble sort
Selection sort
Complexity of selection sort
Insertion sort
Complexity of insertion sort
Merge sort
Splitting the sequence
Merging two sorted subsequences
Complexity of merge sort
Quick sort
Partition
Complexity of quick sort
Summary
Learning Functional Data
Structures and Algorithms
Learning Functional Data
Structures and Algorithms
Copyright © 2017 Packt Publishing
Every effort has been made in the preparation of this book to ensure the
accuracy of the information presented. However, the information
contained in this book is sold without warranty, either express or
implied. Neither the authors, nor Packt Publishing, and its dealers and
distributors will be held liable for any damages caused or alleged to be
caused directly or indirectly by this book.
Livery Place
35 Livery Street
ISBN 978-1-78588-873-1
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
www.packtpub.com
Credits
Authors
Copy Editor
Atul S. Khot
Gladson Monteiro
Raju Kumar Mishra
Raju Kumar Mishra is a consultant and corporate trainer for big data
and programming. After completing his B.Tech from Indian Institute of
Technology (ISM) Dhanbad, he worked for Tata Steel. His deep passion
for mathematics, data science, and programming took him to Indian
Institute of Science (IISc). After graduating from IISc in computational
science, he worked for Oracle as a performance engineer and software
developer. He is an Oracle-certified associate for Java 7. He is a
Hortonworks-certified Apache Hadoop Java developer, and holds a
Developer Certification for Apache Spark (O'Reilly School of
Technology and Databriks), and Revolution R Enterprise-certified
Specialist Certifications. Apart from this, he has also cleared Financial
Risk Manager (FRM I) exam. His interest in mathematics helped him in
clearing the CT3 (Actuarial Science) exam.
Did you know that Packt offers eBook versions of every book
published, with PDF and ePub files available? You can upgrade to the
eBook version at www.PacktPub.com and as a print book customer, you
are entitled to a discount on the eBook copy. Get in touch with us
at [email protected] for more details.
https://www.packtpub.com/mapt
Get the most in-demand software skills with Mapt. Mapt gives you full
access to all Packt books and video courses, as well as industry-leading
tools to help you plan your personal development and advance your
career.
Why subscribe?
Fully searchable across every book published by Packt
Copy and paste, print, and bookmark content
On demand and accessible via a web browser
Customer Feedback
Thank you for purchasing this Packt book. We take our commitment to
improving our content and products to meet your needs seriously—that's
why your feedback is so valuable. Whatever your feelings about your
purchase, please consider leaving a review on this book's Amazon page.
Not only will this help us, more importantly it will also help others in the
community to make an informed decision about the resources that they
invest in to learn. You can also review for us on a regular basis by
joining our reviewers' club. If you're interested in joining, or would
like to learn more about the benefits we offer, please contact us:
[email protected].
Preface
This book is about functional algorithms and data structures. Algorithms
and data structures are fundamentals of computer programming.
For example, reversing a singly linked list using three node pointers is a
well known algorithm. We scan the list once and reverse it by changing
the pointer fields of each node. The three pointer variables guide the
reversal process.
I have come across many such pointer tricks and have used them as
needed.
We slept easier, the code worked as expected, and all was well with the
world!
I could very well see why writing side-effect free code worked! I was
hooked and started playing with Scala, Clojure, and Erlang. Immutability
was the norm here.
All in good time though! Reading this book will help you see that we
need not sacrifice algorithmic performance while avoiding in-place
mutation!
You also need a text editor. Use whichever you are comfortable with.
Who this book is for
The book assumes some familiarity with basic data structures. You
should have played with fundamental data structures like linked lists,
heaps, and binary trees. It also assumes that you have written some code
in a functional language.
We try to site links that offer hands-on code snippets, so you can
practice them yourself.
A lot of thought has gone into making helpful diagrams. Quizzes and
exercises are included, so you can apply what you've learned.
All the code is available online. We strongly advocate keying in the code
snippets though, to internalize the principles and techniques.
Code words in text, database table names, folder names, filenames, file
extensions, pathnames, dummy URLs, user input, and Twitter handles
are shown as follows: "The following function f has a side effect,
though."
New terms and important words are shown in bold. Words that you
see on the screen, for example, in menus or dialog boxes, appear in the
text like this: "Clicking the Next button moves you to the next screen."
Note
Warnings or important notes appear in a box like this.
Tip
Tips and tricks appear like this.
Random documents with unrelated
content Scribd suggests to you:
Socialisme et population, par Leon Marinont.—0 fr. 40
c.
Socialisme et malthusisme, par Victor Ernest.—0 fr. 60
c.
Malthus et ses disciples, par G. Hardy.—0 fr. 50 c.
La loi de Malthus, par G. Hardy.—0 fr. 75 c.
Population et subsistances, par G. Giroud.—1 fr.
Aux jeunes hommes, aux jeunes filles. Ce qu’ils
doivent apprendre sur la vie sexuelle, par Valentin
Grandjean.—1 fr.
Valeur scientifique du malthusianisme, par le Dr.
Gottschalk. Deux brochures (1re et 2e parties). Ensemble, 1 fr. 50 c.
VOLUMES.
Moyens d’eviter la grossesse, par G. Hardy.—1 fr. 25 c.
L’education sexuelle, par Jean Marestan.—2 fr. 50 c.
Peu d’enfants. Pourquoi? Comment? par Eugene
Lericolais.—3 fr.
Le breviaire de la femme enceinte.—4 fr.
La pauvrete, sa seule cause, son seule remede, par le Dr.
George Drysdale.—1 fr.
La procreation volontaire, par le Dr. Klotz-Forest.—2 fr.
Elements de science sociale, par le Dr. G. Drysdale.—3
fr.
L’initiation sexuelle, par G. Bessede.—3 fr.
La vie sexuelle et ses lois, par le Dr. Anton Nystrom.—6
fr.
Notions d’hygiene feminine populaire: l’Adolescente,
par le Dr. Rene Martial.—2 fr.
La fonction sexuelle, par le Dr. Sicard de Plauzoles.—6
fr.
La generation humaine, par le Dr. G.-J. Witkowski.—8 fr.
La question sexuelle, par Auguste Forel.—10 fr.
De l’avortement. Est-ce un crime? par le Dr. Klotz-
Forest.—3 fr. 50 c.
De l’amour physique, par Camille Mauclair.—3 fr.
La physique de l’amour, par Remy de Gourmont.—3 fr.
Generation Consciente.
1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside
the United States, check the laws of your country in addition to
the terms of this agreement before downloading, copying,
displaying, performing, distributing or creating derivative works
based on this work or any other Project Gutenberg™ work. The
Foundation makes no representations concerning the copyright
status of any work in any country other than the United States.
1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if
you provide access to or distribute copies of a Project
Gutenberg™ work in a format other than “Plain Vanilla ASCII” or
other format used in the official version posted on the official
Project Gutenberg™ website (www.gutenberg.org), you must,
at no additional cost, fee or expense to the user, provide a copy,
a means of exporting a copy, or a means of obtaining a copy
upon request, of the work in its original “Plain Vanilla ASCII” or
other form. Any alternate format must include the full Project
Gutenberg™ License as specified in paragraph 1.E.1.
• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”
• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.
1.F.
Most people start at our website which has the main PG search
facility: www.gutenberg.org.