Level order traversal of a binary tree
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.
Ace your Coding Interview
Get hired by top tech companies with our comprehensive interview preparation.
Get StartedGiven 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.
Write an efficient algorithm to check if two binary trees are identical or not, i.e., if they have identical structure and their contents are also identical.
This post will detect cycles in a linked list using hashing and Floyd’s cycle detection algorithm.
Given a linked list, split it into two lists where each list contains alternating elements from the original list and then finally join them back together.
Given a linked list, move its last node to the front. For example, list {1, 2, 3, 4} should be changed to {4, 1, 2, 3}.
Given a linked list and two positive integers, m and n, delete every n nodes after skipping m nodes.
Given a linked list and a positive integer k, find the k’th node from the end of the list.
Given two linked lists, merge their nodes to make one list, taking nodes alternately between the two lists. If either list runs out, all the nodes should be taken from the other list.
Given a linked list, move its front node in front of another given list.
Given a linked list sorted in increasing order, write a function that removes duplicate nodes from the list by traversing it only once.