Instant ebooks textbook Absolute Beginner’s Guide to Algorithms: A Practical Introduction to Data Structures and Algorithms in JavaScript (for True Epub) Kirupa Chinnathambi download all chapters
Instant ebooks textbook Absolute Beginner’s Guide to Algorithms: A Practical Introduction to Data Structures and Algorithms in JavaScript (for True Epub) Kirupa Chinnathambi download all chapters
com
OR CLICK HERE
DOWLOAD NOW
https://ebookmass.com/product/data-structures-and-algorithms-in-c-2nd-
edition/
ebookmass.com
https://ebookmass.com/product/introduction-to-algorithms-for-data-
mining-and-machine-learning-yang/
ebookmass.com
https://ebookmass.com/product/the-art-of-avoiding-your-werewolf-
wildwood-book-1-lola-glass/
ebookmass.com
Mcgraw-hill education 5 teas practice tests, Fourth
Edition Kathy Zahler
https://ebookmass.com/product/mcgraw-hill-education-5-teas-practice-
tests-fourth-edition-kathy-zahler/
ebookmass.com
https://ebookmass.com/product/laughter-and-power-in-the-twelfth-
century-peter-j-a-jones/
ebookmass.com
https://ebookmass.com/product/life-on-our-planet-tom-fletcher/
ebookmass.com
https://ebookmass.com/product/the-surgeon-karl-hill/
ebookmass.com
https://ebookmass.com/product/robert-mugabe-and-the-will-to-power-in-
an-african-postcolony-1st-edition-william-j-mpofu/
ebookmass.com
Core Curriculum for Transplant Nurses 2nd Edition, (Ebook
PDF)
https://ebookmass.com/product/core-curriculum-for-transplant-
nurses-2nd-edition-ebook-pdf/
ebookmass.com
About This eBook
Kirupa Chinnathambi
Absolute Beginner’s Guide to Algorithms
The author and publisher have taken care in the preparation of this
book, but make no expressed or implied warranty of any kind and
assume no responsibility for errors or omissions. No liability is
assumed for incidental or consequential damages in connection with
or arising out of the use of the information or programs contained
herein.
Hoboken, NJ
ISBN-13: 978-0-13-822229-1
ISBN-10: 0-13-822229-0
$PrintCode
Pearson’s Commitment to Diversity, Equity,
and Inclusion
I Data Structures
1 Introduction to Data Structures
Right Tool for the Right Job
Back to Data Structures
Conclusion
Some Additional Resources
2 Big-O Notation and Complexity Analysis
It’s Example Time
It’s Big-O Notation Time!
Conclusion
Some Additional Resources
3 Arrays
What Is an Array?
Adding an Item
Deleting an Item
Searching for an Item
Accessing an Item
Array Implementation / Use Cases
Arrays and Memory
Performance Considerations
Access
Insertion
Deletion
Searching
Conclusion
Some Additional Resources
4 Linked Lists
Meet the Linked List
Finding a Value
Adding Nodes
Deleting a Node
Linked List: Time and Space Complexity
Deeper Look at the Running Time
Space Complexity
Linked List Variations
Singly Linked List
Doubly Linked List
Circular Linked List
Skip List
Implementation
Conclusion
Some Additional Resources
5 Stacks
Meet the Stack
A JavaScript Implementation
Stacks: Time and Space Complexity
Runtime Performance
Memory Performance
Conclusion
Some Additional Resources
6 Queues
Meet the Queue
A JavaScript Implementation
Queues: Time and Space Complexity
Runtime Performance
Memory Performance
Conclusion
Some Additional Resources
7 Trees
Trees 101
Height and Depth
Conclusion
Some Additional Resources
8 Binary Trees
Meet the Binary Tree
Rules Explained
Binary Tree Variants
What about Adding, Removing, and Finding
Nodes?
A Simple Binary Tree Implementation
Conclusion
Some Additional Resources
9 Binary Search Trees
It’s Just a Data Structure
Adding Nodes
Removing Nodes
Implementing a Binary Search Tree
Performance and Memory Characteristics
Conclusion
Some Additional Resources
10 Heaps
Meet the Heap
Common Heap Operations
Heap Implementation
Heaps as Arrays
The Code
Performance Characteristics
Removing the Root Node
Inserting an Item
Performance Summary
Conclusion
Some Additional Resources
11 Hashtable (aka Hashmap or Dictionary)
A Very Efficient Robot
From Robots to Hashing Functions
From Hashing Functions to Hashtables
Adding Items to Our Hashtable
Reading Items from Our Hashtable
JavaScript Implementation/Usage
Dealing with Collisions
Performance and Memory
Conclusion
Some Additional Resources
12 Trie (aka Prefix Tree)
What Is a Trie?
Inserting Words
Finding Items
Deleting Items
Diving Deeper into Tries
Many More Examples Abound!
Implementation Time
Performance
Conclusion
Some Additional Resources
13 Graphs
What Is a Graph?
Graph Implementation
Representing Nodes
The Code
Conclusion
Some Additional Resources
II Algorithms
14 Introduction to Recursion
Our Giant Cookie Problem
Recursion in Programming
Recursive Function Call
Terminating Condition
Conclusion
Some Additional Resources
15 Fibonacci and Going Beyond Recursion
Recursively Solving the Fibonacci Sequence
Recursion with Memoization
Taking an Iteration-Based Approach
Going Deeper on the Speed
Conclusion
Some Additional Resources
16 Towers of Hanoi
How Towers of Hanoi Is Played
The Single Disk Case
It’s Two Disk Time
Three Disks
The Algorithm
The Code Solution
Check Out the Recursiveness!
It’s Math Time
Conclusion
Some Additional Resources
17 Search Algorithms and Linear Search
Linear Search
Linear Search at Work
JavaScript Implementation
Runtime Characteristics
Conclusion
Some Additional Resources
18 Faster Searching with Binary Search
Binary Search in Action
Sorted Items Only, Please
Dealing with the Middle Element
Dividing FTW!
The JavaScript Implementation
Iterative Approach
Recursive Approach
Example of the Code at Work
Runtime Performance
Conclusion
Some Additional Resources
19 Binary Tree Traversal
Breadth-First Traversal
Depth-First Traversal
Implementing Our Traversal Approaches
Node Exploration in the Breadth-First Approach
Node Exploration in the Depth-First Approach
Looking at the Code
Performance of Our Traversal Approaches
Conclusion
Some Additional Resources
20 Depth-First Search (DFS) and Breadth-First Search
(BFS)
A Tale of Two Exploration Approaches
Depth-First Search Overview
Breadth-First Search Overview
Yes, They Are Different!
It’s Example Time
Exploring with DFS
Exploring with BFS
When to Use DFS? When to Use BFS?
A JavaScript Implementation
Using the Code
Implementation Detail
Performance Details
Conclusion
Some Additional Resources
21 Quicksort
A Look at How Quicksort Works
A Simple Look
Another Simple Look
It’s Implementation Time
Performance Characteristics
Time Complexity
Space Complexity
Stability
Conclusion
Some Additional Resources
22 Bubblesort
How Bubblesort Works
Walkthrough
The Code
Conclusion
Some Additional Resources
23 Insertion Sort
How Insertion Sort Works
One More Example
Algorithm Overview and Implementation
Performance Analysis
Conclusion
Some Additional Resources
24 Selection Sort
Selection Sort Walkthrough
Algorithm Deep Dive
The JavaScript Implementation
Conclusion
Some Additional Resources
25 Mergesort
How Mergesort Works
Mergesort: The Algorithm Details
Looking at the Code
Conclusion
Some Additional Resources
26 Conclusion
Index
Acknowledgments
As I found out, getting a book like this out the door is no small feat.
It involves a bunch of people in front of (and behind) the camera
who work tirelessly to turn my ramblings into the beautiful pages
that you are about to see. To everyone at Pearson who made this
possible, thank you!
With that said, there are a few people I’d like to explicitly call out.
First, I’d like to thank Kim Spenceley for making this book possible,
Chris Zahn for meticulously ensuring everything is human-readable,
Carol Lallier for her excellent copyediting, and Loretta Yates for
helping make the connections that made all of this happen years
ago. The technical content of this book has been reviewed in great
detail by my long-time collaborators Cheng Lou and Ashwin Raghav.
To my wife, Meena!
Twitter / X: twitter.com/_chenglou
Twitter / X: twitter.com/ashwinraghav
Part I
Data Structures
1
Onward!
What we want to do is store these tools for easy access later. One
solution is to simply throw all of the tools in a giant cardboard box
and call it a day (Figure 1-2).
FIGURE 1-2
A rummager!
FIGURE 1-4
A toolbox is like the Marie Kondo of the DIY world, with its neat
compartments and organized bliss. Sure, it might take a smidge
more effort to stow things away initially, but that’s the price we pay
for future tool-hunting convenience. No more digging through the
toolbox like a raccoon on a midnight snack raid.
We have just seen two ways to solve our problem of storing our
tools. If we had to summarize both approaches, it would look as
follows:
What we can see is that both our cardboard box and toolbox are
good for some situations and bad for other situations. There is no
universally right answer. If all we care about is storing our tools and
never really looking at them again, stashing them in a cardboard box
is the right choice. If we will be frequently accessing our tools,
storing them in the toolbox is more appropriate.
Conclusion
Over the next many chapters, we’ll learn more about what each data
structure is good at and, more important, what types of operations
each is not very good at. By the end of it, you and I will have
created a mental map connecting the right data structure to the
right programming situation we are trying to address.
When analyzing the things our code does, we are interested in two
things: time complexity and space complexity. Time complexity
refers to how much time our code takes to run, and space
complexity refers to how much additional memory our code requires.
Any code you will ever write will have a specific set of inputs that
yields particular outputs. In an ideal world, we’d want your code to
run as fast as possible and take up as little memory as possible in
doing so.
However, the real world has its quirks, and your code might decide
to take a leisurely stroll instead, depending on the size and
characteristics of its input. While you can always glance at your wall
clock to clock its performance for a specific input set, what we truly
need is way to speak about how it performs with any set of inputs.
And that’s where the Big-O notation strides onto the stage.
Onward!
It’s Example Time
FIGURE 2-1
FIGURE 2-3
The larger the number we provide as the input, the more digits we
have to count through to get the final answer. The important detail
is that the number of steps in our calculation won’t grow abnormally
large (or small) with each additional digit in our number. We can
visualize this by plotting the size of our input versus the number of
steps required to get the count (Figure 2-4).
FIGURE 2-4
Let’s say that we have some additional code that lets us know
whether our input number is odd or even. The way we would
calculate the oddness or evenness of a number is by just looking at
the last digit and doing a quick calculation (Figure 2-5).
Discovering Diverse Content Through
Random Scribd Documents
Yksin voi ihminen kärsiä mitä hyvänsä, mutta kun tietää, että on
olemassa muita, jotka kärsivät saman asian takia, niin tulee oma
tuska moninkertaiseksi…
— No, sen taulun, jossa minä olin mallina ja joka ei vielä tullut
aivan valmiiksi, sen juoksijan…
Martta Hagen oli taaskin ollut tuomari Katajiston luona. Heillä oli
ollut ensin suuren onnen hetkiä, jotka kuitenkin olivat päättyneet
suureen riitaan, kuten tavallisesti. Martta oli taaskin vaatinut liiaksi
rahoja. Tuomari oli ponnistellut vastaan minkä oli voinut, mutta
vihdoin oli Martta, ovelasti kyllä, pukenut päällysvaatteet ylleen,
tekeytynyt ystävälliseksi ja vihdoin sopivalla hetkellä siepannut
hänen lompakkonsa tuolinselustalla riippuvan takin taskusta. Sitten
hän oli livahtanut ulos ja hävinnyt ensimäisellä autolla.
Joka voittaa aikaa, voittaa kaiken. Mutta kylläpä hän nyt oli
hermostunut, hänhän vaikutti suorastaan lapselliselta. Hermostua
nyt yhdestä ainoasta vekselilomakkeesta, niinkuin se olisi ollut ainoa,
niinkuin hän ei vielä olisi -ehtinyt huomiseen mennessä saada jotain
toista nimeä…
Aivan sattumalta oli Janne Pöyhtäri tavannut tohtori Hakalan, joka oli
tuntenut hänet ja pysähdyttänyt sekä kysellyt, miksikä hän ei enää
käynyt iltakursseilla. Silloin Janne oli kertonut koko tarinansa, joka oli
tehnyt syvän vaikutuksen tohtori Hakalaan. Hän oli tullut aivan
hämillensä.
*****
Onni seurasi Jannea hänen pyrinnöissään. Hän oli sekä ahkera että
rohkea, ja kauppa kävi hyvin. Vähän ajan kuluttua hän oli maksanut
velkansa tohtori Hakalalle, joka iloitsi hänen menestyksestään.
Myöskin hän edistyi opinnoissaan tohtori Hakalan opastuksella. Hän
oppi kirjanpitoa ja kansantalouden perusteita sekä luki
joutoaikoinansa mielellänsä historiaa, johon hänellä oli erikoista
harrastusta.
Tämä aika oli merkillinen siitä, että monet, jotka eivät koskaan
olleet ajatelleetkaan mitään kaupantekoa, keksivät jonkun
kauppatavaran, jolla rikastuivat. Kaikki kelpasi, kaikella voitti, kun
vain osasi ja viitsi. Oikea liikemaailma keinotteli kaikenlaisilla
osakkeilla vallan hurjasti, voittaen suunnattomia summia. Varsinkin
teollisuuslaitosten osakkeet olivat haluttua tavaraa. Mutta vähemmän
taitavat ja köyhät möivät ja ostivat mitä vain eteen sattui.
Jannen salainen toive, tulla kerran siihen asemaan, että voisi ostaa
kotitilastaan edes pienen osan takaisin, oli hiljaa toteutumassa.
Vanha äiti ikäänkuin nuortui, ja Hannan onni ja riemu oli rajaton…
Tulevaisuus hymyili Jannelle hohtavaa hymyään… Elämä ei enää ollut
hourailua eikä sairaan unta, se oli riemukasta todellisuutta…
XVII
Tosin häntä oli kauhistuttanut, kun hän ensi kerran itse huomasi,
että jalkansa todella olivat jo niin laihat, että hän ei voinut enää
esiintyä avojalkatanssijattarena. Niissä oli näkynyt kuoleman käden
kosketus, ja niitä ei voinut auttaa ihomaalilla, niinkuin hän auttoi
laihtuneita kasvojansa. Mutta sitten hän oli vähitellen rauhoittunut ja
järjestänyt niin, että esiintyi aina tanssiessaan jonkinlaisissa
pitkäliepeisissä puvuissa. Olihan itse asiassa naurettavaa, että
puvulla piti peittää jalat, jotka olivat tanssin orgaanit, mutta kuka
siihen kiinnitti huomiotaan. Pääasia oli, että hän tanssi ja tanssi
hyvin…
Hän oli todella tuntenut itsensä huonoksi. Rintaa ahdisti niin, että
toisinaan oli vaikeata hengittää, ja lääkärit eivät antaneet hänelle
paljon toivoa. Ne määräsivät hänelle lepoa ja vuoteella-makuuta
sekä oikeata kunnollista hoitoa jossain sanatoriossa. Mutta kuinka
hän olisi voinut maata? Silloin varmaankin kuolema olisi tullut heti
paikalla hänet hakemaan. Juuri se seikka, että hän aina oli
liikkeessä, työssä, touhussa ja ilossa eikä hetkeksikään antanut
sisäisen elämänhalunsa lamaantua tai uinahtaa, piti häntä hengissä.
Ihmiset ihmettelivät hänen voimiansa, ja hän itsekin ihmetteli niitä.
Hänen tuli paha olla, kun hänen ajatuksensa alkoivat kulkea niitä
latuja, joita hänen elämänsä sitten oli kulkenut. Hän nousi, etsi
kaapista madeirapullon ja joi heti kaksi suurta pikarillista. Se hiukan
lämmitti ja rauhoitti. Sitten hän otti vielä pari lasia ja sytytti
paperossin sekä päätti olla ajattelematta mitään. Mutta kuolema
varmaankin oli tänä iltana hänen seurassaan huoneessa, koska hän
taas palasi muistelemaan elämänsä kulkua, tuota tummaa,
monipolvekkeista polkua.
Hyvä Jumala niitä kauheita aikoja, niitä hurjia öitä ja niitä hämäriä,
inhoittavia aamuja, kun hän vihdoin heräsi uuden päivän valoon.
Kuinka usein hän olikaan kutsunut kuolemaa avukseen pelastamaan
häntä tästä alennuksen tilasta, tästä häpeän lietteestä ja tuskan
aallokosta. Mutta kuolema ei tule silloin kun sitä kutsutaan, se tulee
kutsumatta…
Huoneessa oli niin hiljaista, että hiljaisuus ihan soi. Martta terästi
kuuloaan. Se vain soi ja soi. Hiljaisuus puheli kukille hänen
akkunallaan, ja kukat vastasivat ääneti… Hän kuunteli uteliaana,
koputtiko joku hiljaa hänen ruutuunsa. Kukaan ei koputtanut.
Yksin… yksin…
Äkkiä valahti hänen mielensä niin herkäksi. Hugo Hertellin kuva
tuli mieleen, ja kaunis muisto kiipesi hiljaa hänen syliinsä…
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookmass.com