title-img


Matrix

The kingdom of Zion has cities connected by bidirectional roads. There is a unique path between any pair of cities. Morpheus has found out that the machines are planning to destroy the whole kingdom. If two machines can join forces, they will attack. Neo has to destroy roads connecting cities with machines in order to stop them from joining forces. There must not be any path connecting two machines. Each of the roads takes an amount of time to destroy, and only one can be worked on at a time.

View Solution →

Tree: Height of a Binary Tree

The height of a binary tree is the number of edges between the tree's root and its furthest leaf. For example, the following binary tree is of height 2: Function Description Complete the getHeight or height function in the editor. It must return the height of a binary tree as an integer. getHeight or height has the following parameter(s): root: a reference to the root of a binary tree. Note -The Height of binary tree with single node is taken as zero. Input Format The first

View Solution →

Binary Search Tree : Lowest Common Ancestor

You are given pointer to the root of the binary search tree and two values v1 and v2. You need to return the lowest common ancestor (LCA) of v1 and v2 in the binary search tree. Function Description Complete the function lca in the editor below. It should return a pointer to the lowest common ancestor node of the two values given. lca has the following parameters: - root: a pointer to the root node of a binary search tree - v1: a node.data value - v2: a node.data value Input For

View Solution →

Trees: Is This a Binary Search Tree?

For the purposes of this challenge, we define a binary search tree to be a binary tree with the following properties: The data value of every node in a node's left subtree is less than the data value of that node. The data value of every node in a node's right subtree is greater than the data value of that node. The data value of every node is distinct. For example, the image on the left below is a valid BST. The one on the right fails on several counts: - All of the numbers on the right

View Solution →

Tree: Huffman Decoding

Huffman coding assigns variable length codewords to fixed length input characters based on their frequencies. More frequent characters are assigned shorter codewords and less frequent characters are assigned longer codewords. All edges along the path to a character contain a code digit. If they are on the left side of the tree, they will be a 0 (zero). If on the right, they'll be a 1 (one). Only the leaves will contain a letter and its frequency count. All other nodes will contain a null instead

View Solution →