Start free trial
Trending New Genres Authors
EnglishEnglish
EspañolSpanish
简体中文Chinese
繁體中文Chinese (Traditional)
FrançaisFrench
DeutschGerman
日本語Japanese
PortuguêsPortuguese
ItalianoItalian
한국어Korean
РусскийRussian
NederlandsDutch
العربيةArabic
PolskiPolish
हिन्दीHindi
Tiếng ViệtVietnamese
SvenskaSwedish
ΕλληνικάGreek
TürkçeTurkish
ไทยThai
ČeštinaCzech
RomânăRomanian
MagyarHungarian
УкраїнськаUkrainian
IndonesiaIndonesian
DanskDanish
SuomiFinnish
БългарскиBulgarian
עבריתHebrew
NorskNorwegian
HrvatskiCroatian
CatalàCatalan
SlovenčinaSlovak
LietuviųLithuanian
SlovenščinaSlovenian
СрпскиSerbian
EestiEstonian
LatviešuLatvian
فارسیPersian
മലയാളംMalayalam
தமிழ்Tamil
اردوUrdu
Searching...
SoBrief
A Common-Sense Guide to Data Structures and Algorithms

A Common-Sense Guide to Data Structures and Algorithms

Level Up Your Core Programming Skills
Make better programming choices by matching each problem to the structure and algorithm that fits.
by Jay Wengrow 2017 222 pages
4.39
500+ ratings
Listen
Immersive
V2.3
Amazon Kindle Audible
Try Full Access for 3 Days
Unlock listening & more!
Continue

Key Takeaways

Choose data structures by the operations your program repeats most.

Start with operations. A data structure organizes data, and its layout changes the work needed to read, search, insert, or delete. In a contiguous array, reading a known index takes O(1), while searching an unsorted array can require scanning N items. Inserting at the front can shift N values. An array-based set adds a no-duplicates rule, so insertion must search before adding. The same data can therefore behave very differently depending on its container.

Match the workload. If duplicate prevention matters, the set earns its extra check. If frequent front insertions dominate, that choice may be costly. The useful question is not which structure looks simplest, but which operations the application performs most and how much data it must handle.

Analysis

The practical strength of this approach is that it treats data representation as an engineering decision, not a matter of style. A useful extension is to consider the whole workload: a structure that makes one operation cheap may make another expensive, and the balance can change as usage grows. The book's operation-by-operation lens helps expose those trade-offs before code becomes difficult to change. Its caution is equally important: a theoretically attractive structure is only a good choice when its costs match the actual application.

Big O tracks how work grows, not the seconds on one machine.

Measure growth. Big O notation describes how an algorithm's number of steps changes as its input grows. It is not a stopwatch reading, which can vary with hardware. For N items, scanning a list is O(N); reading a known array index is O(1); repeatedly halving a search range is O(log N). Nested loops often produce O(N2), while repeatedly doubling the work can produce exponential growth such as O(2N).

Compare categories. Big O drops constant factors and lower-order terms, so O(N) describes both N and 100N steps. That makes it useful for recognizing long-run growth, but it does not distinguish two algorithms that share a category. The usual analysis emphasizes the worst case, while best and average cases can still guide a choice.

Analysis

Big O gives programmers a shared language for discussing scale without pretending that every machine behaves identically. Its abstraction is also a deliberate loss of detail: constants, memory behavior, and small-input performance disappear from the notation. That is a feature when comparing sharply different growth rates, but a limitation when choosing between implementations with the same asymptotic cost. The sound practice is to use Big O to frame expectations, then measure the real program under representative conditions.

Keep data ordered only when faster searches repay slower updates.

Order has a price. An ordered array enables binary search, which repeatedly halves the remaining candidates and takes O(log N) steps. But inserting into the right position can require shifting values, making insertion O(N). A regular array has cheaper insertion at the end, but searching it may take O(N). The best choice depends on whether the program searches or changes the data more often.

Sorting is not one speed. Bubble Sort and Selection Sort take O(N2) steps. Insertion Sort also has a quadratic worst case, but can be much faster on data that is already mostly ordered. Quicksort is typically O(N log N), though its worst case is O(N2). Quickselect can find a ranked value without sorting everything, averaging O(N) time.

Analysis

