アルゴリズムの設計と解析 (W4022) 教授 : 黄潤和 広野史明 (A4/A8)

Similar documents
今日の予定 1. 展開図の基礎的な知識 1. 正多面体の共通の展開図. 2. 複数の箱が折れる共通の展開図 :2 時間目 3. Rep-Cube: 最新の話題 4. 正多面体に近い立体と正 4 面体の共通の展開図 5. ペタル型の紙で折るピラミッド型 :2 時間目 ~3 時間目

フラクタル 1 ( ジュリア集合 ) 解説 : ジュリア集合 ( 自己平方フラクタル ) 入力パラメータの例 ( 小さな数値の変化で模様が大きく変化します. Ar や Ai の数値を少しずつ変化させて描画する. ) プログラムコード. 2010, AGU, M.

Unofficial Redmine Cooking - QA #782 yaml_db を使った DB のマイグレーションで失敗する

A. 展開図とそこから折れる凸立体の研究 1. 複数の箱が折れる共通の展開図 2 通りの箱が折れる共通の展開図 3 通りの箱が折れる共通の展開図そして. 残された未解決問題たち 2. 正多面体の共通の展開図 3. 正多面体に近い立体と正 4 面体の共通の展開図 ( 予備 )

Androidプログラミング 2 回目 迫紀徳

Computer Programming I (Advanced)

(2,4) Trees Goodrich, Tamassia (2,4) Trees 1

Lecture 4 Branch & cut algorithm

Cloud Connector 徹底解説. 多様な基盤への展開を可能にするための Citrix Cloud のキーコンポーネント A-5 セールスエンジニアリング本部パートナー SE 部リードシステムズエンジニア. 哲司 (Satoshi Komiyama) Citrix

(2,4) Trees. 2/22/2006 (2,4) Trees 1

J の Lab システムの舞台裏 - パワーポイントはいらない -

携帯電話の 吸収率 (SAR) について / Specific Absorption Rate (SAR) of Mobile Phones

WD/CD/DIS/FDIS stage

携帯電話の 吸収率 (SAR) について / Specific Absorption Rate (SAR) of Mobile Phones

JASCO-HPLC Operating Manual. (Analytical HPLC)

MySQL Cluster 7.3 リリース記念!! 5 分で作る MySQL Cluster 環境

Centralized (Indirect) switching networks. Computer Architecture AMANO, Hideharu

Online Meetings with Zoom

Methods to Detect Malicious MS Document File using File Structure Inspection

Quick Install Guide. Adaptec SCSI RAID 2120S Controller

Chapter 1 Videos Lesson 61 Thrillers are scary ~Reading~

Peering 101. August 2017 TPF. Walt Wollny, Director Interconnection Strategy Hurricane Electric AS6939

Zabbix ログ解析方法. 2018/2/14 サイバートラスト株式会社 Linux/OSS 事業部技術統括部花島タケシ. Copyright Cybertrust Japan Co., Ltd. All rights reserved.

Introduction to Information and Communication Technology (a)

サーブレットと Android との連携. Generated by Foxit PDF Creator Foxit Software For evaluation only.

4. 今回のプログラム 4.2 解決のクラス SearchNumber.java

Relaxed Consistency models and software distributed memory. Computer Architecture Textbook pp.79-83

Interdomain Routing Security Workshop 21 BGP, 4 Bytes AS. Brocade Communications Systems, K.K.

Saki is a Japanese high school student who/ has just started to study/ in the US.//

Preparing Information Design-Oriented. Posters. easy to. easy to. See! Understand! easy to. Convey!

Yamaha Steinberg USB Driver V for Mac Release Notes

API サーバの URL. <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE COMPLIANCE_SCAN SYSTEM "

サンプル. NI TestStand TM I: Introduction Course Manual

DürrConnect the clever connection. The quick connection with the Click

BraindumpQuiz. Best exam materials provider - BraindumpQuiz! Choosing us, Benefit more!

Googleの強みは ささえるのは世界一のインフラ. Google File System 2008年度後期 情報システム構成論2 第10回 クラウドと協調フィルタリング. 初期(1999年)の Googleクラスタ. 最近のデータセンタ Google Chrome Comicより

2007/10/17 ソフトウェア基礎課題布広. /** * SOFT * AppletTest01.java * 文字表示 */

Modern editor-independent development environment for PHP

マルチビットアップセット耐性及びシングルビットアップセット耐性を備えた

