Struktur Data & Algoritme (Data Structures & Algorithms)

dokumen-dokumen yang mirip
IKI 20100: Struktur Data & Algoritma

Outline. Struktur Data & Algoritme (Data Structures & Algorithms) Pengantar. Definisi. 2-3 Trees

sistem basis data ti ti ukdw Indexing Materi Minggu ke-10 Teknik Informatika Universitas Kristen Duta Wacana Yogyakarta 04/07/13 budi susanto 1

Objectives. Struktur Data & Algoritme (Data Structures & Algorithms) Sort. Outline. Bubble Sort: idea. Bubble Sort. Sorting

Organisasi File Multi Key y( (Index)

Hal penting dalam menentukan keberhasilan sistem cerdas adalah kesuksesan dalam pencarian.

Struktur Data & Algoritme (Data Structures & Algorithms)

Struktur Data dan Algoritme. Struktur Data & Algoritme (Data Structures & Algorithms) Struktur Data dan Algoritme. Objectives.

Struktur Data & Algoritma

Review. Struktur Data & Algoritme (Data Structures & Algorithms) Objectives. Outline. Stacks & Queues

Struktur Data & Algoritma

Algoritma dan Struktur Data. Linear & Binary Search Tree

TREE ALGORITMA & STRUKTUR DATA. Materi ASD Fakultas Teknik Elektro & Komputer UKSW ( Download Dari :

Struktur Data & Algoritme (Data Structures & Algorithms)

Algoritma dan Struktur Data. Binary Tree & Binary Search Tree (BST)

Adam Mukharil Bachtiar English Class Informatics Engineering Algorithms and Programming Searching

Nama Soal Pembagian Ring Road Batas Waktu 1 detik Nama Berkas Ringroad[1..10].out Batas Memori 32 MB Tipe [output only] Sumber Brian Marshal

DIKTAT KULIAH ALGORITMA dan STRUKTUR DATA II

Virtual Memory Ch. 9. Virtual Memory. SISTIM OPERASI (Operating System) IKI Johny Moningka

Algoritma dan Struktur Data. Pertemuan 7 Linked List

Struktur Data & Algoritme (Data Structures & Algorithms)

Objectives. Struktur Data & Algoritme (Data Structures & Algorithms) Outline. Apa itu Recursion? Recursion

Algoritma Pemrograman & Struktur Data

ANALISIS ALGORITMA BINARY SEARCH

Algoritma Pencarian Blind. Breadth First Search Depth First Search

Sekumpulan field yang bergambung sebagai sebuah unit yang memiliki ukuran tertentu

Algoritma dan Struktur Data. Pertemuan 9 Circular Linked List

IKI 20100: Struktur Data & Algoritma

Algoritma dan Struktur Data. Click to edit Master subtitle style Konsep Tree

ABSTRAK. Kata Kunci : Map, TreeMap, AVL tree. vii Universitas Kristen Maranatha

Tujuan Instruksional

Tree (Struktur Data) Nisa ul Hafidhoh, MT

Syarif Abdullah (G )

Chapter 3 part 3. Internetworking (Routing) Muhammad Al Makky

STRUKTUR DATA. By : Sri Rezeki Candra Nursari 2 SKS

1/5. while and do Loops The remaining types of loops are while and do. As with for loops, while and do loops Praktikum Alpro Modul 3.

Pohon dan Pohon Biner

MODUL PRAKTIKUM STRUKTUR DATA

2. Mahasiswa dapat membuat dan menggunakan array dan linked list dalam suatu kasus.

SORTING (BAGIAN II) Proses kelima

ORGANISASI FILE. Alif Finandhita, S.Kom

File Organization. IKI20410 Basis Data Aniati Murni Fakultas Ilmu Komputer Universitas Indonesia

ADDING RTGS BENEFICIARY FOR CHECKER MAKER SYSTEM

Design and Analysis Algorithm. Ahmad Afif Supianto, S.Si., M.Kom. Pertemuan 08

DIG1G3 Implementasi Struktur Data

Algoritma dan Struktur Data. Pertemuan 8 Doubly Linked List

ABSTRAK. Universitas Kristen Maranatha

UJIAN AKHIR SEMESTER GANJIL 2005/2006 ALGORITMA & STRUKTUR DATA / CS2014

PRAKTIKUM STRUKTUR DATA QUEUE. SULIDAR FITRI, M.Sc

METODE AVL TREE UNTUK PENYEIMBANGAN TINGGI BINARY TREE

Minimum Spanning Trees algorithm

Studi Digital Tree dan Aplikasinya pada Kamus

BAB III ANALISIS DAN PERANCANGAN SISTEM

Organisasi Berkas Sekuensial Berindeks

JAWABAN TUGAS MATRIKULASI STRUKTUR DATA. DOSEN Bpk. Krisna Adiyarta, M.Sc

TIP 163. Game Engine. Topik 5 (Pert 6) Graf, Representasi Dunia, dan Algoritma Pencari Jalur (Pathfinding) Dosen: Aditya Wikan Mahastama

Struktur Data dan Algoritma

Pertemuan 8. Dasar query basis data dengan SQLite ARFIAN HIDAYAT, S.KOM

Connecting & Using the BGAN for Internet Access Menghubungkan dan Menggunakan Alat BGAN

STRUKTUR DATA. By : Sri Rezeki Candra Nursari 2 SKS

Soal Pendahuluan Modul 3

32-bit and 64-bit Windows: Frequently asked questions

13/12/2013. Binary Tree. Contoh Tree

Preorder Tree Traversal

Problem 1. Implementasi Interface. Diberikan definisi interface BentukDuaDimensi berikut:

Multidimensional Data Structures

Pertemuan 9 STRUKTUR POHON & KUNJUNGAN POHON BINER

BAB 3 ANALISA DAN PERENCANAAN

Organisasi Sequential. Rudi Susanto

BAB IX TREE (POHON) ISTILAH DASAR

EFISIENSI JUMLAH ARMADA BUS PATAS AC ANTAR BEBERAPA PERUSAHAAN BERDASARKAN METODE PERTUKARAN TRAYEK DI DKI JAKARTA TESIS

Pemodelan dan Pengelolaan Data Klasifikasi Tanaman Menggunakan Pohon

TUJUAN. Memahami Koneksi dan Pemrosesan Basis Data di Java Memahami JDBC Menggunakan MySQL pada program Java

Koleksi Hirarkis Tree

B-Tree dan Penerapan di Basis Data

03/04/2018. Collection set List Map. Pemrograman Berorientasi Object

Lab. Teknik Informatika Struktur Data 1

TUGAS BROWSING. Diajukan untuk memenuhi salah satu tugas Eksperimen Fisika Dasar 1. Di susun oleh : INDRI SARI UTAMI PEND. FISIKA / B EFD-1 / C

DIG1G3 Implementasi Struktur Data

SEKOLAH TINGGI MANAJEMEN INFORMATIKA & KOMPUTER JAKARTA STI&K SATUAN ACARA PERKULIAHAN

BAB XI Manipulasi Binary Tree

Data Structures. Class 4 Arrays. Pengampu : TATI ERLINA, M.I.T. Copyright 2006 by The McGraw-Hill Companies, Inc. All rights reserved.

ABSTRACT. Keyword: Algorithm, Depth First Search, Breadth First Search, backtracking, Maze, Rat Race, Web Peta. Universitas Kristen Maranatha

Addition of beneficiary for other currency than INR

Pengantar Teknologi Informasi. Komunikasi Data dan Jaringan Komputer

Basis Bilangan 2. Basis bilangan hanya ada dua nilai 0 dan 1

BINARY SEARCH TREE. TUJUAN UMUM Mahasiswa memahami binary search Tree

IMPLEMENTASI PERANGKAT LUNAK DENGAN PENERAPAN PENCARIAN RELATIF (HASH SEARCH)

ABSTRAK. Kata Kunci: antrian, layanan, model antrian. vi Universitas Kristen Maranatha

: Mahasiswa mampu menjelaskan teknik pemrograman menggunakan Linked List. Single Linked List

1-x. dimana dan dihubungkan oleh teorema Pythagoras.

Bab 4. Informed Search

SEARCHING & SORTING. Pendahuluan

Pemrograman Lanjut. Interface

Aplikasi dan Analisis Algoritma BFS dan DFS dalam Menemukan Solusi pada Kasus Water Jug

Lecture Notes On Algorithms and Data Structures. Oleh Thompson Susabda Ngoen

ANALISA PERFORMANSI PERTITIONING TABEL PADA RELATIONAL DATABASE MANAGEMENT SYSTEM

ABSTRAK. Kata Kunci: Game, Pengunduhan, Voucher, Super Admin, Admin, Moderator,Player

Transkripsi:

Struktur Data & Algoritme (Data Structures & Algorithms) B Trees Denny (denny@cs.ui.ac.id) Suryana Setiawan (setiawan@cs.ui.ac.id) Fakultas Ilmu Komputer Universitas Indonesia Semester Genap - 2004/2005 Version 2.0 - Internal Use Only Outline Motivation B-Tree B+Tree SDA/BTREE/V2.0/2 1

Motivation Perhatikan kasus berikut ini: Kamu harus membuat program basisdata untuk menyimpan data di yellow pages daerah Jakarta, misalnya ada 500.000 data. Setiap entry terdapat nama, alamat, nomor telepon, dll. Asumsi setiap entry disimpan dalam sebuah record yang besarnya 512 byte. Total file size = 500,000 * 512 byte = 256 MB. terlalu besar untuk disimpan dalam memory (primary storage) perlu disimpan di disk (secondary storage) Jika kita menggunakan disk untuk penyimpanan, kita harus menggunakan struktur blok pada disk untuk menyimpan basis data tsb. Secondary storage dibagi menjadi blok-blok yang ukurannya sama. Umumnya 512 byte, 2 KB, 4 KB, 8 KB. Block adalah satuan unit transfer antar disk dengan memory. Walaupun program hanya membaca 10 byte dari disk, 1 block akan dibaca dari disk dan disimpan ke memory. SDA/BTREE/V2.0/3 Motivation Misalnya 1 disk block 8.192 byte (8 KB) Maka jumlah blok yang diperlukan = 256 MB / 8 KB per block = 31,250 blocks. Setiap blok menyimpan = 8,192 / 512 = 16 records. A disk access is really expensive due to mechanical limitation. Disk access is approx. 10,000 times slower than main memory. One disk access is worth about 200,000 instructions. The number of disk accesses will dominate the running time. Goal: a multiway search tree that will minimize disk accesses. SDA/BTREE/V2.0/4 2

B-Tree B-tree adalah (a,b)-tree di mana b = 2a - 1. a dan b biasanya merupakan angka-angka yang cukup besar, misalnya a = 100 dan b = 199. B-tree banyak digunakan untuk external data structure. Setiap node berukuran sesuai dengan ukuran block pada disk, misalnya 1 block = 8 KB. Tujuannya: meminimalkan jumlah block transfer. SDA/BTREE/V2.0/5 B Trees The problem with Binary Trees is balance, the tree can easily deteriorate to a linked list. Consequently, the reduced search times are lost, this problem is overcome in B-Trees. B stands for Balanced, where all the leaves are the same distance from the root. B-Trees guarantee a predictable efficiency. There are several varieties of B-Trees, most applications use the B+Tree. SDA/BTREE/V2.0/6 3

B Tree B Tree of degree m has the following properties: All non-leaf nodes (except the root which is not bound by a lower limit) have between m/2 and m non-empty children. A non-leaf node that has n branches will contain n-1 keys. All leaves are at the same level, that is the same depth from the root. >= 1250 1291 0625 1000 1277 1282 1425 2000 SDA/BTREE/V2.0/7 B+Tree B+Tree adalah variant dari B-tree: semua key value disimpan dalam leaf. disertakan suatu pointer tambahan untuk menghubungkan setiap leaf node tersebut sebagai suatu linear linked-list. Struktur ini memungkinkan akses sikuensial data dalam B-tree tanpa harus turun-naik pada struktur hirarkisnya. node internal digunakan sebagai indeks. Beberapa key value dapat muncul dua kali di dalam tree. SDA/BTREE/V2.0/8 4

B+Tree Leaf Nodes 1250 >= 0625 1000 1425 2000 0350 0625 1000 1250 1300 1425 1600 2000 SDA/BTREE/V2.0/9 B+Tree Node Structure A high level node (internal node) P 1 K1 P 2 K2....... P n-1 K n-1 P n Pointer to Pointer to Pointer to subtree for subtree for subtree for keys K keys>= K 1& K 2 keys>= K & K n-1 A leaf node (Every key value appears in a leaf node) P K P K....... P K P 1 1 2 2 n-1 n-1 n Pointer to subtree for keys>= K 1 n-2 n-1 Pointer to record (block) Pointer to record (block) Pointer to record (block) Pointer to leaf with smallest key greater than with key K 1 with key K 2 with key K n-1 K n-1 SDA/BTREE/V2.0/10 5

Example of a B+Tree Leaf Nodes 1250 >= 0625 1000 1425 2000 0350 0625 1000 1250 1300 1425 1600 2000 0350 0625 1000 1250 1425 2000 1300 1600 Actual Data Records SDA/BTREE/V2.0/11 Queries on B+Trees Find all records with a search-key value of k. 1. Start with the root node 1. Examine the node for the smallest search-key value > k. 2. If such a value exists, assume it is K j. Then follow P i to the child node 3. Otherwise k K m 1, where there are m pointers in the node. Then follow P m to the child node. 2. If the node reached by following the pointer above is not a leaf node, repeat the above procedure on the node, and follow the corresponding pointer. 3. Eventually reach a leaf node. If for some i, key K i = k follow pointer P i to the desired record (or bucket). Else no record with search-key value k exists. SDA/BTREE/V2.0/12 6

Queries on B+Trees: Range Query Find all records with a search-key value > k and l (range query). Find all records with a search-key value of k. while the next search-key value l, follow the corresponding pointer to the records. when the current search-key is the last search-key in a node, follow the last pointer P n to the next leaf node. SDA/BTREE/V2.0/13 Insertion on B+Trees Find the leaf node in which the search-key value would appear If the search-key value is already there in the leaf node (non-unique seach-key), record is added to data file, and if necessary search-key and the corresponding pointer is inserted into the leaf node SDA/BTREE/V2.0/14 7

Insertion on B+Trees If the search-key value is not there, then add the record to the data file: If there is room in the leaf node, insert (key-value, pointer) pair in the leaf node (should be sorted) Otherwise, split the node (along with the new (key-value, pointer) entry) as shown in the next slides. Splitting a node: Take the new (search-key value, pointer) pairs (including the one being inserted) in sorted order. Place the first n/2 in the original node, and the rest in a new node. When splitting a leaf, promote the middle/median key in the parent of the node being split, but retain the copy in the leaf. When splitting an internal node, promote the middle/median key in the parent of the node being split, but DO NOT retain the copy in the leaf. If the parent is full, split it and propagate the split further up. SDA/BTREE/V2.0/15 Building a B+Tree 67, 123, 89, 18, 34, 87, 99, 104, 36, 55, 78, 9 67 89 123 split data records leaf node root node promote but retain a copy 18 67 89 123 The split at leaf nodes 18 67 89 >= 89 123 root node why promote 89, not 67? data records SDA/BTREE/V2.0/16 8

67, 123, 89, 18, 34, 87, 99, 104, 36, 55, 78, 9 89 18 34 67 >= 89 123 root node split 67 89 root node >= 18 34 67 87 89 123 SDA/BTREE/V2.0/17 67, 123, 89, 18, 34, 87, 99, 104, 36, 55, 78, 9 67 89 root node >= split 18 34 67 87 89 99 123 18 34 67 89 104 root node 89 99 104 123 67 87 SDA/BTREE/V2.0/18 9

67, 123, 89, 18, 34, 87, 99, 104, 36, 55, 78, 9 67 89 104 split double node split 18 34 36 split 67 87 The splitting of nodes proceeds upwards till a node that is not full is found. In the worst case the root node may be split increasing the height of the tree by 1. 89 99 104 123 promote and do not retain a copy 36 67 89 104 89 The split at non-leaf nodes 18 34 36 67 104 89 99 104 123 36 55 67 87 SDA/BTREE/V2.0/19 Observations about B+Trees The B+Tree contains a relatively small number of levels (logarithmic in the number of data), thus searches can be conducted efficiently. In processing a query, a path is traversed in the tree from the root to some leaf node. If there are K search-key values in the file, the path is no longer than log m/2 (K), where b is index blocking factor Q: Why log m/2, not just log m? SDA/BTREE/V2.0/20 10

Deletion on B+Trees Remove (search-key value, pointer) from the leaf node If the node has too few entries due to the removal (minimum requirement: m/2 children), and the entries in the node and a sibling fit into a single node, then Merge the two nodes into a single node Delete the pair (K i 1, P i ), where P i is the pointer to the deleted node, from its parent, recursively using the above procedure. SDA/BTREE/V2.0/21 Deletion on B+Trees Otherwise, if the node has too few entries due to the removal, and the entries in the node and a sibling does not fit into a single node, then Redistribute the pointers between the node and a sibling such that both have more than the minimum number of entries. Update the corresponding search-key value in the parent of the node. The node deletions may cascade upwards till a node which has n/2 or more pointers is found. SDA/BTREE/V2.0/22 11

Summary B Tree is mostly used as an external data structure for databases. B Tree of degree m has the following properties: All non-leaf nodes (except the root which is not bound by a lower limit) have between m/2 and m children. A non-leaf node that has n branches will contain n-1 keys. All leaves are at the same level, that is the same depth from the root. B+Tree is a variant from B Tree where all key values are stored in leaves SDA/BTREE/V2.0/23 Further Reading applet simulasi B+Tree http://www.cs.msstate.edu/~cs2314/global/btreeanimation/visual ization.html SDA/BTREE/V2.0/24 12

What s Next Priority Queue, Heap SDA/BTREE/V2.0/25 13