Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: Jay Wengrow

Rating 4.0 AI initial rating

Algorithms and data structures are much more than abstract concepts. Mastering them enables you to write code that runs faster and more efficiently, which is particularly important for today's web and mobile apps. Take a practical approach to data structures and algorithms, with techniques and real-world scenarios that you can use in your daily production code, with examples in JavaScript, Python, and Ruby. This new and revised second edition features new chapters on recursion, dynamic programming, and using Big O in your daily work. Use Big O notation to measure and articulate the efficiency of your code, and modify your algorithm to make it faster. Find out how your choice of arrays, linked lists, and hash tables can dramatically affect the code you write. Use recursion to solve tricky problems and create algorithms that run exponentially faster than the alternatives. Dig into advanced data structures such as binary trees and graphs to help scale specialized applications such as social networks and mapping software. You even encounter a single keyword that can give your code a turbo boost. Practice your new skills with exercises in every chapter, along with detailed solutions. Use these techniques today to make your code faster and more scalable.

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
【One-Line Pitch】 A patient, example-driven introduction to data structures and algorithms that turns Big O from a scary notation into a practical tool for writing faster code. Best for self-taught and early-career developers who want intuition and working code (in JavaScript, Python, and Ruby) rather than formal proofs. 【Book Arc】 - **Opening (~0%–15%)**: Frames the whole book around a single question — how many steps does an operation take? Introduces arrays and ordered arrays, then shows why the choice of data structure and algorithm changes real runtime costs. - **Early (~15%–30%)**: Builds Big O as a working vocabulary: O(1), O(N), O(log N), and O(N²), with binary search, bubble sort, and insertion sort as concrete cases. Also introduces best/average/worst-case thinking and how to optimize for the optimistic scenario. - **Early–Middle (~30%–40%)**: Applies Big O to everyday code — nested loops that are not quadratic, merging sorted arrays, substring search — before moving into hash tables and their O(1) lookups, collisions, and the "use a hash table as an index" trick. - **Middle (~40%–55%)**: Covers constrained data structures — stacks and queues as abstract data types built on arrays — and argues that limiting how data can be accessed is itself a design virtue. - **Late (~55%–85%)**: Moves into recursion and the advanced structures the blurb promises — binary trees and graphs — for scaling specialized applications. (Excerpts do not cover the exact chapter sequence or percentages in this stretch.) - **Ending (~85%–100%)**: Closes with dynamic programming and practical guidance on using Big O in daily work, plus exercises and solutions throughout. (Excerpts do not cover the closing chapters in detail.) 【Key Takeaways】 - **Speed is measured in steps, not seconds** (Opening): The book defines time complexity as the number of computational steps an operation takes, making performance comparable across hardware. This reframing is the foundation for everything that follows. - **Array operations have very different costs** (Opening): Reading by index is one step, but insertion and deletion require shifting elements — worst case at index 0, roughly N steps. Knowing this explains why arrays are fast for lookup and slow for middle edits. - **Big O defaults to the worst case** (Early): Linear search is O(1) best-case but O(N) worst-case, and the pessimistic reading is the useful one for planning. Best/average/worst-case analysis is presented as a core skill for choosing and optimizing algorithms. - **O(log N) is the "doubling" curve** (Early): Binary search adds one step each time the data doubles, placing it between constant and linear time. This gives readers a mental model for recognizing logarithmic algorithms. - **Nested loops are not automatically O(N²)** (Early): Only when both loops scale with N does quadratic behavior appear; a fixed five-iteration inner loop stays constant. This is a common misreading the book explicitly corrects. - **Hash tables trade order for O(1) lookup** (Middle): Hashing a key jumps directly to its value, but only in the key→value direction; reverse lookups fall back to O(N). Collisions and table sizing are the practical caveats. - **Hash tables can serve as an index** (Middle): Storing each item as a key (with any truthy value) turns repeated O(N) membership checks into O(1) lookups — a reusable trick for real code. - **Constraints are a feature** (Middle): Stacks (LIFO) and queues are abstract data types layered over arrays; restricting access makes intent clear and enables use cases like undo. The book treats this as design guidance, not just trivia. 【Reading Tips】 - **Deep-read the Big O chapters (roughly the first third).** Everything later assumes fluency with O(1)/O(N)/O(log N)/O(N²); skimming here will cost you later. - **Do the exercises, then compare with the solutions.** The book's value is in step-counting practice; reading solutions without attempting the problems yields much less. - **Skim code in languages you don't use.** Examples rotate across JavaScript, Python, and Ruby; the concepts transfer, so don't get stuck on syntax. - **Watch for the "everyday code" chapter.** It is the bridge from theory to production code and is worth a slow pass. - **Treat recursion and dynamic programming as the hard spots.** Budget extra time there; the excerpts do not show how gradually the book builds up to them. 【Coverage Limits】 This guide is based on stratified excerpts covering roughly the first half of the book plus the blurb; the recursion, tree, graph, and dynamic-programming chapters are described only at the level of the back-cover summary, so specifics on those sections are not verified here.
Page 9
he Importance of Constrained Data Structures 143 Queues 144 Queues in Action 146 Wrapping Up 147 Exercises 148 10. Recursively Recurse with Recursion . . . ....
View in text
Excerpt 2
rithm that increases one step each time the data is doubled. As you learned in the previous chapter, binary search does just that. You’ll see momentarily why...
View in text
Excerpt 3
practice with optimizing for best- and worst-case scenarios. The solutions to these exercises are found in the section, Chapter 6, on page 442. 1. Use Big O...
View in text
Excerpt 4
k, then, you generally have to use one of the built-in data structures to actually hold the data. Here is one way to implement a stack using Ruby, which uses...
View in text
Excerpt 5
re going to write a reverse function that reverses a string. So, if the function accepts the argument "abcde", it’ll return "edcba". First, let’s identify th...
View in text
Excerpt 6
that runs while current_index is less than the index we’re attempting to read: while current_index < index do In each pass-through of the loop, we access the...
View in text
Excerpt 7
contain a smaller value than any of its descendants. Such a heap is known as the min-heap, which I mentioned earlier. We’re going to con- tinue to focus on t...
View in text
Excerpt 8
f Fred. We’ve iterated over all his neighbors too, so we’re done searching him as well. The computer pops off Bob, but we’re don
View in text
Tags
AI categories
Programming LanguageEducation
ISBN: 1680507222
Publisher: Pragmatic Bookshelf
Publish Year: 2020
Language: English
Pages: 506
File Format: PDF
File Size: 8.7 MB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…