The Euler-tour technique

Slides:



Advertisements
Similar presentations
Mathematical Preliminaries
Advertisements

General algorithmic techniques: Balanced binary tree technique Doubling technique: List Ranking Problem Divide and concur Lecture 6.
1 Parallel Algorithms (chap. 30, 1 st edition) Parallel: perform more than one operation at a time. PRAM model: Parallel Random Access Model. p0p0 p1p1.
Parallel Algorithms.
Lecture 15. Graph Algorithms
CS 336 March 19, 2012 Tandy Warnow.
Advanced Topics in Algorithms and Data Structures
Divide and Conquer. Subject Series-Parallel Digraphs Planarity testing.
Chapter 10: Trees. Definition A tree is a connected undirected acyclic (with no cycle) simple graph A collection of trees is called forest.
Lecture 3: Parallel Algorithm Design
ALGORITHMS THIRD YEAR BANHA UNIVERSITY FACULTY OF COMPUTERS AND INFORMATIC Lecture six Dr. Hamdy M. Mousa.
Introduction This chapter explores graphs and their applications in computer science This chapter explores graphs and their applications in computer science.
Data Structures and Algorithms1 Trees The definitions for this presentation are from from: Corman, et. al., Introduction to Algorithms (MIT Press), Chapter.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 21: Graphs.
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 14 Strongly connected components Definition and motivation Algorithm Chapter 22.5.
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.
Lists A list is a finite, ordered sequence of data items. Two Implementations –Arrays –Linked Lists.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2001 Lecture 9 Tuesday, 11/20/01 Parallel Algorithms Chapters 28,
Costas Busch - RPI1 Mathematical Preliminaries. Costas Busch - RPI2 Mathematical Preliminaries Sets Functions Relations Graphs Proof Techniques.
Graphs G = (V,E) V is the vertex set. Vertices are also called nodes and points. E is the edge set. Each edge connects two different vertices. Edges are.
Advanced Topics in Algorithms and Data Structures Page 1 An overview of lecture 3 A simple parallel algorithm for computing parallel prefix. A parallel.
Courtesy Costas Busch - RPI1 Mathematical Preliminaries.
CSE 373, Copyright S. Tanimoto, 2002 Up-trees - 1 Up-Trees Review of the UNION-FIND ADT Straight implementation with Up-Trees Path compression Worst-case.
Balanced Binary Search Trees height is O(log n), where n is the number of elements in the tree AVL (Adelson-Velsky and Landis) trees red-black trees get,
Review of Graphs A graph is composed of edges E and vertices V that link the nodes together. A graph G is often denoted G=(V,E) where V is the set of vertices.
Discrete Mathematics Lecture 9 Alexander Bukharovich New York University.
KNURE, Software department, Ph , N.V. Bilous Faculty of computer sciences Software department, KNURE The trees.
Binary Trees Chapter 6.
1 CSCI 2400 section 3 Models of Computation Instructor: Costas Busch.
Theory of Computing Lecture 10 MAS 714 Hartmut Klauck.
Advanced Algorithms Analysis and Design Lecture 8 (Continue Lecture 7…..) Elementry Data Structures By Engr Huma Ayub Vine.
ساختمانهای گسسته دانشگاه صنعتی شاهرود – اردیبهشت 1392.
Graph Theory Topics to be covered:
1 Section 1.4 Graphs and Trees A graph is set of objects called vertices or nodes where some pairs of objects may be connected by edges. (A directed graph.
Week 11 - Wednesday.  What did we talk about last time?  Graphs  Euler paths and tours.
CSCI 115 Chapter 7 Trees. CSCI 115 §7.1 Trees §7.1 – Trees TREE –Let T be a relation on a set A. T is a tree if there exists a vertex v 0 in A s.t. there.
Lecture 8 Tree.
Mathematical Preliminaries. Sets Functions Relations Graphs Proof Techniques.
Complexity 20-1 Complexity Andrei Bulatov Parallel Arithmetic.
Fall 2005Costas Busch - RPI1 Mathematical Preliminaries.
Prof. Busch - LSU1 Mathematical Preliminaries. Prof. Busch - LSU2 Mathematical Preliminaries Sets Functions Relations Graphs Proof Techniques.
5.5.3 Rooted tree and binary tree  Definition 25: A directed graph is a directed tree if the graph is a tree in the underlying undirected graph.  Definition.
Preview  Graph  Tree Binary Tree Binary Search Tree Binary Search Tree Property Binary Search Tree functions  In-order walk  Pre-order walk  Post-order.
Discrete Structures Trees (Ch. 11)
10 Copyright © William C. Cheng Data Structures - CSCI 102 Graph Terminology A graph consists of a set of Vertices and a set of Edges C A B D a c b d e.
5.5.2 M inimum spanning trees  Definition 24: A minimum spanning tree in a connected weighted graph is a spanning tree that has the smallest possible.
Data Structures and Algorithms in Parallel Computing Lecture 2.
Graphs. Graphs Similar to the graphs you’ve known since the 5 th grade: line graphs, bar graphs, etc., but more general. Those mathematical graphs are.
1 Fat heaps (K & Tarjan 96). 2 Goal Want to achieve the performance of Fibonnaci heaps but on the worst case. Why ? Theoretical curiosity and some applications.
Graph theory and networks. Basic definitions  A graph consists of points called vertices (or nodes) and lines called edges (or arcs). Each edge joins.
Eulerian Paths and Cycles. What is a Eulerian Path Given an graph. Find a path which uses every edge exactly once. This path is called an Eulerian Path.
Data Structures & Algorithms Graphs Richard Newman based on book by R. Sedgewick and slides by S. Sahni.
Graphs G = (V,E) V is the vertex set. Vertices are also called nodes and points. E is the edge set. Each edge connects two different vertices. Edges are.
Discrete Structures CISC 2315 FALL 2010 Graphs & Trees.
Chapter 10: Trees A tree is a connected simple undirected graph with no simple circuits. Properties: There is a unique simple path between any 2 of its.
Fall 2008Simple Parallel Algorithms1. Fall 2008Simple Parallel Algorithms2 Scalar Product of Two Vectors Let a = (a 1, a 2, …, a n ); b = (b 1, b 2, …,
HYPERCUBE ALGORITHMS-1
1 Mathematical Preliminaries. 2 Sets Functions Relations Graphs Proof Techniques.
Chapter 20: Graphs. Objectives In this chapter, you will: – Learn about graphs – Become familiar with the basic terminology of graph theory – Discover.
3/12/2013Computer Engg, IIT(BHU)1 PRAM ALGORITHMS-3.
Graphs and Shortest Paths Using ADTs and generic programming.
Chapter 11. Chapter Summary  Introduction to trees (11.1)  Application of trees (11.2)  Tree traversal (11.3)  Spanning trees (11.4)
Lecture 20. Graphs and network models 1. Recap Binary search tree is a special binary tree which is designed to make the search of elements or keys in.
Balanced Binary Search Trees
Lecture 3: Parallel Algorithm Design
Parallel Algorithms (chap. 30, 1st edition)
Balanced Binary Search Trees
Unit –VIII PRAM Algorithms.
Mathematical Preliminaries
Graphs G = (V,E) V is the vertex set.
Presentation transcript:

The Euler-tour technique The problem of computing the depth of each node in an n-node binary tree

Binary tree Let T be a binary tree stored in a PRAM C B Let T be a binary tree stored in a PRAM Each node i has fields parent[i], left[i] and right[i], which point to node i’s parent, left child and right child respectively Let’s assume that each node is identified by a non-negative integer Also we associate not one but 3 processes with each node; we call these node’s A,B and C processors Mapping between each node i and its 3 processors A,B and C: 3i, 3i+1, 3i+2

Computing depth of each node in an n node tree takes O(n) time on a serial RAM A simple parallel algorithm to compute depths propagates a “wave” downward from the root of the tree. The wave reaches all nodes at the same depth simultaneously, and thus by incrementing a counter carried along with the wave, we can compute the depth of each node. This parallel algorithm works well on a complete binary tree, since it runs in time proportional to the tree’s height. But the height of the tree could be as large as n-1

Using the Euler-tour technique we can compute node depths in O(log n) time on an EREW PRAM An Euler-tour of a graph is a cycle that traverses each edge exactly once, although it may visit a vertex more than ones A connected, directed graph has an Euler tour if and only if for all vertices v, the in-degree of v equals the out degree of v Since each undirected edge (u,v) in an undirected graph maps to two directed edges (u,v) and (v,u) in the directed version, the directed of any connected, undirected graph (and therefore of any undirected tree) has an Euler tour

Depth of nodes computation First we form an Euler tour of the directed version of T. The tour corresponds to walk of the tree with the following structure: A node’s A processor points to the A processor of its left child, if it exist, and otherwise to its own B processor A node’s B processor points to the A processor of its right child, if it exist, and otherwise to its own C processor A node’s C processor points to the B processor of its parent, if it is a left child and to the C processor of its parent if it is a right child. The root’s C processor points to NIL.

A B C

First step Thus, the head of the linked list formed by the Euler tour is the root’s A processor, and the tail is the root’s C processor. Given the pointers composing the original tree, an Euler tour can be constructed in O(1) time. Once we have linked list representing the Euler tour of T, we place a 1 in each A processor, a 0 in each B processor and a –1 in each C processor

A B C 1 -1

Second step We then perform a parallel prefix computation using ordinary addition as the associative operation We claim that after performing the parallel prefix computation, the depth of each node resides in the node’s C processor. Why?

A B C 1 2 3 4

WHY ??? The numbers are placed into the A,B and C processors in such a way that the net effect of visiting a subtree is to add 0 to the running sum The A processor of each node i contributes 1 to running sum The B processor of each node i contributes 0 because the depth of the node i’s left child equals the depth of the node i’s right child The C processor contributes –1, so the entire visit to the subtree rooted at node i has no effect on the running sum.

Conclusion The list representing Euler-tour can be computed in O(1) time. It has 3n objects, and thus the parallel prefix computation takes only O(log n) time Thus the total amount of time to compute all node depths is O(log n). Because no concurrent memory accesses are needed, the algorithm is an EREW algorithm.