← Back to Data Structures & Algorithms
Question 532
Array Children Of A Node
Array Children Of A Node
A complete binary tree can be stored in a list, row by row, with the root at index 0. Write array_children(i: int) -> tuple[int, int] that returns the indexes of the left and right children of the node at index i as a tuple: the left child is at 2 * i + 1 and the right child at 2 * i + 2. Do NOT write a main block or any top-level test code; the tests construct the calls. Input: one integer, the index; the tests print the tuple your function returns.
Expected Output:
(1, 2)= newline. The output ends with a newline — print one after the last line.
Hints2 available
Sign in to use hintsTopics:
Data Structures & Algorithms
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (pr, inp, def)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.