Range Trees IOI Training Camp Keegan C-Smith.

Slides:



Advertisements
Similar presentations
SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.
Advertisements

Parallel Prefix Computation Advanced Algorithms & Data Structures Lecture Theme 14 Prof. Dr. Th. Ottmann Summer Semester 2006.
More sorting algorithms: Heap sort & Radix sort. Heap Data Structure and Heap Sort (Chapter 7.6)
Kymberly Fergusson CSE1303 Part A Data Structures and Algorithms Summer Semester 2003 Lecture A12 – Binary Trees.
Insert A tree starts with the dummy node D D 200 D 7 Insert D
Kymberly Fergusson CSE1303 Part A Data Structures and Algorithms Summer Semester 2003 Lecture A12 – Binary Trees.
Advanced Topics in Algorithms and Data Structures Page 1 An overview of lecture 3 A simple parallel algorithm for computing parallel prefix. A parallel.
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 19 Binary.
K-d tree k-dimensional indexing. Jaruloj Chongstitvatana k-d trees 2 Definition Let k be a positive integer. Let t be a k -d tree, with a root node p.
Heaps and heapsort COMP171 Fall 2005 Part 2. Sorting III / Slide 2 Heap: array implementation Is it a good idea to store arbitrary.
1 Section 9.2 Tree Applications. 2 Binary Search Trees Goal is implementation of an efficient searching algorithm Binary Search Tree: –binary tree in.
Recursion and Binary Tree ICS 51 – Introductory Computer Organization.
Types of Binary Trees Introduction. Types of Binary Trees There are several types of binary trees possible each with its own properties. Few important.
Trees By Charl du Plessis. Contents Basic Terminology Basic Terminology Binary Search Trees Binary Search Trees Interval Trees Interval Trees Binary Indexed.
1 Trees 2 Binary trees Section Binary Trees Definition: A binary tree is a rooted tree in which no vertex has more than two children –Left and.
Chapter 19 Implementing Trees and Priority Queues Fundamentals of Java.
Binary Trees 2 Overview Trees. Terminology. Traversal of Binary Trees. Expression Trees. Binary Search Trees.
Chapter 13 B Advanced Implementations of Tables – Balanced BSTs.
2-3 Tree. Slide 2 Outline  Balanced Search Trees 2-3 Trees Trees.
Binary Search Tree vs. Balanced Search Tree. Why care about advanced implementations? Same entries, different insertion sequence: 10,20,30,40,50,60,70,
1 5. Abstract Data Structures & Algorithms 5.1 Data Structure Fundamentals.
HEAPS. Review: what are the requirements of the abstract data type: priority queue? Quick removal of item with highest priority (highest or lowest key.
Data Structures: A Pseudocode Approach with C, Second Edition 1 Chapter 7 Objectives Create and implement binary search trees Understand the operation.
BINARY TREES A BINARY TREE t IS EITHER EMPTY OR CONSISTS OF AN ITEM, CALLED THE ROOT ITEM, AND TWO DISTINCT BINARY TREES, CALLED THE LEFT SUBTREE AND.
CHAPTER 10.1 BINARY SEARCH TREES    1 ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS.
Question 4 Tutorial 8. Part A Insert 20, 10, 15, 5,7, 30, 25, 18, 37, 12 and 40 in sequence into an empty binary tree
Interval Trees Marco Gallotta. Problem ● Given a collection of items i, each with value V i ● Want to answer many queries of the form: How many items.
Partially Ordered Data ,Heap,Binary Heap
Balanced Search Trees 2-3 Trees AVL Trees Red-Black Trees
Data Structures and Algorithms
Data Structures: Disjoint Sets, Segment Trees, Fenwick Trees
Binary search tree. Removing a node
Binary Search Tree (BST)
Binary Search Tree Chapter 10.
Chapter 10.1 Binary Search Trees
Tree.
Section 8.1 Trees.
Binary Search Trees < > = Binary Search Trees
External Methods Chapter 15 (continued)
Chapter 16 Tree Implementations
Heaps.
Binary Search Tree In order Pre order Post order Search Insertion
Tree data structure.
The Heap Data Structure
original list {67, 33,49, 21, 25, 94} pass { } {67 94}
Data Structures: Segment Trees, Fenwick Trees
Binary Heaps Text Binary Heap Building a Binary Heap
Binary Search Trees < > =
Heapsort Heap & Priority Queue.
Tree data structure.
Binary Tree Application Operations in Heaps
Dictionaries < > = /9/2018 3:06 AM Dictionaries
Heap Sort The Heap Data Structure
Multiway Trees Searching and B-Trees Advanced Tree Structures
Binary Trees: Motivation
Binary Search Trees < > =
Representing binary trees with lists
CMSC 341 Splay Trees.
Binary Search Trees Chapter 7 Objectives
Solution for Section Worksheet 4, #7b & #7c
m-Way Search Trees A m-way Search tree of degree ‘m’ can have
Chapter 20: Binary Trees.
CMSC 341 Splay Trees.
Tree and its terminologies
Algorithms CSCI 235, Spring 2019 Lecture 26 Midterm 2 Review
CS203 Lecture 14.
Binary Tree Implementation And Applications
Data Structures Using C++ 2E
Chapter 11 Trees © 2011 Pearson Addison-Wesley. All rights reserved.
A Binary Tree is a tree in which each node has at most 2 children
Presentation transcript:

Range Trees IOI Training Camp Keegan C-Smith

Overview ● Not called a range tree. ● Range trees can tell you how many of an item you in O (log n) ● Insertions in avg case: O (log n) ● Insertions can be ranges or single number. ● All ranges must be Integer ranges.

How it works ● Complete binary tree. ● Root encompasses entire range. ● Each node will cover a range [A,B]. – Left child will have range [A,(A+B)/2]. – Right child will have range ((A+B)/2,B]. – If A == B, a node has no children. A -> B (A+B)/ > B A -> (A+B)/2 5 -> > 105 -> 7

How it works cont. ● Because ranges have to be indexes, (A+B)/2 must be floored or ceil. For these slides I am going to use floor. ● Ranges must be inclusive.

Inserting ● When passing through a node: – If every num in range is in nodes range, increase node's count. Do not traverse children. – If no num in range is in left child's range, do not traverse left child. – If no num in range is in right child's range, do not traverse right child.

Inserting examples 1 -> > > > > > > 4 0

Inserting 1->4 1 -> > > > > > > 4 0

Inserting 2->3 1 -> > > > > > > 4 0

Inserting 2->4 1 -> > > > > > > 4 0

Inserting 4->4 1 -> > > > > > > 4 1

Reading ● To find out how many of item C you have you traverse as if inserting range C->C. ● Each node you pass through, you increment a count.

Reading of 4 1 -> > > > > > > 4 1 There are = 4 items of item 4

Implementation in an Array ● Can be implemented in an array if using indexing from 1. – Left tree index = current index * 2 – Right tree index = current index * ● Size of array:

Array Indexes