LeetCode Queue Design Patterns in C++: Put the Answer at an Edge LeetCode Queue Design Patterns in C++: Put the Answer at an Edge nycomdorics.com · preview of the WordPress post · source deck by Joseph Choi A binary heap will hand you its smallest element instantly and tell you nothing whatsoever about the second smallest. A std::vector will append and remove at the back in constant time and charge you a full shift to remove from the front. Every structure in this family is generous at its edges and useless in its interior. So the design job is always READ MORE
Tag: Data Structures
Priority Queues & Binary Heaps Explained: How They Work Under the Hood
Imagine a hospital emergency room. Patients don’t get seen in the order they arrived — they get seen based on the severity of their condition. A patient with a heart attack jumps ahead of someone with a sprained ankle, regardless of who checked in first. That’s exactly the problem a priority queue solves in software. In this post, we’ll cover what priority queues are, how the binary heap makes them efficient, and how the core operations — insertion, extraction, and heapify — actually work. What Is a Priority Queue? A priority queue is a specialized version of a regular queue. READ MORE
Tree Data Structures Explained: Binary Trees, BSTs & Tree Traversals
Arrays and hash tables are great for storing flat collections of data. But what about data that’s naturally hierarchical — like a company org chart, a file system, or the rules in a decision-making process? That’s where trees come in. Trees are one of the most widely used data structures in computer science, and a solid understanding of them will help you with everything from database internals to coding interviews. In this post, we’ll cover what trees are, the most important types, and how to traverse them in four different ways. What Is a Tree? A tree is a hierarchical READ MORE
Hash Tables Explained: How Hashmaps Work Under the Hood
If you’ve ever used a dictionary in Python, an object in JavaScript, or an unordered_map in C++, you’ve already used a hash table. It’s one of the most important data structures in programming — and once you understand how it works internally, a lot of things in software development start to click. In this post, we’ll cover everything from the basics of key-value pairs to hash functions, collision handling, and the trade-offs behind different implementations. What Is a Hash Table? A hash table (also called a hashmap) is a data structure that stores key-value pairs and allows you to look READ MORE
BFS vs DFS Explained: Graph Traversal Algorithms with Code Examples
Every graph algorithm starts with the same fundamental question: how do we visit every node? Answering that question efficiently is the job of the two core traversal algorithms — Breadth-First Search (BFS) and Depth-First Search (DFS). By the end of this post you’ll understand how both work, when to use each, and how DFS extends naturally into topological sort — one of the most useful tools in any developer’s toolkit. This is Part 2 of a 3-part series. Start with Part 1 if you haven’t yet. The Node Status Model Before writing any traversal code, it helps to think of READ MORE
Graph Data Structures Explained: A Beginner’s Guide to Nodes, Edges & Representations
If you’ve ever used Google Maps, browsed a social network, or watched a package get routed across the internet — you’ve already interacted with a graph without knowing it. Graphs are one of the most powerful and widely-used data structures in computer science, and understanding them will level up the way you think about problems. In this first post of a three-part series, we’ll cover everything you need to get started: what graphs are, the vocabulary you’ll need to know, and how to represent them in code. What Is a Graph? A graph is a collection of two things: That’s READ MORE