All Nodes Distance K in Binary Tree


We are given a binary tree (with root node root), a target node, and an integer value K. Return a list of the values of all nodes that have a distance K from the target node.  The answer can be returned in any order.   Example 1: Input: root = [3,5,1,6,2,0,8,null,null,7,4], target = 5, K = 2 Output: [7,4,1] Explanation: The nodes that are… Read more »

Priority Queues in Java

Programming Queue

Priority queues are a generalisation of stacks and queues. Rather than inserting and deleting elements in a fixed order, each element is assigned a priority represented by an integer. We always remove an element with the highest priority, which is given by the minimal integer priority assigned. Priority queues often have a fixed size. Advantages… Read more »

Binary Search Trees

Binary Search Programming Tree

Binary Search Trees or BST is an ordered binary tree where all the nodes on the left of a node are less or equal to the node’s own value and all the values on the right are greater or equal to the node’s own value. A Binary Tree is a tree with only two children,… Read more »

Breadth First Search or BFS for a Graph


In Breadth-first search (BFS) you start with the root, move left to right across the second level, then move left to right across the third level, and so forth. Breadth-first search (BFS) is a method for exploring a tree or graph. In a BFS, you first explore all the nodes one step away, then all… Read more »