Serialize a Binary Tree or a General Tree
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的更多相关文章
- 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 ...
- 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, ...
- 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 ...
- 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 ...
- 145. Binary Tree Postorder Traversal (Stack, Tree)
Given a binary tree, return the postorder traversal of its nodes' values. For example: Given binary ...
- LeetCode -- 1038. Binary Search Tree to Greater Sum Tree
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode ...
- 【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 ...
- 【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 ...
- 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 ...
随机推荐
- activity_main.xml
activity_main.xml: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android ...
- HDU 3974 Assign the task 简单搜索
根据Rex 的思路才知道可以这么写. 题目意思还是很好理解的,就是找到当前雇员最近的任务. 做法是,可以开辟一个 tim 变量,每次有雇员得到昕任务时候 ++tim 然后取寻找最近的任务的时候写一个搜 ...
- js词法作用域
作用域链和原型链是JS中比较重要的2个概念, JS的是函数作用域,与C之类语言的块级作用域不同 JS的作用域还是词法作用域,或者叫静态作用域,作用域链是在语法解析时就完成的,而不是在执行时创建. 例子 ...
- 详解iOS7升级细节:引领视觉革命
下星期我们将看到的正式版将和WWDC上看到的大不相同.苹果六月份发布了全新版本的iOS操作系统——这是从2007年首次发布以来的最大的一次调整和改进.这次的改变招致许多批评.许多设计师在网站上晒出了他 ...
- 死锁 android ANR
以下为一段ANR的LOG,主要是在WindowManagerService.java和ActivityManagerService.java中实现. W/WindowManager( 2183): K ...
- 多个线程怎样操作同一个epoll fd
自己曾经做一个接口server时候,这样的场景下我的设计是多个线程操作同一个epoll fd.彼时,我的理由是epoll的系列函数是线程安全的. 当然有人不理解为什么会有多个线程操作同一个epoll ...
- Cocos2D-X扫盲之坐标系、锚点
一.引言 在Cocos2D-X的开发过程中,经常会碰到设置精灵位置的问题.而设置位置的过程,涉及到两个问题:第一是坐标系,包括原点的位置.X/Y坐标轴的方向灯:第二是基准点(Cocos2D-X中叫锚点 ...
- PostgreSQL正则表达式查询
参考http://www.php100.com/manual/PostgreSQL8/functions-matching.html LIKE string LIKE pattern [ ESCAPE ...
- redis安装及数据类型简介(string、list、set、sorted_set、hash)
一:简介: redis国内最大的案例--->新浪微博 memcache:是key-value数据库 数据类型:只支持key value数据 过期策略:支持 持久化:不支持(可以通过三方程序) 主 ...
- 设计模式(五)适配器模式Adapter(结构型)
设计模式(五)适配器模式Adapter(结构型) 1. 概述: 接口的改变,是一个需要程序员们必须(虽然很不情愿)接受和处理的普遍问题.程序提供者们修改他们的代码;系统库被修正;各种程序语言以及相 ...