Data Structure Lecture#15: Non-Binary Trees 2 (Chapter 6) U Kang Seoul National University

Similar documents
Module 4: Index Structures Lecture 13: Index structure. The Lecture Contains: Index structure. Binary search tree (BST) B-tree. B+-tree.

Data Structure Lecture#14: Non-Binary Trees (Chapter 6) U Kang Seoul National University

Data Structure Lecture#10: Binary Trees (Chapter 5) U Kang Seoul National University

Extra: B+ Trees. Motivations. Differences between BST and B+ 10/27/2017. CS1: Java Programming Colorado State University

Chapter 20: Binary Trees

CS127: B-Trees. B-Trees

CSE 530A. B+ Trees. Washington University Fall 2013

CE 221 Data Structures and Algorithms

Cpt S 122 Data Structures. Data Structures Trees

Binary Trees

Why Do We Need Trees?

Trees. CSE 373 Data Structures

INF2220: algorithms and data structures Series 1

Data Structure Chapter 6

Binary Trees, Binary Search Trees

Physical Level of Databases: B+-Trees

Binary Trees. Examples:

Programming II (CS300)

CSI33 Data Structures

An AVL tree with N nodes is an excellent data. The Big-Oh analysis shows that most operations finish within O(log N) time

INF2220: algorithms and data structures Series 1

Trees. Introduction & Terminology. February 05, 2018 Cinda Heeren / Geoffrey Tien 1

Garbage Collection: recycling unused memory

Background: disk access vs. main memory access (1/2)

amiri advanced databases '05

Todays Lecture. Assignment 2 deadline: You have 5 Calendar days to complete.

Section 5.5. Left subtree The left subtree of a vertex V on a binary tree is the graph formed by the left child L of V, the descendents

CSIT5300: Advanced Database Systems

BST Implementation. Data Structures. Lecture 4 Binary search trees (BST) Dr. Mahmoud Attia Sakr University of Ain Shams

Introduction to Linked List: Review. Source:

Chapter 13: Indexing. Chapter 13. ? value. Topics. Indexing & Hashing. value. Conventional indexes B-trees Hashing schemes (self-study) record

Trees. (Trees) Data Structures and Programming Spring / 28

Trees. Reading: Weiss, Chapter 4. Cpt S 223, Fall 2007 Copyright: Washington State University

» Access elements of a container sequentially without exposing the underlying representation

THE B+ TREE INDEX. CS 564- Spring ACKs: Jignesh Patel, AnHai Doan

Trees. Eric McCreath

Associate Professor Dr. Raed Ibraheem Hamed

CSC 553 Operating Systems

Intro to DB CHAPTER 12 INDEXING & HASHING

Trees. Q: Why study trees? A: Many advance ADTs are implemented using tree-based data structures.

Last Class Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

Trees. Truong Tuan Anh CSE-HCMUT

Comp 335 File Structures. B - Trees

B-Trees & its Variants

Chapter 4 Trees. Theorem A graph G has a spanning tree if and only if G is connected.

Lecture 37 Section 9.4. Wed, Apr 22, 2009

TREES. Trees - Introduction

Data Structures. Trees. By Dr. Mohammad Ali H. Eljinini. M.A. Eljinini, PhD

Trees. Trees. CSE 2011 Winter 2007

10/23/12. Outline. Part 6. Trees (3) Example: A B-tree of degree 5. B-tree of degree m. Inserting 55. Inserting 55. B-Trees External Methods

Design and Analysis of Algorithms Lecture- 9: B- Trees

Efficient pebbling for list traversal synopses

Question Bank Subject: Advanced Data Structures Class: SE Computer

Database System Concepts, 6 th Ed. Silberschatz, Korth and Sudarshan See for conditions on re-use

CS 206 Introduction to Computer Science II

Main Memory and the CPU Cache

Binary Tree. Binary tree terminology. Binary tree terminology Definition and Applications of Binary Trees

CS 525: Advanced Database Organization 04: Indexing

AP Programming - Chapter 20 Lecture page 1 of 17

9/29/2016. Chapter 4 Trees. Introduction. Terminology. Terminology. Terminology. Terminology

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

Introduction to Indexing 2. Acknowledgements: Eamonn Keogh and Chotirat Ann Ratanamahatana

Indexing Methods. Lecture 9. Storage Requirements of Databases

Chapter B: Hierarchical Model

CS 245: Database System Principles

CS350: Data Structures B-Trees

B-Trees. CS321 Spring 2014 Steve Cutchin

Multi-way Search Trees! M-Way Search! M-Way Search Trees Representation!

6-TREE. Tree: Directed Tree: A directed tree is an acyclic digraph which has one node called the root node

Lecture 32. No computer use today. Reminders: Homework 11 is due today. Project 6 is due next Friday. Questions?

Chapter 12: Indexing and Hashing. Basic Concepts

M-ary Search Tree. B-Trees. Solution: B-Trees. B-Tree: Example. B-Tree Properties. B-Trees (4.7 in Weiss)

Material You Need to Know

Chapter 12: Indexing and Hashing

* Due 11:59pm on Sunday 10/4 for Monday lab and Tuesday 10/6 Wednesday Lab

CSC148 Week 6. Larry Zhang

Algorithms and Data Structures

Data Structure and Algorithm Homework #3

CSE 4/521 Introduction to Operating Systems. Lecture 23 File System Implementation II (Allocation Methods, Free-Space Management) Summer 2018

8. Binary Search Tree