This is a broader lesson about paying costs at the moment they are incurred. Maintaining order makes queries cheaper by shifting effort into updates; sorting on demand makes the reverse trade. The input's condition matters too: Insertion Sort benefits from nearly ordered data, while Quicksort's performance depends on how partitions divide the values. A careful design asks not simply which algorithm is fastest in the abstract, but how often each operation occurs and what the input tends to look like.

Turn repeated searches into hash-table lookups when memory allows.

Build an index. A hash table pairs keys with values. A hash function converts a key into a location, allowing an average lookup or insertion in O(1) time. Hash tables are useful for naturally paired information, such as menu items and prices, but they can also act as an index: store each item as a key and use a lookup to test whether it exists.

Pay attention to collisions. Different keys can map to the same location. One common solution, separate chaining, stores colliding entries together and searches that small collection. Too many collisions can make lookup as slow as O(N). Hash tables trade memory for speed; converting an array-based subset check from O(N M) to O(N) requires extra storage for an index.

Analysis

An index changes the shape of a problem: instead of repeatedly searching the original collection, the program prepares a representation designed for fast questions. This is a powerful general strategy, but it moves work rather than making it vanish. Building the table consumes time and memory, and its performance depends on how well entries are distributed. The method is most persuasive when many lookups reuse the same data, not when a single query would make the setup more expensive than the search.

Use stacks and queues when processing order is part of the rule.

Make the rule explicit. A stack is an abstract data type, meaning a set of rules for using an underlying structure. It allows adding and removing items only at the top, so the last item added is the first removed. A queue also restricts access, but removes items from the front, so the earliest item added is handled first.

Let order shape the algorithm. A code linter can push opening brackets onto a stack, then check each closing bracket against the most recent opening one. A printer manager can place jobs in a queue so documents are handled in arrival order. These structures are useful for temporary data: after an item is processed, it can be removed rather than kept as permanent history.

Analysis

Restricted interfaces can make a program easier to reason about because they encode a protocol in the data structure itself. The linter's bracket checks depend on the most recent unmatched opening mark, while a printer queue preserves arrival order. This is more than a convenience: the structure communicates the intended behavior to the next programmer. The limitation is also real. FIFO is fair only when arrival order is the right priority, and LIFO is appropriate only when the newest pending item truly deserves attention first.

Use linked lists when edits matter more than jumping to an index.

Follow the links. A linked list stores values in nodes, each of which points to the next node. Unlike an array, its nodes need not occupy adjacent memory locations. To reach an item, the computer starts at the head and follows links, so reading or searching can take O(N) steps.

Edit without shifting. Inserting or deleting at the head takes O(1), and changing a link to add or remove a node takes one step once the relevant node is already available. Arrays, by contrast, may need to shift many values. This makes linked lists useful when an algorithm walks through a list while removing items. A doubly linked list also points backward and tracks both ends, making it useful for queues.

Analysis

The linked list's advantage is conditional, which is exactly why it is worth understanding. It avoids moving neighboring values, but it does not provide fast access to an arbitrary position. If an algorithm must first walk across the list to find the edit point, that traversal may dominate the cost. The strongest case is when the program already has a useful node in hand or is traversing sequentially while making changes. The structure rewards local edits, not random access.

Use recursion for nested problems, then control repeated subproblems.

Reduce the problem. Recursion occurs when a function calls itself. It fits problems with nested structure, such as exploring directories, or calculations that can be expressed through a smaller version of the same problem. Every recursive function needs a base case that stops the calls. Each active call also occupies space on the call stack, so recursion can run out of memory even when its logic is correct.

Avoid recomputing. In the Fibonacci example, a direct recursive solution recalculates the same values many times, producing O(2N) work. Memoization stores completed results so repeated subproblems can reuse them, bringing the work to O(N). A bottom-up loop can also avoid repeated calls. Recursion can clarify the logic, but clarity does not guarantee efficiency.

Analysis

Recursion offers a way to describe a complex task through a smaller instance of itself, often making the structure of the solution visible. The cost is that the computer must preserve unfinished calls, and naive recursion can repeat substantial work. Memoization addresses repetition; iteration can avoid call-stack growth altogether. These are not competing doctrines. The right decision depends on whether recursion makes the problem clearer and whether the resulting memory and runtime costs fit the task.

Choose trees by their invariant: sorted navigation or fast priorities.

