← Back to Data Structures & Algorithms
Question 547
Array Parent Of A Node
Array Parent Of A Node
In a complete binary tree stored in a list, the children of index i are at 2 * i + 1 and 2 * i + 2, so the parent of any index above 0 is at (i - 1) // 2. Write array_parent(i: int) -> int that returns the parent index, or -1 for the root at index 0 (that case is already in the starter). Use floor division. 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 value your function returns.
Expected Output:
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.