Sezione DSAMedio

Attraversamenti sugli alberi

Guida dettagliata e implementazione Python per il problema 'Tree Traversals'.

Dichiarazione del problema

Medio

Scrivi una funzione get_tree_traversals(tree_arr) che accetta una rappresentazione array di un albero binario tree_arr e restituisce un elenco di elenchi contenenti [inorder, preorder, postorder] attraversamenti dell'albero.

Vincoli
  • 0 <= len(tree_arr) <= 1000

Esempi

Example 1
Input
tree_arr = [1, None, 2, None, None, 3]
Output
[[1, 3, 2], [1, 2, 3], [3, 2, 1]]
Explanation

Inorder traversal visits left-root-right: [1, 3, 2]. Preorder visits root-left-right: [1, 2, 3]. Postorder visits left-right-root: [3, 2, 1].

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.