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
Tag: C++
Dijkstra’s Algorithm, Minimum Spanning Trees & Union Find Explained
In Part 1 we covered what graphs are and how to represent them. In Part 2 we explored BFS and DFS — the two ways to traverse a graph. Now it’s time for the advanced algorithms that solve real engineering problems: finding the shortest weighted path, connecting a network at minimum cost, and efficiently grouping nodes. This is Part 3 of a 3-part series. Start from Part 1 if you’re new to graphs. Dijkstra’s Algorithm — Shortest Path in a Weighted Graph The Problem BFS finds the shortest path in an unweighted graph (fewest edges). But what if edges have 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
Basics of C++ Class
C++ class is a custom data type user defines, which is called user-defined type.A data type in C++ represents certain types of data.For example, there are built-in types such as int and double which represent integer and decimal numbers.Declaring a variable with a data type requires memory and you can perform operations such as addition, subtraction, multiplication, and division with it.You can also use those variables as function arguments, parameters, and return values.In that sense, you can define your own data type to operate like built-in data type variables. Why do we need a user-defined type? A user-defined type is READ MORE
C++ Filestream
In C++, you can interact (read/write) with disk files using filestream classes.The C++ filestream is very similar to standard cin and cout streams.Just like cin and cout, there are two classes for filestream: ifstream for input and ofstream for output.For the input stream, you can imagine there is a stream connected to disk file and characters are copied from the file to the stream and your program is reading characters from the stream.For the output stream, you can imagine the opposite way of the input stream: your program writes to the stream and stream to the disk file. Basic Usage READ MORE
Intro to Binary Search Algorithm
Let’s say there is an unsorted array and you need to find certain values.How would you search for those values? You can’t avoid iterating the entire array every time you are searching since the array is unsorted.Wouldn’t this be a very inefficient way of searching?It may be fine if the size of the array is pretty small. However, what if there are one million elements in the array?You probably do not want to iterate one million elements every time you search because it’s a waste of time. Binary search algorithm is a very efficient search algorithm.It requires the array to READ MORE
Intro to Binary Search Tree
Binary search tree is very efficient and has strengths of array and linked list.Array and Linked List are great data structure but they have some weaknesses.It’s fast to access array but slow to adjust the size.It’s slow to access linked list but fast to adjust the size.However, it’s fast to access binary search tree and it’s still very flexible to adjust the size. What is Binary Tree? Before diving into binary search tree we need to understand binary tree first.Binary tree is an extended form of singly linked list but has two pointers to other nodes (children) instead.Pointers are not READ MORE
Intro to Heap data structure
Heap is one of the most efficient data structure that can handle data for certain purposes.To have a better understanding of heap you can imagine a priority queue. For example, let’s say there are multiple jobs that you need to do for today. They could be chores, work, and any activities.However, not all of them have the same priority and you probably want to finish jobs in order of importance. A priority queue is a queue that takes tasks and handles them in order of specified priority.Therefore, unlike a normal queue which is FIFO – first in first out, a READ MORE
Intro to Array data structure Part 2 – 2D Array
Continuing from the last post I am going to discuss more about the array data structure which is 2D array.In this post, I will focus on the basic concept and usage. What is 2D Array? 2D array is basically array within array.Typically array contains specified data type in its element.However, it is possible that the element can contain another array instead! This is a 2D array with 3 rows and 5 columns.In each row, there is an array of size 5 which is the column size.In other words, there is an array of size 3 (row) and there is another READ MORE