CS301 - Data Structures Glossary By

ECE250: Algorithms and Data Structures B-Trees (Part A)

Chapter 11: Indexing and Hashing" Chapter 11: Indexing and Hashing"

Data and File Structures Laboratory

CS F-11 B-Trees 1

Course Review for. Cpt S 223 Fall Cpt S 223. School of EECS, WSU

CS 206 Introduction to Computer Science II

CSCI-401 Examlet #5. Name: Class: Date: True/False Indicate whether the sentence or statement is true or false.

Data Structure Lecture#22: Searching 3 (Chapter 9) U Kang Seoul National University

CSE 5311 Notes 4a: Priority Queues

ITEC2620 Introduction to Data Structures

Chapter 11: Indexing and Hashing

File Systems. ECE 650 Systems Programming & Engineering Duke University, Spring 2018

Dictionaries. Priority Queues

Chapter 11: Indexing and Hashing

Algorithms in Systems Engineering ISE 172. Lecture 16. Dr. Ted Ralphs

Data Structure Lecture#11: Binary Trees (Chapter 5) U Kang Seoul National University

Trees. Estruturas de Dados / Programação 2 Árvores. Márcio Ribeiro twitter.com/marciomribeiro. Introduc)on. Hierarchical structure

Binary Search Trees. See Section 11.1 of the text.

Transcription:

Data Structure Lecture#15: Non-Binary Trees 2 (Chapter 6) U Kang Seoul National University U Kang (2016) 1

In This Lecture Main ideas in implementations of general trees Compare advantages and disadvantages of implementations Motivation and main ideas of sequential implementation U Kang (2016) 2

General Tree Implementation 1. List of Children 2. Left-Child/Right-Sibling 3. Dynamic Node 4. Dynamic Left-Child/Right-Sibling Evaluation criteria: how well each implementation supports parent(); leftmostchild(); rightsibling(); U Kang (2016) 3

1. Lists of Children U Kang (2016) 4

1. List of Children Advantages parent() is efficient leftmostchild() is efficient Combining two trees is easy if both trees are stored in an array Disadvantages rightsibling() is inefficient Problem from array-based implementation: needs to know the number of nodes in advance U Kang (2016) 5

2. Leftmost Child/Right Sibling Index U Kang (2016) 6

2. Leftmost Child/Right Sibling Index U Kang (2016) 7

2. Leftmost Child/Right Sibling Advantages parent(), leftmostchild(), rightsibling() are efficient Combining two trees is easy if both trees are stored in an array More space-efficient than 1. List of children approach Disadvantages Problem from array-based implementation: needs to know the number of nodes in advance U Kang (2016) 8

3. Dynamic Node ver 1 Link-based implementation of 1. List of children approach Each node can have a parent pointer as well (omitted for simplicity) U Kang (2016) 9

3. Dynamic Node ver 1 Advantages parent() is efficient (if parent pointer is stored for each node) leftmostchild() is efficient Combining two trees is easy No need to know the number of nodes in advance Disadvantages rightsibling() is inefficient Still, needs to allocate fixed-size array for each node U Kang (2016) 10

3. Dynamic Node ver 2 Each node now requires a fixed amount of space (assuming space for data = space for pointer) U Kang (2016) 11

3. Dynamic Node ver 2 Compared to ver 1, Ver 2 is more flexible: adding or removing an element is easy On the other hand, ver 2 requires more space than ver 1 U Kang (2016) 12

4. Dynamic Left-Child/Right-Sibling Link-based implementation of 2. Leftmost-Child/Right-Sibling approach Each node can have a parent pointer as well (omitted for simplicity) U Kang (2016) 13

4. Dynamic Left-Child/Right-Sibling Dynamic Left-Child/Right-Sibling approach vs. array based 2. Leftmost-Child/Right-Sibling approach Dynamic Left-Child/Right-Sibling is better: no need to preallocate memory Dynamic Left-Child/Right-Sibling approach vs. 3. Dynamic Node approach Dynamic Left-Child/Right-Sibling is better for space: uses less space U Kang (2016) 14

Sequential Implementations (1) In some cases, we want to focus only on space Goal is to minimize space, without considering the time for parent(), leftmostchild(), rightsibling() Application? archiving tree to backup disk (bank) Sequential tree implementation aims to minimize space to store the tree List node values in the order they would be visited by a preorder traversal No pointers are stored Saves space, but allows only sequential access Need to retain tree structure for reconstruction U Kang (2016) 15

Sequential Implementations (2) For binary trees Idea 1) use a symbol to mark null links AB/D//CEG///FH//I// / : null link What is the amount of space overhead? How can we further improve idea 1, especially for full binary tree? Idea 2) use a bit to indicate internal nodes. A B /DC E G/F HI : internal node. / : null link No / for full binary tree For full binary tree, space overhead? (assume each node requires 4 bytes which include the bit) U Kang (2016) 16

Sequential Implementations (3) For general trees, mark the end of each subtree with ) RAC)D)E))BF))) Can we use the same technique to store binary trees? Why or why not? U Kang (2016) 17

Sequential Implementations (4) Exercise: reconstruct a general tree from the sequential representation XAD)E))B)CG)H))) U Kang (2016) 18

Summary Main ideas in implementations of general trees Evaluation criteria Compare advantages and disadvantages of implementations Operations, running time, and space Motivation and main ideas of sequential implementation Reconstruct trees from sequential representations U Kang (2016) 19

Questions? U Kang (2016) 20