practivceAlgorithm/swexpertacademy

[SWEA][Python] 5176 이진 탐색

findTheValue 2021. 8. 24. 00:40

전위순회. 좌진입, 출력, 우진입 순서

 

def inorder_tree(node,value):
    if node > N:
        return value
    else:
        value = inorder_tree(node*2,value)
        value += 1
        tree[node] = value
        value = inorder_tree(node*2 + 1,value)
        return value
 
for test in range(1, int(input())+1):
    N = int(input())
    tree = [0] *(N+1)
    inorder_tree(1,0)
    print(f'#{test} {tree[1]} {tree[N//2]}')

'practivceAlgorithm > swexpertacademy' 카테고리의 다른 글

[SWEA][Python] 5178 노드의 합  (0) 2021.08.24
[SWEA][Python] 5177 이진힙  (0) 2021.08.24
[SWEA][Python] 5174 subtree  (0) 2021.08.24
[SWEA][Python] 5122 수열편집  (0) 2021.08.24
[SWEA][Python] 5120 암호  (0) 2021.08.24