2. 集団の注目位置推定 提案手法では 複数の人物が同一の対象を注視している状況 置 を推定する手法を検討する この状況下では 図 1 のよう. 顔画像からそれぞれの注目位置を推定する ただし f は 1 枚 この仮説に基づいて 複数の人物を同時に撮影した低解像度顔

Snoop cache. AMANO, Hideharu, Keio University Textbook pp.40-60

暗い Lena トーンマッピング とは? 明るい Lena. 元の Lena. tone mapped. image. original. image. tone mapped. tone mapped image. image. original image. original.

Agilent. IO Libraries Suite 16.3/16.2 簡易取扱説明書. [ IO Libraries Suite 最新版 ]

Studies of Large-Scale Data Visualization: EXTRAWING and Visual Data Mining

Infragistics ASP.NET リリースノート

Dream the sky. Make it yours.

Lecture 11: Multiway and (2,4) Trees. Courtesy to Goodrich, Tamassia and Olga Veksler

PRODUCT DESCRIPTIONS AND METRICS

振込依頼書記入要領 Entry Guide for Direct Deposit Request Form

BABr11.5 for Linux のインストール 2007/12/21. You are running Linux on Kernel smp. Analyzing the environment

Certificate of Accreditation

Quick Installation Manual

アルゴリズムの設計と解析 (W4022) 教授 : 黄潤和 広野史明 (A4/A10)

Multi-way Search Trees. (Multi-way Search Trees) Data Structures and Programming Spring / 25

本書について... 7 本文中の表記について... 7 マークについて... 7 MTCE をインストールする前に... 7 ご注意... 7 推奨 PC 仕様... 8 MTCE をインストールする... 9 MTCE をアンインストールする... 11

Yamaha Steinberg USB Driver V for Windows Release Notes

UML. A Model Trasformation Environment for Embedded Control Software Design with Simulink Models and UML Models

UB-U01III/U02III/U03II User s Manual

JR SHIKOKU_Wi Fi Connection Guide

Web Billing User Guide

楽天株式会社楽天技術研究所 Autumn The Seasar Foundation and the others all rights reserved.

PSLT Adobe Typekit Service (2016v1.1)

Book Template. GGerry.

電脳梁山泊烏賊塾 構造体のサイズ. Visual Basic

Certificate of Accreditation

Synchronization with shared memory. AMANO, Hideharu Textbook pp.60-68

MathWorks Products and Prices Japan September 2016

Search Trees - 1 Venkatanatha Sarma Y

Rechargeable LED Work Light

Codegate 2014 オンライン予選 Write Up Chrono (Logical) 300

Kazunari Okada( 岡田一成 ) Sr. Technical Marketing Manager ISO Vibration Analyst (CAT II) National Instruments Corporation Japan

PCIe SSD PACC EP P3700 Intel Solid-State Drive Data Center Tool

グラフを表すデータ構造 JAVA での実装

Yamaha Steinberg USB Driver V for Windows Release Notes

TOOLS for MR V1.7.7 for Mac Release Notes

IRS16: 4 byte ASN. Version: 1.0 Date: April 22, 2008 Cisco Systems 2008 Cisco, Inc. All rights reserved. Cisco Systems Japan

高速鉄道に関する日本国政府とインド共和国政府との間の協力覚書 日本国政府及びインド共和国政府 ( 以下 両者 という ) は ムンバイ アーメダバード間高速鉄道路線 (MAHSR) に関する共同調査の 成功裡の完了に留意し MAHSR の整備に協力することについて 次のとおり確認した

Instantaneous/Accumulated Flowsensor NW, OF-W Handling Manual compliance

A note on quaternion, applied to attitude estimation Minoru HIGASHIGUCHI 四元数について衛星姿勢の逐次推定への応用例

MetaSMIL : A Description Language for Dynamic Integration of Multimedia Content

Video Annotation and Retrieval Using Vague Shot Intervals

INFRAGISTICS WPF 13.2 サービスリリースノート 2014 年 12 月

Effects of Aging and Visual Acuity on the Legible Point Size for a Single Character on an E-paper Display 電子ペーパーディスプレイの単一文字の読み取れるポイントサイズに対する加齢と視力の影響

Vehicle Calibration Techniques Established and Substantiated for Motorcycles

2-3 Tree. Outline B-TREE. catch(...){ printf( "Assignment::SolveProblem() AAAA!"); } ADD SLIDES ON DISJOINT SETS

Operational Precaution

TestsDumps. Latest Test Dumps for IT Exam Certification

