1. 程式人生 > >Falling Leaves(10.1.2))

Falling Leaves(10.1.2))


Figure 1

Figure 1 shows a graphical representation of a binary tree of letters. People familiar with binary trees can skip over the definitions of a binary tree of letters, leaves of a binary tree, and a binary search tree of letters, and go right to The problem.

A binary tree of letters may be one of two things:
  1. It may be empty.
  2. It may have a root node. A node has a letter as data and refers to a left and a right subtree. The left and right subtrees are also binary trees of letters.

In the graphical representation of a binary tree of letters:
  1. Empty trees are omitted completely.
  2. Each node is indicated by
    • Its letter data,
    • A line segment down to the left to the left subtree, if the left subtree is nonempty,
    • A line segment down to the right to the right subtree, if the right subtree is nonempty.

A leaf in a binary tree is a node whose subtrees are both empty. In the example in Figure 1, this would be the five nodes with data B, D, H, P, and Y.

The preorder traversal of a tree of letters satisfies the defining properties:
  1. If the tree is empty, then the preorder traversal is empty.
  2. If the tree is not empty, then the preorder traversal consists of the following, in order
    • The data from the root node,
    • The preorder traversal of the root's left subtree,
    • The preorder traversal of the root's right subtree.

The preorder traversal of the tree in Figure 1 is KGCBDHQMPY.

A tree like the one in Figure 1 is also a binary search tree of letters. A binary search tree of letters is a binary tree of letters in which each node satisfies:

The root's data comes later in the alphabet than all the data in the nodes in the left subtree.

The root's data comes earlier in the alphabet than all the data in the nodes in the right subtree.

The problem:

Consider the following sequence of operations on a binary search tree of letters

Remove the leaves and list the data removed
Repeat this procedure until the tree is empty
Starting from the tree below on the left, we produce the sequence of trees shown, and then the empty tree

by removing the leaves with data

BDHPY
CM
GQ
K

Your problem is to start with such a sequence of lines of leaves from a binary search tree of letters and output the preorder traversal of the tree.

相關推薦

Falling Leaves10.1.2)

Figure 1 Figure 1 shows a graphical representation of a binary tree of letters. People familiar with binary trees can skip over the definitions of a bin

Shell特殊位置變量$0,$1$2,$*,$#,$$,$?,$@,${}

shell$0 文件名及路徑$1,$2 參數1,參數2$# 傳遞給腳本或函數的參數個數$$ 當前Shell進程ID$? 判斷上個命令的執行成功與否,0為成功。$@ 傳遞腳本或函數的所有參數$* 傳遞腳本或函數的所有參數${}註:$@和$*都是傳遞腳本或函數的所有參數。

WinPcap 中文技術文件4.1.2 第三章

1.  WinPcap教程:循序漸進教您使用WinPcap 本節將向您顯示如何使用WinPcapAPI的一些特性。本教程被組織成一系列課程,以循序漸進的方式,讓讀者從最基本的部分(獲得裝置列表)到最複雜的部分(控制傳送佇列並收集和統計網路流量)來了解如何使用WinPcap進

CCF計算機軟體能力認證模擬試題參考答案JAVA201703 1+2

1.分蛋糕: 小明今天生日,他有n塊蛋糕要分給朋友們吃,這n塊蛋糕(編號為1到n)的重量分別為a1, a2, …, an。小明想分給每個朋友至少重量為k的蛋糕。小明的朋友們已經排好隊準備領蛋糕,對於每個朋友,小明總是先將自己手中編號最小的蛋糕分給他,當這個朋友所分得蛋

webstorm10.0.2的埠號修改

