Tag: recursion

How a Regex Engine Work?

A regular expression defines a set of string. A regex engine matches a pattern against input and returns true/false for the condition that pattern exists in the input. I have got a C++ implementation of a regex engine which uses simple constructs of matching the following: A single character An equal length pattern and input A pattern that has ^…

Height of a Binary Tree: Recursion Unrolled & Explained

— tags: >- development, C++, tree, height, programming, recursion, internals, complete flow categories: development — Height of a Binary Tree is the longest path in the tree. Code int getHeight(node *root) { if (root == NULL) { return -1; } int leftHeight = getHeight(root->left); int rightHeight = getHeight(root->right); return (max(leftHeight, rightHeight) + 1); } Suppose the tree is as follows:…