Giter Site home page Giter Site logo

chaangliu / serialize-and-deserialize-multinode-tree Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 0.0 5 KB

Serialize and deserialize a binary tree is a platitude, this repo demonstrates how to Serialize and deserialize a multi-node tree. 序列化和反序列化一棵多叉树。

Java 100.00%

serialize-and-deserialize-multinode-tree's Introduction

Serialize and Deserialize a Multi-node Tree


Serialize and deserialize a binary tree is a platitude, this repo demonstrates how to Serialize and deserialize a multi-node tree, both recursively and iteratively.

Basically it is the idea of recording the children amount of each node.

For instance, a multi-child tree like below

         1
        /|\
       2 3 4
      / \
     5   6

will be serialized as:

Recursively:

"1#3,2#2,5#0,6#0,3#0,4#0,", each item representing: id#childCount.

Iteratively:

"1#3,2#2,3#0,4#0,5#0,6#0,", each item representing: id#childCount.

*In Addition, recursive approach will probably cause StackOverFlow exception. According to my test on my MBP(Core i5, 8GbRAM), 19,000~20,000 recursion will cause StackOverFlow exception, which means when there's more than 19,000 nodes, recursive approach may not work.


To realize binary tree serialization/deserialization, see also: serialize-and-deserialize-binary-tree

serialize-and-deserialize-multinode-tree's People

Contributors

chaangliu avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.