Print top view of a binary tree
Given a binary tree, print the top view of it. Assume the left and right child of a node makes a 45–degree angle with the parent.
Ace your Coding Interview
Get hired by top tech companies with our comprehensive interview preparation.
Get StartedGiven a binary tree, print the top view of it. Assume the left and right child of a node makes a 45–degree angle with the parent.
Given a binary tree, print the bottom view of it. Assume the left and right child of a node makes a 45–degree angle with the parent.
Given a binary tree, write an efficient algorithm to print its left view. For example, the left view of the following binary tree is 1, 2, 4, 7.
Given a binary tree, print its nodes level by level in reverse order, i.e., print all nodes present at the last level first, followed by nodes of the second last level, and so on… Print nodes at any level from left to right.
Given a binary tree, print its nodes level by level in spiral order, i.e., all nodes present at level 1 should be printed first from left to right, followed by nodes of level 2 right to left, followed by nodes of level 3 from left to right and so on…
Given a binary tree, print its nodes level by level, i.e., print all nodes of level 1 first, followed by nodes of level 2 and so on… Print nodes for any level from left to right.
Given a binary tree, write an efficient algorithm to delete the entire binary tree. The program should deallocate every single node present in the tree, not just change the root node’s reference to null.
Write an efficient algorithm to compute the binary tree’s height. The height or depth is the total number of edges or nodes on the longest path from the root node to the leaf node.
Given an M × N binary matrix, replace all occurrences of 0’s by 1’s, which are not completely surrounded by 1’s from all sides (top, left, bottom, right, top-left, top-right, bottom-left, and bottom-right).
Flood fill (also known as seed fill) is an algorithm that determines the area connected to a given node in a multi-dimensional array.
Given an M × N matrix of characters, find all occurrences of a given string in the matrix. We are allowed to search the string in all eight possible directions. Note that there should not be any cycles in the output path.
Given an N × N matrix of positive integers, find a path from the first cell of the matrix to its last cell.