DSA 섹션중간

B 트리

'B 트리' 문제에 대한 자세한 가이드 및 Python 구현입니다.

문제 설명

중간

B-트리 구조 노드 속성이 유효한지 확인하는 함수 is_valid_btree_leaf_depth(keys, child_pointers, t)을 작성하세요. 특히 모든 리프 노드가 동일한 깊이에 있고 모든 노드(루트 제외)에 t-1에서 2t-1 키가 있는 경우 True을 반환합니다. 여기서 t는 최소 차수입니다. 입력 형식: keys 노드 ID를 키 목록에 매핑, child_pointers 노드 ID를 하위 ID 목록에 매핑, 최소 차수 t.

제약
  • 2 <= t <= 10
  • 1 <= len(keys) <= 100

Example 1
Input
keys = {1: [10, 20], 2: [5], 3: [15], 4: [25, 30]}, child_pointers = {1: [2, 3, 4]}, t = 2
Output
True
Explanation

Root 1 has keys [10, 20]. Children 2, 3, 4 are leaves at the same depth 1 and satisfy the key count constraint of 1 to 3 keys.

Need a Hint?
세트나 힙과 같은 트리 관련 데이터 구조를 사용해 보세요.
Edge Cases to Watch
  • 빈 입력 구조
  • 단일 요소 입력
  • 큰 수치 범위

해결할 준비가 되셨나요?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

편집기에서 열기
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

권장 Python 리소스

관련 대화형 튜토리얼, 치트 시트, 코드 비교를 통해 지식을 확장하세요.