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
- Consider the following JSON object: json { "user": { "id": "u123", "name": "Alice", "age": 30, "address": { "street": "123 ...
- The order of convergence of Newton-Raphson method is:
- The Divide and Conquer paradigm involves three main steps. What are they?
- What is the primary purpose of a system call?
- Which operator in C has the highest precedence among the following?
- A Process Control Block (PCB) stores all information about a process. Which of the following is not typically stored in a PCB?
- What is a 'context switch' in operating systems?
- Which device operates at the Data Link Layer and uses MAC addresses to forward frames only to the intended recipient port?
- Which of these is a cloud-based IoT platform?
- In a perfectly balanced Binary Search Tree with N nodes, what is the worst-case time complexity for searching for an element?
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)