How to Serialize Binary Tree

后端 未结 10 916
野的像风
野的像风 2020-12-23 21:09

I went to an interview today where I was asked to serialize a binary tree. I implemented an array-based approach where the children of node i (numbering in level-order trave

10条回答
  •  感动是毒
    2020-12-23 21:31

    convert it to array with size of (2n + 1) each left son and right son will be in place of (2 * node number) and ((2 * node number) + 1 accordingly.

    using https://www-inst.eecs.berkeley.edu//~cs61bl/r/cur/trees/array-repr.html?topic=lab20.topic&step=1&course=

提交回复
热议问题