Representing a Directed Unweighted Graph with an Adjacency Matrix

Representing a Directed Unweighted Graph with an Adjacency Matrix

A directed unweighted graph can be stored in an adjacency matrix where each row is a starting node and each column is an ending node. A value of 0 means no edge and 1 means an edge exists. Because the structure is really a contiguous one dimensional array under the hood, reading or writing any cell is constant time. Self connections are not implied unless explicitly added, and the matrix is not symmetric the way an undirected graph matrix would be.
How to Represent an Undirected Unweighted Graph with an Adjacency Matrix

How to Represent an Undirected Unweighted Graph with an Adjacency Matrix

Represent an undirected unweighted graph as an adjacency matrix of ones and zeros. A one in the cell at row i and column j means an edge exists between those nodes. Because the graph is undirected the matrix is symmetric across the diagonal. Changing a cell from zero to one adds an edge and changing it back removes the edge. Self-loops appear on the diagonal. This representation stores only the connection relationships and supports constant-time edge checks.
AVL Tree Rotations Tutorial: Fixing Imbalance After Adding a Node

AVL Tree Rotations Tutorial: Fixing Imbalance After Adding a Node

Learn how to maintain balance in AVL trees through rotations. This tutorial shows inserting a new node into an AVL tree, recalculating balance factors up the path to the root, identifying the first imbalanced node, selecting X Y Z nodes based on subtree heights, and executing a double right rotation to restore the AVL property while preserving binary search tree ordering.
AVL Tree Rotation Types Explained for Self-Balancing Binary Search Trees

AVL Tree Rotation Types Explained for Self-Balancing Binary Search Trees

In AVL trees, when we find a node with a balance factor of 2 or worse, we perform rotations on the trinode subtree. There are four input patterns that all resolve to the same balanced output pattern through single or double rotations. Single rotations handle straight line imbalances while double rotations address the zigzag cases. Each rotation rearranges parent-child pointers to reduce the height from 3 to 2, helping keep the overall tree balanced for log time operations.
AVL Tree Tutorial: Balance Factors and Why They Fix Slow BSTs

AVL Tree Tutorial: Balance Factors and Why They Fix Slow BSTs

AVL trees are self-balancing binary search trees that prevent the tree from becoming unbalanced. We compute balance factors as the absolute value of left subtree height minus right subtree height. If any node has a balance factor of 2 or worse, we rebalance using rotations on trinode subtrees. This keeps search, insert, and other operations efficient at logarithmic time.