Sezione DSAMedio

B Albero

Guida dettagliata e implementazione Python per il problema "B Tree".

Dichiarazione del problema

Medio

Scrivi una funzione is_valid_btree_leaf_depth(keys, child_pointers, t) che controlla se le proprietà del nodo di una struttura B-Tree sono valide. Nello specifico, restituisce True se tutti i nodi foglia sono alla stessa profondità e ogni nodo (eccetto root) ha chiavi comprese tra t-1 e 2t-1, dove t è il grado minimo. Formato di input: keys mappatura dell'ID del nodo all'elenco di chiavi, child_pointers mappatura dell'ID del nodo all'elenco degli ID secondari e grado minimo t.

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

Esempi

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?
Prendi in considerazione l'utilizzo di strutture dati specifiche di Trees come set o heap.
Edge Cases to Watch
  • Strutture di input vuote
  • Ingressi a elemento singolo
  • Grandi limiti numerici

Pronto a risolvere?

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

Apri nell'editor
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

Risorse Python consigliate

Espandi le tue conoscenze con tutorial interattivi, foglietti illustrativi e confronti di codici correlati.