CJCoding With Joseph
15free / daySign inCreate account

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
Topics:
Data Structures & Algorithms
📥 Auto-Input:
6\n
This input is automatically fed to your program's stdin
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.