Preserve the right property. A binary search tree keeps smaller values among a node's left descendants and larger values among its right descendants. When the tree is balanced, search, insertion, and deletion take about O(log N). If values arrive in sorted order and the tree becomes a chain, those operations can degrade to O(N). A tree's shape matters as much as its definition.

Prioritize instead. A heap requires each parent to outrank its descendants and keeps the tree complete. In a max-heap, the root is always the largest value, making it useful for a priority queue. Insertion and deletion take O(log N), but searching for an arbitrary value is not efficient. The heap's weaker ordering is what makes its priority operations practical.

Analysis

These tree structures demonstrate that an invariant is a promise about what will remain easy. A search tree promises directional navigation; a heap promises quick access to the highest-priority item. Neither is universally superior, and confusing their purposes leads to the wrong performance expectations. Balance is especially important for search trees: an operation's advertised logarithmic behavior depends on the tree not collapsing into a long chain. The choice should begin with the question the application must answer most often.

Use tries when prefixes matter more than whole-word lookup.

Follow characters. A trie stores text as a path of character nodes. Each node can branch to many children, and a marker at a path's end identifies a complete word. Searching for a prefix such as 'cat' follows one character at a time; the work depends on the prefix length K, so it is O(K), rather than on the total number of dictionary entries.

Build suggestions from paths. If the trie contains 'cat', 'catnap', and 'catnip', searching for 'catn' reaches the shared prefix, then the remaining branches provide possible completions. The same structure can hold word popularity scores at terminal markers, letting an application rank suggestions. A trie specializes in prefix questions, not arbitrary searches that ignore how words begin.

Analysis

The trie is an example of organizing information around the shape of the questions asked about it. Autocomplete repeatedly asks which words share a beginning, so shared character paths make that query natural. The benefit is not that all text operations become instant, but that the cost is tied to the input prefix rather than the dictionary's total size. This specialization is valuable when prefix queries are central; a general-purpose lookup structure may be simpler when they are not.

Search graphs according to whether proximity or shortest route matters.

Model relationships. A graph represents items as vertices and their connections as edges. It can describe friendships, routes, or other relationships. Breadth-first search explores nearby vertices before moving farther away, while depth-first search follows one branch deeply before backtracking. Both can traverse a graph in O(V + E), where V is the number of vertices and E the number of edges.

Choose by the question. Breadth-first search is useful for finding the fewest-edge path in an unweighted graph. For a weighted graph, where edges carry costs such as flight prices, Dijkstra's algorithm tracks the cheapest known routes and the preceding stopover needed to reconstruct a path. The graph structure exposes relationships that a flat list would require repeated scanning to discover.

Analysis

Graph search makes the meaning of a connection operational: it can reveal reachability, nearby contacts, or a route through many intermediate points. Breadth-first and depth-first search differ not in what a graph is, but in the order they explore it. Weighted routes demand another distinction, since the fewest edges need not mean the lowest cost. The key design move is to state what 'best' means before selecting the search strategy.

Optimize from a measured baseline, then weigh speed against memory.

Name the target. First determine the current algorithm's Big O, then imagine the fastest plausible cost for the task. If the two differ, look for a better approach. The book's techniques include using a hash table to make repeated lookups direct, changing data structures, and testing a greedy choice that selects the best available option at each step. Generating examples can reveal patterns that simplify a problem, as in the coin game and stock-price exercises.

Count space too. A faster algorithm may allocate a new array, hash table, or large recursive call stack. Space complexity measures this additional memory. An in-place array change can save space, while memoization or indexing may spend space to save time. Big O points toward promising changes; benchmarking checks whether the actual implementation improved.

Analysis

Optimization is most disciplined when it begins with a diagnosis instead of a hunch. A target keeps effort focused, while examples and alternative representations can reveal structure hidden by the first implementation. Yet asymptotic improvement is not the whole decision: memory limits, input patterns, and actual runtime can alter what is best in practice. The book's insistence on benchmarking is an important final check. A clever explanation is a hypothesis about performance, not a substitute for measurement.

Analysis

The book's central achievement is pedagogical: it turns data structures and algorithms from a collection of intimidating names into a sequence of practical questions. What operation is the program doing? How many times must it do that work? Which representation would make that work cheaper? The progression from array operations to Big O, then to specialized structures, gives readers a reusable method rather than a catalog to memorize.