1.file ---> settings 2.build --> debugger --> built-in server port:你需要的埠號 -->apply --> ok 埠號修改完成。 其他 [我的部落格,歡迎交流!](

webstorm10.0.2設定測試伺服器 -- 區域網內其他裝置訪問

1、埠更改和允許外部:更改埠號“63342”為“8081”,並“√”可以接受外部連結,如下 2、在部署中增加一條規則 3、設定規則名稱和方式 4、設定檔案地址(前端頁面本地資料夾路徑)和訪問路徑(本機IP和80

Xcode7 運行iOS10以上系統10.110.210.3解決Could not find Developer Disk Image

ges 添加 -1 eve device images 真機 文件 eight 由於歷史原因,需要在Xcode7上真機運行下app,無奈手機系統已是10.3了,一運行, 就提示:Could not find Developer Disk Image 解決辦法: 1、找

HyperLedger Fabric 1.2 Solo模式簡介10.1

ive 高可用 測試環境 成功 nbsp 高可用性 連接 spa 進行 Solo模式指單節點通信模式,該環境中只有一個排序(orderer)服務,從節點(peer)發送來的消息由一個orderer進行排序和產生區塊;由於排序(orderer)服務只有一個ord

MyEclipse2015 stable 2.0 for mac破解系統版本為Mac OS X 10.10.1 Yosemite

之前開發java是在虛擬機器上安裝的myeclipse,但是使用虛擬機器感覺耗電快、發熱有點厲害,所以就想在mac上安裝myeclipse。 安裝成功後破解了很多次都沒成功,網上查了好久終於破解成功。現在跟大家分享下: 我用的myeclipse版本是2015 stabl

阿裏數加1-2api調用分析

-c demo spm 保留字 使用場景 sta 字段 3.2 app https://data.aliyun.com/product/nls?spm=5176.doc30437.2.1.UPDABu 下面以最常用的”一句話識別”服務給大家做一個入門級的示例,為您介紹如

Jetty入門1-2配置Jetty - 獨立運行模式

https monitored log www rtu mon 方式 新版本 demo 本文詳述如何安裝和配置Jetty服務器,主要講述Jetty的獨立運行模式(Standalone)。隨後介紹它的配置選項,以及模塊化的架構。 Jetty有獨立運行模式、嵌入運行模式和J

luogu cogs . [NOIP2003] 傳染病控制 WA1/2

getch 特定 start using def algo logs space blog ★★★ 輸入文件:epidemic.in 輸出文件:epidemic.out 簡單對比 時間限制:1 s 內存限制:128 MB 【問題背景】 近來,一種新的傳

免費SSL證書支持1.0、1.11.2

logs 免費 設置 重啟 cloud 下載 需要 微信小程序 .html 由於公司要開發微信小程序,而微信小程序的接口需要https協議的,並且要支持TLS1.0、TLS1.1、TLS1.2。如果僅僅是為了開發小程序,安全等級又不用太高,可以選擇免費的SSL證書 在這裏選

深入理解計算機系統1.2------存儲設備

高速 計算 想法 知識 1-1 運用 文件 字符 設備   上一章我們講解了hello world 程序在計算機系統中是如何運行的。 hello 程序的機器指令最初是存放在磁盤上的,當程序加載時,他們被復制到主存;當處理器運行程序的時候,指令又從主存復制到處理器。相似的,數

【Android】實用教程:匯入android-gif-drawable包,不用在GitHub下載Android Studio 3.1.2

轉載請註明出處,原文連結:https://blog.csdn.net/u013642500/article/details/80193877 【AS版本】 【步驟】 1、開啟Project Structural。(可點選圖示,也可以在File選單中開啟,也可以按Ctrl+Al

【Android】實用教程:匯入SlidingMenu包,不用在GitHub下載Android Studio 3.1.2

轉載請註明出處,原文連結:https://blog.csdn.net/u013642500/article/details/80192923 【AS版本】 【步驟】 1、開啟Project Structural。(可點選圖示,也可以在File選單中開啟,也可以按Ctrl+Al

Django2.1.2基礎

Django(2.1.2)基礎 Django(2.1.2) 1.Django介紹 2.為什麼使用Django? 3.使用Django開發要具備基礎知識 4.建立一個Django工程 4.1在Git中建立一個Dj

字典序問題演算法課本課後實現題1-2

題目描述:        在資料加密和資料壓縮中常需要對特殊的字串進行編碼.給定的字母表A由26個小寫英文字母組成,即A={a,b...z}.該字母表產生的升序字串是指定字串中字母從左到右出現的次序與字母在字母表中出現的次序相同,且每個字元最多出

Vijos1144 皇宮看守 0/1/2三種狀態的普通樹形Dp

題意: 給出一個樹以及一些覆蓋每個點的花費,求每個點都能被自己被覆蓋,或者相鄰的點被覆蓋的最小价值。 細節: 其實我乍一眼看過去還以為是 戰略遊戲 的複製版 可愛的戰略遊戲在這裡QAQ(請原諒這波廣告) 顯然這是一個巨坑,所以必須先來看一張神奇的圖片~ ~ ~ ~ ~ 帥氣的

1-2line-height的各類屬性值

                    (1-2)line-height的各類屬性值  首先來個疑問!沒有問題印象不深嘛 一、line-height支援哪些屬性值呢? 五隻手指頭就能數過來了咯。 比如normal, <number>, <length>,<percent&g