For a binary tree, preorder traversal may be enough.

For example,

    _30_
   /   \   
  10    20
 /     /  \
50    45  35

The result is

30 10 50 # # # 20 45 # # 35 # #
Using a queue to deserialize it . 

But a for multi-way tree, we could also use an array to serialize it, e.g.,

30 10 20 50 45 35

-1   0    0   1    2   2

Serialize a Binary Tree or a General Tree的更多相关文章

  1. What is the difference between a binary tree, a binary search tree, a B tree and a B+ tree?

    Binary Tree : It is a tree data structure in which each node has at most two children. As such there ...

  2. 102. Binary Tree Level Order Traversal (Tree, Queue; BFS)

    Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, ...

  3. 199. Binary Tree Right Side View (Tree, Stack)

    Given a binary tree, imagine yourself standing on the right side of it, return the values of the nod ...

  4. 124. Binary Tree Maximum Path Sum (Tree; DFS)

    Given a binary tree, find the maximum path sum. For this problem, a path is defined as any sequence ...

  5. 145. Binary Tree Postorder Traversal (Stack, Tree)

    Given a binary tree, return the postorder traversal of its nodes' values. For example: Given binary ...

  6. LeetCode -- 1038. Binary Search Tree to Greater Sum Tree

    /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode ...

  7. 【leetcode】1038. Binary Search Tree to Greater Sum Tree

    题目如下: Given the root of a binary search tree with distinct values, modify it so that every node has ...

  8. 【LeetCode】 99. Recover Binary Search Tree [Hard] [Morris Traversal] [Tree]

    Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing ...

  9. Data Structure Binary Tree: Convert a given tree to its Sum Tree

    http://www.geeksforgeeks.org/convert-a-given-tree-to-sum-tree/ #include <iostream> #include &l ...

随机推荐

  1. 配置greenplum参数

    在进行一个greenplum安装之前需要进行配置一下相关的系统参数,否则很容易出现意想不到的错误. 1.修改系统参数 编辑 /etc/sysctl.conf ,以下是最小配置 kernel.shmma ...

  2. 自己新建Xib 和.h .m文件关联

    代理中注意点 1.新建MainViewController.h 和 MainViewController.m文件: 新建Main.xib文件: 2.拖View到Main.xib中: 3.点击File’ ...

  3. [POJ 1521]--Entropy(哈夫曼树)

    题目链接:http://poj.org/problem?id=1521 Entropy Time Limit: 1000MS    Memory Limit: 10000K Description A ...

  4. django中上传图片的写法

    view参数 @csrf_exemptdef before_upload_avatar(request):    before = True    return render_to_response( ...

  5. 基于visual Studio2013解决C语言竞赛题之0514单词统计

     题目 解决代码及点评 /************************************************************************/ /* 14. 有一行字 ...

  6. 无线网络wifi (WPA/WPA2)密码破解方法

    无线网络password破解WPA/WPA2教程 本教程用于探索无线路由安全漏洞,禁止用于非法用途,违者法律必究(与我无关) 在动手破解WPA/WPA2前,应该先了解一下基础知识,本文适合新手阅读 首 ...

  7. 九度OnlineJudge之1023:EXCEL排序

    题目描述:     Excel可以对一组纪录按任意指定列排序.现请你编写程序实现类似功能.     对每个测试用例,首先输出1行“Case i:”,其中 i 是测试用例的编号(从1开始).随后在 N ...

  8. PHP - 对象转json - json转数组

    前台js转为json,传给php后台,php后台接收并转为数组. 效果: -- 前台js将对象转为json: var rows = JSON.stringify(rows); 后台php接收转为数组: ...

  9. NSString和NSDate的转换

    输入的日期字符串形如:@"1992-05-21 13:08:08" - (NSDate *)dateFromString:(NSString *)dateString{ NSDat ...

  10. 高级UIKit-06(UIImagePickerController)

    [day07-1-getSystemImage]:获取系统相册 UIImagePickerController图片采集控制器 picker采集者,采摘者 该方法继承自:UINavigationCont ...