Its strongest conceptual move is treating efficiency as growth in work, not elapsed time. That framing makes comparisons portable across machines and makes hidden costs in nested loops visible. It also encourages an important habit: compare an implementation with a plausible lower bound, then seek a better representation or exploit a pattern. The examples show that optimization is often a change in how the problem is framed, not merely a cleverer line of code.

The abstraction has limits. Big O suppresses constants and commonly discussed worst cases, while actual performance also depends on input distribution, implementation, memory behavior, and workload. Hash-table lookups are typically constant-time, not invulnerable to collisions; binary search trees are logarithmic only when their shape stays balanced. The book does explain several of these qualifications, but readers should treat complexity classes as models for decisions, not performance guarantees.

The broadest lesson is a form of disciplined engineering judgment. Arrays, linked lists, hash tables, trees, tries, and graphs are not contestants in a universal ranking. Each encodes a different promise: direct indexing, cheap local edits, rapid key lookup, ordered navigation, priority access, prefix sharing, or explicit relationships. Strong programmers learn to recognize the promise, identify its price, and verify that it matches the real problem. The result is not simply faster code, but code whose trade-offs can be explained and tested.

Summary in 30 Seconds
Algorithm efficiency depends on how work grows with input size: scanning takes O(N), binary search O(log N), and direct array access O(1). Choose structures for the operations repeated most. Hash tables average O(1) lookup by trading memory for speed, while ordered arrays search quickly but make insertion costly. Memoization reduces repeated Fibonacci work from O(2^N) to O(N). Measure performance, then weigh speed against memory.
Contains spoilers

Last updated:

Report Issue

Review Summary

4.39 out of 5
Average of 500+ ratings from Goodreads and Amazon.

A Common-Sense Guide to Data Structures and Algorithms receives mostly positive reviews for its clear explanations and beginner-friendly approach. Readers appreciate the intuitive examples, diagrams, and step-by-step breakdowns of complex concepts. Many find it helpful for interview preparation and as a refresher for those with prior knowledge. Some criticisms include inconsistent programming language use, lack of depth in certain areas, and occasional errors. Overall, it's highly recommended for beginners and self-taught programmers, though more advanced readers may find it too basic.

Your rating:
4.6
115 ratings
Want to read the full book?

Glossary

Big O Notation

Describes growth in work

A notation for describing how an algorithm's work changes as its input grows. O(1) denotes constant growth, O(N) linear growth, and O(log N) logarithmic growth. Big O commonly describes a worst-case upper bound and ignores constant factors and lower-order terms, making it useful for broad comparisons rather than exact runtime predictions.

abstract data type

Rules for using data

A conceptual data structure defined by its permitted operations and behavior, rather than by the particular storage mechanism underneath. A stack, for example, allows insertion and removal at one end and follows last-in, first-out order. It may be implemented using an array or another underlying structure.

hash function

Maps keys to locations

A function that transforms a key, such as a string, into a number used to determine where its associated value is stored in a hash table. A valid hash function must return the same result for the same key every time. If different keys map to the same location, the table must handle a collision.

load factor

Data-to-cell ratio

The ratio between the number of stored elements and the number of available cells in a hash table. A table with many entries relative to its cells is more likely to experience collisions, which can slow lookups. The book presents 0.7 as a practical target, or roughly seven items for every ten cells.

memoization

Stores computed results

A technique for avoiding repeated recursive work by saving the result of each completed computation, commonly in a hash table. Before calculating a result again, the function checks whether it has already been stored. Memoization is especially useful when recursive branches contain overlapping subproblems.

dynamic programming

Avoids repeated subproblems

A family of techniques for improving problems that can be broken into smaller versions of themselves, especially when those subproblems overlap. The book presents memoization and bottom-up computation as approaches. Memoization saves recursive results; a bottom-up solution builds results iteratively, often avoiding recursion.

heap condition

Orders parents over descendants

The ordering rule that defines a heap. In a max-heap, each node's value is greater than the values of its descendants, so the root contains the greatest value. A min-heap reverses this relationship. The heap condition does not order values enough to make arbitrary searches efficient.

trie

Stores shared character paths

A tree-based structure for storing words or other sequences as paths of characters. Words with shared beginnings reuse the same initial path, and a marker identifies where a complete word ends. Searching or inserting a string takes work related to its character count, making tries useful for prefix search and autocomplete.