ご注意. (4) 運用した結果の影響につきましては (4) の項に関わらず責任を負いかねますのでご了承ください (5) Autodesk Device Interface(ADI) および Heidi Device Interface(HDI) ドライバは 周辺機器メーカーに対応しています

さまざまなニーズにお応えできるラインナップ!

L3 SSG/SSD を使用している PPPoA クライアントで PC を設定すること

~ ソフトウエア認証への取り組みと課題 ~

URL IO オブジェクト指向プログラミング特論 2018 年度只木進一 : 工学系研究科

此処 夏? プログラムの概要 VB マウストレーニングソフト 此処 夏? で有る 無人島に取り残された女の子を マウスでドラッグして浅瀬を通り 椰子の島に導いて行く 一般的に 実用プログラムに比較するとゲームプログラムは 高度なテクニックを要求される事が多い

DSK8AD1DA. 8ch A/D & 1ch D/A for DSK/EVM.

MITSUBISHI Mitsubishi Industrial Robot

Verify99. Axis Systems

SteelEye Protection Suite for Linux

Unified System Management Technology for Data Centres

びんぼうでいいの による LCD シールド aitendo UL024TF のオシロスコープモード試験

Private Sub 終了 XToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 終了 XToolStripMenuItem.

Transcription:

アルゴリズムの設計と解析 教授 : 黄潤和 SA: (W4022) rhuang@hosei.ac.jp 広野史明 (A4/A8) fumiaki.hirono.5k@stu.hosei.ac.jp

Contents (L6 Search trees) Searching problems AVL tree 2-3-4 trees Insertion (review) Deletion 2

3

Insertion in 2-3-4 trees 1. 挿入するノードを見つける 挿入する値より小さい値は左側 大きい値は右側に位置するような葉ノードを見つける 2. 挿入の準備をする 2 ノードもしくは木全体でアイテムがなければなにもしない 3 ノードならば 親ノードのアイテムが 2 つ以下ならばなにもしない 親ノードのアイテムが 3 つならば挿入前に親ノードの分裂を行なう 4 ノードならば挿入前に分裂を行なう 3. 挿入する 分裂 根ノードであれば 真ん中の値を新たに根ノードとし 残りの 2 つの値はそれぞれその子ノードとなる 根ノードでなければ 真ん中の値を親ノードに移動し 残りの 2 つの値はそれぞれその親ノードの子ノードとなる 4

2-3-4 tree demo http://www.cs.unm.edu/~rlpm/499/ttft.html 2-3-4-tree.jar de-jar http://www.unf.edu/~broggio/cop3540/chap10/tree234app.java 5

Compare the Python code with the Java code 6

Splitting 4-nodes pitemc In parent level pitemb

2-3-4 Tree implementation in Java For the complete source code, please see the above file. You can refer to the web link below as well. http://www.unf.edu/~broggio/cop3540/chap10/tree234app.java 17/5/14 12 時 15 分 8

Objects of this Class Represent Data Items Actually Stored. // tree234.java import java.io.*; //////////////////////////////////////////////////////////////// class DataItem { public int ddata; // one data item //-------------------------------------------------------------- public DataItem(int dd) // constructor { ddata = dd; } //-------------------------------------------------------------- public void displayitem() // display item, format "/27" { System.out.print("/"+dData); } //-------------------------------------------------------------- } // end class DataItem This is merely A data item stored at the nodes. In practice, this might be an entire record or object. Here we are only showing the key. 9

