Question
A recursive function calculate_height(node) is designed to find the height of a binary tree (where a single node has height 0). The function is implemented as: def calculate_height(node): if node is None: return -1 # Base case left_height = calculate_height(node.left) right_height = calculate_height(node.right) return 1 + max(left_height, right_height) When tested with a single-node tree (e.g., Node(10)), it returns 0. However, when tested with an empty tree (None), it returns -1. If the desired output for an empty tree is also -1 and for a single node tree is 0, the current implementation is correct. But if the definition of height for a single node tree is 1, what change would be needed in the base case?
More IT Operating System Questions
- What is the typical time complexity for inserting an element into a java.util.PriorityQueue with N elements? import java.util.PriorityQueue; ...
- What is the purpose of the #include directive in C/C++ programming?
- What is the relationship between the Java Virtual Machine (JVM) and the Java Runtime Environment (JRE)?
- Which is relational Database
- In Oracle database variable length column is declared by ____________
- If receiver noise floor is 2 dB, signal-to-noise ratio is 3 dB then what is the receiver sensitivity?
- What is the main advantage of using knowledge graphs in AI?
- Fill the blank In K-Means algorithm, we calculate the distance between each point of the dataset to every ________ initialized.
- Three processes P1 (burst time 6 ms), P2 (burst time 4 ms), and P3 (burst time 2 ms) all arrive at time 0 and are scheduled using Round Robin with a time q...
- A system uses 36-bit virtual addresses and a page size of 8 KB. How many bits of the virtual address are used to represent the page offset?
Hey! Ask a query
Please enter email id
The email must be a valid email address.
Please enter Mobile Number
Please enter valid Mobile Number
Please enter your Doubt
Think You're Ready for RBI Grade B?
RBI Grade B 2026 Phase 1 Memory Based Paper
- 200 Questions with Detailed Solutions
- Section-wise Coverage (GA, English, Quant & Reasoning)