Advanced Topics in Algorithms and Data Structures 1 An example.

Slides:



Advertisements
Similar presentations
Chapter 13. Red-Black Trees
Advertisements

Interval Heaps Complete binary tree. Each node (except possibly last one) has 2 elements. Last node has 1 or 2 elements. Let a and b be the elements in.
Advanced Topics in Algorithms and Data Structures
Parallel algorithms for expression evaluation Part1. Simultaneous substitution method (SimSub) Part2. A parallel pebble game.
S. Sudarshan Based partly on material from Fawzi Emad & Chau-Wen Tseng
Tree Data Structures &Binary Search Tree 1. Trees Data Structures Tree  Nodes  Each node can have 0 or more children  A node can have at most one parent.
Augmenting Data Structures Advanced Algorithms & Data Structures Lecture Theme 07 – Part I Prof. Dr. Th. Ottmann Summer Semester 2006.
Trees1 More on Trees University Fac. of Sci. & Eng. Bus. School Law School CS Dept. EE Dept. Math. Dept.
AVL Tree Smt Genap Outline AVL Tree ◦ Definition ◦ Properties ◦ Operations Smt Genap
A parallel pebble game with applications to expression evaluation Lecture 11.
Advanced Topics in Algorithms and Data Structures 1 Rooting a tree For doing any tree computation, we need to know the parent p ( v ) for each node v.
Parallel Prefix Computation Advanced Algorithms & Data Structures Lecture Theme 14 Prof. Dr. Th. Ottmann Summer Semester 2006.
Advanced Topics in Algorithms and Data Structures 1 Lecture 4 : Accelerated Cascading and Parallel List Ranking We will first discuss a technique called.
A Binary Tree root leaf. A Binary Tree root leaf descendent of root parent of leaf.
Accelerated Cascading Advanced Algorithms & Data Structures Lecture Theme 16 Prof. Dr. Th. Ottmann Summer Semester 2006.
Arithmetic Expression Consider the expression arithmetic expression: (a – b) + ((c + d) + (e * f)) that can be represented as the following tree.
4/17/2017 Section 9.3 Tree Traversal ch9.3.
Advanced Topics in Algorithms and Data Structures Page 1 An overview of lecture 3 A simple parallel algorithm for computing parallel prefix. A parallel.
Tree Contraction Label leaf nodes 1...n –Rake odd indexed leaf nodes –Left Compress –Right Compress –Left Compress –Right Compress Key: avoid memory conflicts.
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.
DAST 2005 Week 4 – Some Helpful Material Randomized Quick Sort & Lower bound & General remarks…
Optimal binary search trees
1 Section 9.2 Tree Applications. 2 Binary Search Trees Goal is implementation of an efficient searching algorithm Binary Search Tree: –binary tree in.
MergeSort Source: Gibbs & Tamassia. 2 MergeSort MergeSort is a divide and conquer method of sorting.
ساختمانهای گسسته دانشگاه صنعتی شاهرود – اردیبهشت 1392.
Trees. Containers we have studied so far are linear. To represent nonlinear, i.e. hierarchal data we use trees. Nonlinear Containers root node leaf edge.
Trees CSC 172 SPRING 2002 LECTURE 14. Lists We have seen lists: public class Node { Object data; Node next; } 
The Binary Heap. Binary Heap Looks similar to a binary search tree BUT all the values stored in the subtree rooted at a node are greater than or equal.
Data Structure & Algorithm II.  Delete-min  Building a heap in O(n) time  Heap Sort.
1 Red-Black Trees By Mary Hudachek-Buswell Red Black Tree Properties Rotate Red Black Trees Insertion Red Black Trees.
Compiled by: Dr. Mohammad Omar Alhawarat
2-3 Tree. Slide 2 Outline  Balanced Search Trees 2-3 Trees Trees.
Reading and Writing Mathematical Proofs Spring 2015 Lecture 4: Beyond Basic Induction.
Recursive Data Structures and Grammars  Themes  Recursive Description of Data Structures  Grammars and Parsing  Recursive Definitions of Properties.
CS690L Data Mining: Classification
Recursive Data Structures and Grammars  Themes  Recursive Description of Data Structures  Recursive Definitions of Properties of Data Structures  Recursive.
Recursive Data Structures and Grammars  Themes  Recursive Description of Data Structures  Recursive Definitions of Properties of Data Structures  Recursive.
© University of Auckland Trees – (cont.) CS 220 Data Structures & Algorithms Dr. Ian Watson.
AVL trees1 AVL Trees Height of a node : The height of a leaf is 1. The height of a null pointer is zero. The height of an internal node is the maximum.
1 More Trees Trees, Red-Black Trees, B Trees.
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.
1. Iterative Preorder Traversal Rpreorder(T) 1. [process the root node] if T!= NULL then Write Data(T) else Write “empty Tree” 2. [process the left subtree]
Data Structures: A Pseudocode Approach with C, Second Edition 1 Chapter 7 Objectives Create and implement binary search trees Understand the operation.
ECOE 556: Algorithms and Computational Complexity Heapsort Serdar Taşıran.
DAST Tirgul 6. What is a Binary Search Tree? The keys in a binary search tree (BST) are always stored in such a way as to satisfy the search property:
COSC 2007 Data Structures II Chapter 13 Advanced Implementation of Tables II.
Data Structures and Algorithms for Information Processing
Recursive Objects (Part 4)
Binary search tree. Removing a node
CS202 - Fundamental Structures of Computer Science II
CS202 - Fundamental Structures of Computer Science II
AVL DEFINITION An AVL tree is a binary search tree in which the balance factor of every node, which is defined as the difference between the heights of.
Chapter 10.1 Binary Search Trees
Section 8.1 Trees.
CS223 Advanced Data Structures and Algorithms
CS200: Algorithms Analysis
BTrees.
CS202 - Fundamental Structures of Computer Science II
Abstract Data Structures
Lecture 9 Algorithm Analysis
Lecture 9 Algorithm Analysis
Lecture 9 Algorithm Analysis
Binary Tree Traversals
Section 9.3 by Andrew Watkins
Lecture 36 Section 12.2 Mon, Apr 23, 2007
Trees Addenda.
CS223 Advanced Data Structures and Algorithms
Chapter 20: Binary Trees.
CS202 - Fundamental Structures of Computer Science II
CS202 - Fundamental Structures of Computer Science II
Presentation transcript:

