Red -BlackTrees Evaliata Br Sembiring.

Slides:



Advertisements
Presentasi serupa
INTRO (TO BPOS). What is BPOS? Apakah BPOS itu? •BPOS = (Microsoft) Business Productivity Online Suite (Service) •adalah sebuah layanan online Microsoft,
Advertisements

INTRO TO BPOS ( Coffey’s Project Portal). What is BPOS? Apakah BPOS itu? •BPOS = (Microsoft) Business Productivity Online Suite (Service) •adalah sebuah.
Pengujian Hipotesis untuk Satu dan Dua Varians Populasi
Mata Kuliah : ALGORITMA dan STRUKTUR DATA 1.
PERUBAHAN VS PERBAIKAN Center for Continuous Improvement, Today is better than yesterday, tomorrow is better than today
Program Keahlian I – SI By Antonius Rachmat C, S.Kom
Materi Analisa Perancangan System.
THE FINDING A PATTERN STRATEGY STRATEGI MENEMUKAN POLA Oleh Kelompok 3.
EKO NURSULISTIYO.  Perhatikan gambar 11 a, perahu dikenai oleh ombak dari arah kanan misalkan setiap 4 sekon dalam keadaan perahu diam. Dalam keadaan.
Chapter Nine The Conditional.
PERULANGANPERULANGAN. 2 Flow of Control Flow of Control refers to the order that the computer processes the statements in a program. –Sequentially; baris.
Slide 3-1 Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Revised by IB & SAM, Fasilkom UI, 2005 Exercises Apa saja komponen utama.
Prof. Busch - LSU1 Mathematical Preliminaries. Prof. Busch - LSU2 Mathematical Preliminaries Sets Functions Relations Graphs Proof Techniques.
Introduction to The Design & Analysis of Algorithms
IF-ITB/SAS/25Aug2003 IF7074 – Bagian Pertama Page 1 IF 7047 Kewirausahaan Teknologi Informasi Bagian Pertama: 1.1. Entrepreneurship, entrepreneur, dan.
PROSES PADA WINDOWS Pratikum SO. Introduksi Proses 1.Program yang sedang dalam keadaan dieksekusi. 2.Unit kerja terkecil yang secara individu memiliki.
1. Objek dalam kalimat aktif menjadi subjek dalam kalimat pasif
KIMIA ORGANIK II ELFI SUSANTI VH.
Review Operasi Matriks
Internal dan Eksternal Sorting
Bilqis1 Pertemuan bilqis2 Sequences and Summations Deret (urutan) dan Penjumlahan.
Risk Management.
VALUING COMMON STOCKS Expected return : the percentage yield that an investor forecasts from a specific investment over a set period of time. Sometimes.
Text 1 By: Siwi Ratri K / Titik Rahayu /
Implementing an REA Model in a Relational Database
Pendugaan Parameter part 2
MEMORY Bhakti Yudho Suprapto,MT. berfungsi untuk memuat program dan juga sebagai tempat untuk menampung hasil proses bersifat volatile yang berarti bahwa.
Basisdata Pertanian. After completing this lesson, you should be able to do the following Identify the available group functions Describe the use of group.
2nd MEETING Assignment 4A “Exploring Grids” Assignment 4 B “Redesign Grids” Create several alternatives grid sysytem using the provided elements: (min.
Slide 1 QUIS Langkah pertama caranya Buat di slide pertama judul Slide kedua soal Slide ketiga waktu habis Slide keempat jawaban yang benar Slide kelima.
LESSON 10: LET’S COOK LEARNING FOCUS USING “a little” USING “a few”
LOGO Manajemen Data Berdasarkan Komputer dengan Sistem Database.
TRAVERSING BINARY TREE
Linked List dan Double Linked List
Definisi VLAN Pemisahan jaringan secara logis yang dilakukan pada switch Pada tradisional switch, dalam satu switch menunjukkan satu segmentasi LAN.
Amortization & Depresiasi
Contentment Philippians 4: Contentment What does it mean to be content? What does it mean to be content? Are you a content person? Are you a content.
SMPN 2 DEMAK GRADE 7 SEMESTER 2
By : Fitroh Amaluddin & Galih Wasis W.
1. 2 Work is defined to be the product of the magnitude of the displacement times the component of the force parallel to the displacement W = F ║ d F.
Lecture 8 Set and Dictionary Sandy Ardianto & Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.
RED BLACK TREE INSERTION
Romans 1: Romans 1:16-17 New Living Translation (NLT) 16 For I am not ashamed of this Good News about Christ. It is the power of God at work, saving.
Via Octaria Malau Transfer (Internal Transfers) Transfer (Transfers Internal) Select the account from which funds are to be transferred FROM and then select.
Algoritma dan Struktur Data
PENJUMLAHAN GAYA TUJUAN PEMBELAJARAN:
Double Linked List. © 2005 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Double Linked List Sama seperti single linked list, double.
The intensive state of a PVT system containing N chemical species and  phases in equilibrium is characterized by the intensive variables, temperature.
TCP, THREE-WAY HANDSHAKE, WINDOW
ASSALAMU’ALAIKUM Wr.Wb I will be presenting on how to make ice cream (Assalamu'alaikum Wr.Wb Saya akan menyajikan tentang cara untuk membuat es krim) Name:M.
Retrosintetik dan Strategi Sintesis
Web Teknologi I (MKB511C) Minggu 12 Page 1 MINGGU 12 Web Teknologi I (MKB511C) Pokok Bahasan: – Text processing perl-compatible regular expression/PCRE.
Made by: Febri, Andrew, Erina, Leon, Luvin, Jordy
2. Introduction to Algorithm and Programming
Pertemuan 13 Graph + Tree jual [Valdo] Lunatik Chubby Stylus.
Menulis Kolom  Kolom adalah opini atau artikel. Tidak seperti editorial, kolom memiliki byline.  Kolom Biasanya ditulis reguler. Biasanya mingguan atau.
Red-Black Trees.
BAB 6 KOMBINATORIAL DAN PELUANG DISKRIT. KOMBINATORIAL (COMBINATORIC) : ADALAH CABANG MATEMATIKA YANG MEMPELAJARI PENGATURAN OBJEK- OBJEK. ADALAH CABANG.
Bina Nusantara Mata Kuliah: K0194-Pemodelan Matematika Terapan Tahun : 2008 Aplikasi Model Markov Pertemuan 22:
1 Pertemuan 15 Game Playing Matakuliah: T0264/Intelijensia Semu Tahun: Juli 2006 Versi: 2/1.
Binary Search Tree. Sebuah node di Binary Search Tree memiliki path yang unik dari root menurut aturan ordering – Sebuah Node, mempunyai subtree kiri.
Fondasi Pemrograman & Struktur Data
Teknik Informatika - Universitas Muhammadiyah Malang (UMM)
CSG3F3/ Desain dan Analisis Algoritma
Algorithms and Programming Searching
Master data Management
Fix problems opening Norton  Fix problems opening Norton This problem can happen after you update Norton. To fix the matter, restart the computer. Fix.
If you are an user, then you know how spam affects your account. In this article, we tell you how you can control spam’s in your ZOHO.
Splay Trees.
Lecture 8 Normal model.
Transcript presentasi:

Red -BlackTrees Evaliata Br Sembiring

Red Black Trees (RBT) RBT : pohon pencarian biner (a binary search tree) dengan beberapa fitur spesial. Pokok Bahasan: ● How unbalanced trees degrade performance ● The characteristics of red-black trees ● The color rules ● How to use the RBTree Workshop applet (no) ● How to rotate a subtree

Overview A red-black tree is a binary search tree with some special features. Ordinary binary search trees, which we explored in Hours 15, “Binary Trees” and 16, “Traversing Binary Trees,” have an unfortunate defect: If data is inserted in a non-random sequence, the tree might become unbalanced, seriously degrading its performance. A red-black tree can fix this by ensuring that the tree remains balanced at all times. In this hour we’ll learn: ● How unbalanced trees degrade performance ● The characteristics of red-black trees ● The color rules ● How to use the RBTree Workshop applet (not) ● How to rotate a subtree In the next hour we’ll see how to use these techniques to insert a new node into a tree while keeping the tree balanced.

“Binary Trees” - “Traversing Binary Trees If data is inserted in a non-random sequence, the tree might become unbalanced. Ketika binary search tree menyimpan data yang sudah terurut (ascending/descending), kemudian dilakukan insert data maka kemungkinan tree menjadi tidak seimbang Alasan: setiap item baru lebih besar nilainya daripada yang terakhir, akan dihubungkan ke subtree kanan dari setiap item sebelumnya atau sebaliknya

How unbalanced trees degrade performance The nodes arrange themselves in a line with no branches. Because each node is larger than the previously inserted one, every node is a right child, so all the nodes are on one side of the root. The tree is maximally unbalanced. If you inserted items in descending order, every node would be the left child of its parent; the tree would be unbalanced on the other side. item inserted in ascending order

Red Black Trees (RBT) RBT adalah BST (binary search tree) dimana tiap node memiliki atribut warna yang bernilai merah atau hitam.

Red-Black Tree Characteristics The nodes are colored. During insertion and deletion, rules are followed that preserve various arrangements of these colors.

Colored Nodes In a red-black tree, every node is either black or red. These are arbitrary colors; blue and yellow would do just as well. In fact, the whole concept of saying that nodes have “colors” is somewhat arbitrary. Some other analogy could have been used instead: We could say that every node is either heavy or light, or yin or yang. However, colors are convenient labels.

Red-Black Rules Every node is either red or black. The root is always black. If a node is red, its children must be black (although the converse isn’t necessarily true). Every path from the root to a leaf, or to a null child, must contain the same number of black nodes.

Red-Black Rules Setiap node berwarna merah atau hitam Root selalu berwarna hitam Node yang berwarna merah tidak dapat memiliki anak yang juga berwarna merah. Jika sebuah node berwarna merah dan warna yang hanya mungkin untuk node berikutnya adalah hitam. Jumlah node hitam bersama setiap jalur di red-black tree harus sama, karena parent hitam dan children merah adalah bagian dari node logis yang sama, node merah tidak dihitung sepanjang jalan. (Setiap path dari node yang menuju ke nil harus mengandung nilai yang sama dengan node yang berwarna hitam.) Semua algoritma yang menjaga keseimbangan dalam red-black tree tidak boleh melanggar aturan ini. Ketika semua aturan berlaku, tree tersebut merupakan red-black tree yang valid, dan tinggi tree tersebut tidak dapat lebih pendek dari log (N + 1) tetapi juga tidak lebih tinggi dari 2 * log (N + 1).

Contoh : Insert New Nodes Memberikan root node dengan nilai 50 Tambah node baru yang lebih kecil dari root (50), misal 25 Tambah node kedua dengan nilai yang lebih besar dari root (50), misal 75 50 25 75

Contoh : Rotations Rotasi ada 2 : Rotasi kanan dan Rotasi Kiri. Dimulai dengan 3 node pada contoh sebelumnya

Contoh : Perform a Color Flip Mulai dengan contoh sebelumnya (1) Menambah node baru dengan nilai 12 Posisi root tetap berwarna merah Kedua child dari root diganti dari merah menjadi hitam. Catatan: Rule2 (root selalu berwarna hitam)  sehingga RBT masih benar. Karena : tidak ada sebuah parent dan child berwarna merah, dan semua path memiliki jumlah node berwarna hitam yang sama(2).

Contoh : Create an Unbalanced Tree Menambah node baru dengan nilai 6 Parent and child adalah merah, (pelanggaran Rule3) Rule3 : node red child black maka node 6 black. Bagaimana membuatnya seimbang? The good news is we fixed the problem of both parent and child being red. The bad news is that now the message says Error: Black heights differ. The path from the root to node 6 has three black nodes in it, while the path from the root to node 75 has only two. Thus Rule 4 is violated.

Path to a Null Child “black height is the number of black nodes from a given node to the root” the black height of the root (50) is 1 from the root to 25 is still 1 from the root to 12 is 2, and so on.

Duplicate Keys What happens if there’s more than one data item with the same key? This presents a slight problem in red-black trees. It’s important that nodes with the same key are distributed on both sides of other nodes with the same key. That is, if keys arrive in the order 50, 50, 50, you want the second 50 to go to the right of the first one, and the third 50 to go to the left of the first one. Otherwise, the tree becomes unbalanced. This could be handled by some kind of randomizing process in the insertion algorithm. However, the search process then becomes more complicated if all items with the same key must be found. It’s simpler to outlaw items with the same key. In this discussion we’ll assume duplicates aren’t allowed.

The Actions ● You can change the colors of nodes. What actions can you take if one of the red-black rules is broken? There are two, and only two, possibilities: ● You can change the colors of nodes. ● You can perform rotations. Changing the color of a node means changing its red-black border color (not the center color). A rotation is a rearrangement of the nodes that hopefully leaves the tree more balanced.

Rotation What’s Rotating? The term rotation can be a little misleading. The nodes themselves aren’t rotated, it’s the relationship between them that changes. One node is chosen as the “top” of the rotation. If we’re doing a right rotation, this “top” node will move down and to the right, into the position of its right child. Its left child will move up to take its place. Remember that the top node isn’t the “center” of the rotation. If we talk about a car tire, the top node doesn’t correspond to the hubcap, it’s more like the topmost part of the tire tread. ======================================================== Summary rotation: In a rotation, one node is designated the top node. ● A right rotation moves the top node into the position of its right child, and the top node’s left child into its position. ● A left rotation moves the top node into the position of its left child, and the top node’s right child into its position.

Rotation

Next : Insert RBT