class Node { private static final int ORDER = 4; private intnumitems; 4 private Node parent; 3 private Node childarray[] = new Node[ORDER]; private DataItem itemarray[] = new DataItem[ORDER-1]; // ------------------------------------------------------------- public void connectchild(int childnum, Node child) {// connect child to this node childarray[childnum] = child; if(child!= null) child.parent = this; } // ------------------------------------------------------------- public Node disconnectchild(int childnum) {// disconnect child from this node, return it Node tempnode = childarray[childnum]; childarray[childnum] = null; return tempnode; } // ------------------------------------------------------------- public Node getchild(int childnum) { return childarray[childnum]; } // ------------------------------------------------------------- public Node getparent() { return parent; } // ------------------------------------------------------------- public boolean isleaf() { return (childarray[0]==null)? true : false; } // ------------------------------------------------------------- public int getnumitems() { return numitems; } Note: two arrays: a child array and an item array. Note their size: nodes = 4; item = 3. The child array is size 4: the links: maximum children. The second array, itemarray is of size 3 the maximum number of data items in a node. Ordered too. One of three slides of code for class Node For a given node, note we store the number of items Also, the node s parent is an attribute in the class. Major work done by finditem(), insertitem() and removeitem() (next slides) for a given node. These are complex routines and NOT to be confused with find() and insert() for the Tree234 class itself. Recall: references are automatically initialized to null and numbers to 0 when their object is created. So, Node doesn t need a Constructor. 10

Class Node (continued) Find routine: Looking for the data within the node where we are located. Delete Routine Saves the deleted item. Sets the location contents to null. Decrements the number of items at the node. Returns the deleted data item. public DataItem getitem(int index) // get DataItem at index { return itemarray[index]; } // ------------------------------------------------------------- public boolean isfull() { return (numitems==order-1)? true : false; } // ------------------------------------------------------------- public int finditem(int key) // return index of { // item (within node) for(int j=0; j<order-1; j++) // if found, { // otherwise, if(itemarray[j] == null) // return -1 break; else if(itemarray[j].ddata == key) return j; } return -1; } // end finditem // ------------------------------------------------------------- public DataItem removeitem() { // removes largest item // assumes node not empty DataItem temp = itemarray[numitems-1]; // save item itemarray[numitems-1] = null; // disconnect it numitems--; // one less item return temp; // return item } // ------------------------------------------------------------- public void displaynode() { // format "/24/56/74/" for(int j=0; j<numitems; j++) itemarray[j].displayitem(); // "/56" System.out.println("/"); // final "/" } } // end class Node 11

Class Node (continued) Insert Routine Increments number of items in node. Get key of new item. Now loop. Go through code and my comments. Start looking for place to insert the data item. Start on the right and proceed left looking for proper place. // ------------------------------------------------------------- public int insertitem(dataitem newitem) { // assumes node is not full numitems++; // will add new item int newkey = newitem.ddata; // key of new item for(int j=order-2; j>=0; j--) // start on right to examine data { if(itemarray[j] == null) // if item null, go left one cell. continue; else { // if not null, get its key int itskey = itemarray[j].ddata; if(newkey < itskey) // if it's bigger itemarray[j+1] = itemarray[j]; // shift existing key right else { // otherwise, insert new item and return index.+1 itemarray[j+1] = newitem; return j+1; } } // end else (not null) } // end for // shifted all items, itemarray[0] = newitem; return 0; } // end insertitem() // insert new item 12

17/5/14 12 時 59 分 13

17/5/14 13 時 2 分 14

15

Analysis of Insertion 挿入の分析 Algorithm insertitem(k, o) 1. We search for key k to locate the insertion node v 2. We add the new item (k, o) at node v 3. while overflow(v) if isroot(v) create a new empty root above v v split(v) Let T be a (2,4) tree with n items n 個の値を持つ 2-4 木 T で考察 Tree T has O(log n) height Step 1 takes O(log n) time because we visit O(log n) nodes Step 2 takes O(1) time Step 3 takes O(log n) time because each split takes O(1) time and we perform O(log n) splits Thus, an insertion in a (2,4) tree takes O(log n) time 16

(2,4) tree Deletion Algorithm 17/5/14 12 時 15 分 17

(2,4) tree Deletion Algorithm Deleting item I: remember 1. Locate node n, which contains item I 2. If node n is not a leaf swap I with inorder successor deletion always begins at a leaf deletion always begins at a leaf 3. If leaf node n contains another item, just delete item I else

2-3-4 Tree: Deletion Explain the deletion procedure from examples items are deleted at the leafs swap item of internal node with inorder successor Case: 10. sibling nodes are 2-node merge to right Delete, then handle problem result

2-3-4 Tree: Deletion Deletion procedure: items are deleted at the leafs swap item of internal node with inorder successor merge 60,70,80 90 pull down 70 result 60 70 80 100 Prevent problem, then delete

2-3-4 Tree: Deletion (underflow problem and solution) Note: a 2-node leaf creates a problem (1-node, underflow ) Solution: on the way from the root down to the leaf - turn 2-nodes (except root) into 3-nodes Case 1: an adjacent sibling has 2 or 3 items solution "steal" item from sibling by rotating items and moving subtree

2-3-4 Tree: Deletion (underflow problem and solution) Turning two 2-node into a 4-node... Case 2: each adjacent sibling has only one item "steal" item from parent and merge node with sibling (note: parent has at least two items, unless it is the root) two 2-node a 4-node

Deletion - more examples Example: to delete key 24, we replace it with 27 (inorder successor) 10 15 24 2 8 12 18 27 32 35 Swap and delete? 23

Deletion - more examples Example: to delete key 18, 10 15 27 2 8 12 18 32 35 rotation and delete? 24

Deletion - more examples Example: to delete key 27, 10 15 32 merge 2 8 12 27 35? merge and delete 25

Deletion - more examples the adjacent siblings of v are 2-nodes merge v with an adjacent sibling w and move an item from u to the merged node v' After merging, the underflow may propagate to the parent u u 9 14 w 2 5 7 10 v Delete and merge u 2 5 7 9 10 14 v' 26

Deletion - more example an adjacent sibling w of v is a 3-node or a 4-node Transfer operation: 1. we move a child of w to v 2. we move an item from u to v 3. we move an item from w to u After a transfer, no underflow occurs u 4 9 w v 2 6 8 12 2. 3. rotation and delete u 4 8 w v 2 6 9 12 Delete 12 1. 27

Deletion - more example an adjacent sibling w of v is a 3-node or a 4-node Transfer operation: 1. we move a child of w to v 2. we move an item from u to v 3. we move an item from w to u After a transfer, no underflow occurs 2 u 4 9 w 6 8 v 2. 3. delete and rotation u 4 8 w v 2 6 9 1. 28

Analysis of Deletion 削除の分析 Let T be a (2,4) tree with n items Tree T has O(log n) height 木 T の高さは O(log n) In a deletion operation We visit O(log n) nodes to locate the node from which to delete the item 削除するために O(log n) のノードを訪れる We handle an underflow with a series of O(log n) fusions, followed by at most one transfer Each fusion and transfer takes O(1) time 合体と移動 : O(1) Thus, deleting an item from a (2,4) tree takes O(log n) time (2,4) 木での削除の時間 : O(log n) 17/5/14 12 時 15 分 (2,4) Trees 29

2-3-4 Tree: Deletion Practice Work in class Delete 32, 35, 40, 38, 39, 37, 60

2-3-4 Tree: Deletion Practice (solution) Delete 32, 35, 40, 38, 39, 37, 60 result

2-3-4-Tree.jar 17/5/14 14 時 44 分 32

Work in class Insertion of 75, 5, 70, 10, 65, 15, 60, 20, 55, 25, 50, 30, 45, 35, 40, 80 33

解答例 : Insertion of 75, 5, 70, 10, 65, 15, 60, 20, 55, 25, 50, 30, 45, 35, 40, 80 10 65 15 60 20 55 25 50 30 45 35 40 80 34

例 1:Deletion From the root down to the leaf 1. find the node in which item I is in and then check the following cases 2. if (the node is leaf) 3. delete 4. if (the node is not leaf) 5. swap 6. if (the root and two children are 2-nodes) 7. merge1 8. if (sibling node has 2 or 3 items) 9. right/left rotate 10. if (sibling nodes are 2-nodes) 11. merge2 5. swap: swap item of internal node with inorder successor 7. merge 1 combine all three elements into the root. 9. right/left rotate: parent item to the right/left child and the left/right child to its parent 11. merge2 combine all three elements as a child node. 99 90 15 3. delete: 99 is in the lead node 7.merge1 and delete: a 2-node (50, 30, 70) 80 70 40 50 9. right rotate and delete a 2-node (20, 30, 40) 11.merge2 and delete a 2-node (50, 30, 60) 20 10 30 60 merge and delete: a 2-node (30, 10, 60) 35

例 2:Delete 70, 30, 35, 10, 75, 80, 40,45-70 -30-35 (50,60,70) 9.right rotate (70.75) 5.swap (70) delete (30,50,60) 9.left rotate (30.35) 5.swap (30) delete (35.40) 5.swap (35) delete -10-75 (10,20,40) 9.left rotate (5,10.15) 11.merge2 (10) delete (60,50,75) 11.merge2 (65,75,80) 11.merge2 (75) delete Work in class: delete 80, 40, 45 36

Exercise 6-1 Consider the following sequence of keys: (4, 12, 13, 14). Remove the items with this set of keys in the order given from the (2,4) tree below. Draw the tree after each removal. 12 キー配列について考える : (4, 12, 13, 14) このキーのセットを図の (2,4) 木に削除しなさい 5,10 15 それぞれの削除後の (2,4) 木を描きなさい 4 6, 8 11 13,14 17 37

Exercise 6-2 (optional) Please implement the 2-3-4 Tree deletion algorithm in python. 38

References https://www.unf.edu/~broggio/ 17/5/14 12 時 30 分 39