VOOZH about

URL: https://www.geeksforgeeks.org/dsa/minimizing-signal-propagation-time-in-a-binary-tree/

⇱ Minimizing Signal Propagation Time in a Binary Tree - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Minimizing Signal Propagation Time in a Binary Tree

Last Updated : 23 Jul, 2025

Given a binary tree and a source node "start" which transmits a network signal. The signal propagates to neighboring nodes every second, the task is to determine the minimum amount of time required for the entire tree to receive the signal.

Examples:

Input:
11
/ \
12 13
/ \
14 15
/ \ / \
21 22 23 24
Start = 14
Output: 3

Input: 
4
/ \
3 1
\
2
Start = 1
Output: 2

Minimizing Signal Propagation Time in a Binary Tree using BFS:

Start from the given node "start" and use a Breadth-First Search (BFS) approach. Propagate signal to neighboring nodes during the BFS process and keep track of time until all nodes have been visited. To handle the issue of determining a node's parent, create a data structure that maintains parent-node relationships, this will allowing to track each node's parent.

Step-by-step approach:

  • Store parent-child relationships for each node using a parent[] array.
  • Find the given start node in the tree.
  • Initilise a queue for BFS and a visited[] array to track nodes which received signal.
  • While the queue is not empty:
    • For each level of nodes in the queue:
      • If the current node's parent exists and didn't receive signal, mark it as visited and add it to the queue.
      • If the left child of the current node exists and didn't receive signal, mark it as visited and add it to the queue.
      • If the right child of the current node exists and didn't receive signal, mark it as visited and add it to the queue.
    • Increment the time (or, result) by 1.
  • Finally, return the time (or, result).

Below is the implementation of the above approach:


Output
3

Time Complexity: O(N), where N is the number of nodes in the binary tree.
Auxiliary Space: O(N)

Comment