Advanced Topics in Algorithms and Data Structures 1 An example

Advanced Topics in Algorithms and Data Structures 2 An example

Advanced Topics in Algorithms and Data Structures 3 Evaluation of arithmetic expressions If we evaluate an expression tree bottom-up, it will take O( n ) time for a long and skinny tree. Hence we apply tree contraction.

Advanced Topics in Algorithms and Data Structures 4 Evaluation of arithmetic expressions We do not completely evaluate each internal node. We evaluate the internal nodes partially. For each internal node v, we associate a label ( a v, b v ). a v and b v are constants. The value of the expression at node is: ( a v X + b v ), where X is an unknown value for the expression of the subtree rooted at v.

Advanced Topics in Algorithms and Data Structures 5 Keeping an invariant Invariant: Let u be an internal node which holds the operation  , . Let v and w are the children of u with labels ( a v, b v ) and ( a w, b w ). Then the value at u is: val ( u ) = ( a v val ( v ) + b v )  ( a w val ( w ) + b w )

Advanced Topics in Algorithms and Data Structures 6 Keeping an invariant

Advanced Topics in Algorithms and Data Structures 7 Applying the rake operation The value at node u is: val ( u ) = ( a v c v + b v )  ( a w X + b w ) X is the unknown value at node w.

Advanced Topics in Algorithms and Data Structures 8 Applying the rake operation The contribution of val ( u ) to the value of node p ( u ) is: a u  val ( u ) + b u = a u [( a v c v + b v )  ( a w X + b w )] + b u We can adjust the labels of node w to ( a ’ w, b ’ w ) a ’ w = a u ( a v c v + b v ) a w b ’ w = a u ( a v c v + b v ) b w + b u

Advanced Topics in Algorithms and Data Structures 9 Complexity of expression evaluation The correctness of the expression evaluation depends on correctly maintaining the invariants. We start with a label (1, 0) for each leaf and correctly maintain the invariant at each rake operation. We have already proved the correctness of the rake operation. Hence, evaluation of an expression given as a binary tree takes O ( n ) work and O (log n ) time.

Advanced Topics in Algorithms and Data Structures 10 An example

Advanced Topics in Algorithms and Data Structures 11 An example

Advanced Topics in Algorithms and Data Structures 12 An example