当前位置:网站首页>2.7 binary tree, post order traversal - [FBI tree]
2.7 binary tree, post order traversal - [FBI tree]
2022-07-02 12:33:00 【I boiled the night white_】
List of articles
Title Description

Input description
The first line is an integer N(0<=N<=10)
The second line is a length of 2N Of “01” strand .
Output description
Output a string , namely FBI The subsequent traversal sequence of the tree .
I/o sample
Input :
3
10001011
Output :
IBFBBBFIBFIIIFF
The final code
1. c/c++
#include <bits/stdc++.h>
using namespace std;
char s[2000],tree[280000]; //tree[] Full binary tree
// First, the leaf node has a value , Then determine the value of the parent node according to the value of the leaf node
void build_FBI(int k,int left,int right)
{
// Reach the leaf node
if(left==right)
{
if(s[right]=='1') tree[k]='I';
else tree[k]='B';
return;
}
int mid=(left+right)/2; // Split in two
build_FBI(2*k,left,mid); // Recursive left half
build_FBI(2*k+1,mid+1,right); // Recursive right half
if(tree[2*k]=='B' && tree[2*k+1]=='B') // Both left and right sons B
tree[k]='B';
else if(tree[2*k]=='I'&&tree[2*k+1]=='I') // Both left and right sons I
tree[k]='I';
else tree[k]='F';
}
void postorder (int v){
// After the sequence traversal
if(tree[2*v])
postorder (2*v);
if(tree[2*v+1])
postorder (2*v+1);
printf("%c",tree[v]);
}
int main(){
int n;
scanf("%d",&n);
scanf("%s",s+1);
build_FBI(1,1,strlen(s+1));
// Post order traversal output
postorder(1);
}
2. java
3. python
Process understanding


边栏推荐
- SparkContext: Error initializing SparkContext解决方法
- arcgis js 4.x 地图中加入图片
- China traffic sign detection data set
- Drools executes string rules or executes a rule file
- Simple understanding of ThreadLocal
- When uploading a file, the server reports an error: iofileuploadexception: processing of multipart / form data request failed There is no space on the device
- How to write a pleasing English mathematical paper
- Drools terminates the execution of other rules after executing one rule
- Drools executes the specified rule
- Deep understanding of P-R curve, ROC and AUC
猜你喜欢

Natural language processing series (I) -- RNN Foundation

Go学习笔记—多线程

Record the range of data that MySQL update will lock

Anti shake throttle

Find the common ancestor of any two numbers in a binary tree

kubenetes中port、targetPort、nodePort、containerPort的区别与联系

Addition, deletion, modification and query of MySQL table (Advanced)

mysql表的增删改查(进阶)

arcgis js 4. Add pictures to x map

Drools dynamically add, modify, and delete rules
随机推荐
Jenkins user rights management
H5 to app
mysql索引和事务
子线程获取Request
CDA data analysis -- Introduction and use of aarrr growth model
Fastdateformat why thread safe
Those logs in MySQL
LeetCode—<动态规划专项>剑指 Offer 19、49、60
This "little routine" is set on the dough cake of instant noodles. No wonder programmers are always hungry
Leetcode - < dynamic planning special> Jianzhi offer 19, 49, 60
The programmer and the female nurse went on a blind date and spent 360. He packed leftovers and was stunned when he received wechat at night
Is the neural network (pinn) with embedded physical knowledge a pit?
Find the factorial of a positive integer within 16, that is, the class of n (0= < n < =16). Enter 1111 to exit.
China traffic sign detection data set
趣味 面试题
5g era, learning audio and video development, a super hot audio and video advanced development and learning classic
String palindrome hash template question o (1) judge whether the string is palindrome
Intel 内部指令 --- AVX和AVX2学习笔记
单指令多数据SIMD的SSE/AVX指令集和API
初始JDBC 编程