Dijkstra's algorithm

Finds cheapest weighted routes

An algorithm for finding shortest paths in a weighted graph, where edges represent costs such as distance or price. It tracks the cheapest known cost from a starting vertex to other vertices, updates routes when a cheaper path is found, and records preceding vertices so a chosen path can be reconstructed.

best-imaginable Big O

Sets an optimization target

The fastest complexity a programmer believes could plausibly solve a particular problem. Comparing this target with the current algorithm's Big O helps reveal whether optimization might be worthwhile and provides a direction for improvement. It is an aspiration for analysis, not a guarantee that the target can be achieved.

magical lookups

Imagines constant-time searches

An optimization technique that asks whether an algorithm would improve if it could find a needed item in O(1) time. If the answer is yes, an additional data structure, often a hash table, may make the lookup possible. The method can reduce repeated scans, usually in exchange for extra memory.

About the Author

Jay Wengrow is the author of "A Common-Sense Guide to Data Structures and Algorithms." He is known for his ability to explain complex computer science concepts in simple, easy-to-understand language. Wengrow's writing style is praised for its clarity, use of real-life scenarios, and step-by-step explanations. His approach makes the book accessible to beginners and self-taught programmers. Wengrow's empathetic communication style and inclusion of illustrations help readers grasp difficult topics. He focuses on practical applications of algorithms and data structures, making the content relevant to real-world programming challenges. Wengrow's background and expertise in simplifying technical concepts contribute to the book's popularity among readers seeking a gentle introduction to data structures and algorithms.

Download PDF

To save this A Common-Sense Guide to Data Structures and Algorithms summary for later, download the free PDF. You can print it out, or read offline at your convenience.
Download PDF
File size: 0.31 MB     Pages: 19

Download EPUB

To read this A Common-Sense Guide to Data Structures and Algorithms summary on your e-reader device or app, download the free EPUB. The .epub digital book format is ideal for reading ebooks on phones, tablets, and e-readers.
Download EPUB
File size: 1.35 MB     Pages: 20
Want to read the full book?
Follow
Listen
Home
Swipe
Library
Get App
Try Full Access for 3 Days
Listen, bookmark, and more
Compare Features Free Pro
📖 Read Summaries
Read unlimited summaries. Free users get 3 per month
🎧 Listen to Summaries
Listen to unlimited summaries in 40 languages
—
❤️ Unlimited Bookmarks
Free users are limited to 4
—
📜 Unlimited History
Free users are limited to 4
—
📥 Unlimited Downloads
Free users are limited to 1
—
Risk-Free Timeline
Today: Get Instant Access
Listen to full summaries of 26,000+ books. That's 12,000+ hours of audio!
Day 2: Trial Reminder
We'll send you a notification that your trial is ending soon.
Day 3: Your subscription begins
You'll be charged on Nov 25,
cancel anytime before.
Consume 2.8× More Books
2.8× more books Listening Reading
Our users love us
1M+ readers
Trustpilot Rating
TrustPilot
4.6 Excellent
This site is a total game-changer. I've been flying through book summaries like never before. Highly, highly recommend.
— Dave G
Worth my money and time, and really well made. I've never seen this quality of summaries on other websites. Very helpful!
— Em
Highly recommended!! Fantastic service. Perfect for those that want a little more than a teaser but not all the intricate details of a full audio book.
— Greg M
Save 62%
Yearly
$119.88 $44.99/year/yr
$3.75/mo
Monthly
$9.99/mo
Start a 3-Day Free Trial
3 days free, then $44.99/year. Cancel anytime.
Unlock a world of fiction & nonfiction books
26,000+ books for the price of 2 books
Read any book in 10 minutes
Discover new books like Tinder
Request any book if it's not summarized
Read more books than anyone you know
#1 app for book lovers
Lifelike & immersive summaries
30-day money-back guarantee
Download summaries in EPUBs or PDFs
Cancel anytime in a few clicks

Why one summary?

Scanner
Find a barcode to scan

⭐
⭐
⭐
We have a special gift for you
Open
38% off
DISCOUNT FOR YOU
⭐
⭐
⭐
$79.99
$49.99/year
Only $4.16 per month
Continue
2 taps to start, super easy to cancel
Settings
General
Widget
Loading...