TREES– Interesting problems

Slides:



Advertisements
Similar presentations
CS Fall 2012, Lab 08 Haohan Zhu. Boston University Slideshow Title Goes Here CS Fall 2012, Lab /17/2015 Tree - Data Structure  Basic.
Advertisements

S. Sudarshan Based partly on material from Fawzi Emad & Chau-Wen Tseng
AA Trees another alternative to AVL trees. Balanced Binary Search Trees A Binary Search Tree (BST) of N nodes is balanced if height is in O(log N) A balanced.
Data Structures: Trees i206 Fall 2010 John Chuang Some slides adapted from Marti Hearst, Brian Hayes, or Glenn Brookshear.
Chapter 4: Trees General Tree Concepts Binary Trees Lydia Sinapova, Simpson College Mark Allen Weiss: Data Structures and Algorithm Analysis in Java.
© 2004 Goodrich, Tamassia Binary Search Trees   
1 Trees. 2 Outline –Tree Structures –Tree Node Level and Path Length –Binary Tree Definition –Binary Tree Nodes –Binary Search Trees.
CHAPTER 12 Trees. 2 Tree Definition A tree is a non-linear structure, consisting of nodes and links Links: The links are represented by ordered pairs.
Deletion algorithm – Phase 2: Remove node or replace its with successor TreeNode deleteNode(TreeNode n) { // Returns a reference to a node which replaced.
 Trees Data Structures Trees Data Structures  Trees Trees  Binary Search Trees Binary Search Trees  Binary Tree Implementation Binary Tree Implementation.
Chapter 10: Search Trees Nancy Amato Parasol Lab, Dept. CSE, Texas A&M University Acknowledgement: These slides are adapted from slides provided with Data.
CH 8. HEAPS AND PRIORITY QUEUES ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA.
Rudiments of Trees a Joshua presentation DATA STRUCTURES.
CH 7. TREES ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA AND MOUNT (WILEY.
CSE 3358 NOTE SET 13 Data Structures and Algorithms.
1 Joe Meehean. A A B B D D I I C C E E X X A A B B D D I I C C E E X X  Terminology each circle is a node pointers are edges topmost node is the root.
Week 7 - Wednesday.  What did we talk about last time?  Recursive running time  Master Theorem  Symbol tables.
CH 7 : TREE ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA AND MOUNT (WILEY.
CHAPTER 10 SEARCH TREES ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA AND.
CHAPTER 13 GRAPH ALGORITHMS ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA.
CH 9 : MAPS AND DICTIONARIES 1 ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA.
CHAPTER 10.1 BINARY SEARCH TREES    1 ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS.
Chapter 6 – Trees. Notice that in a tree, there is exactly one path from the root to each node.
Trees CSIT 402 Data Structures II 1. 2 Why Do We Need Trees? Lists, Stacks, and Queues are linear relationships Information often contains hierarchical.
BSTs, AVL Trees and Heaps Ezgi Shenqi Bran. What to know about Trees? Height of a tree Length of the longest path from root to a leaf Height of an empty.
CH 1-4 : INTRODUCTION ACKNOWLEDGEMENT: THE SLIDES ARE PREPARED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA AND.
3.1 Height-Balanced Trees 3.2 Weight-Balanced Trees
Binary Search Trees < > = © 2010 Goodrich, Tamassia
Binary Search Trees < > =
AA Trees.
CO4301 – Advanced Games Development Week 11 AVL Trees
Binary Search Trees < > =
Recursive Objects (Part 4)
AVL Trees 6/25/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M.
Maps, Hash tables, Skip Lists– Interesting problems
Trees.
CISC220 Fall 2009 James Atlas Lecture 13: Binary Trees.
Binary Search Tree Neil Tang 01/28/2010
Sections 8.7 – 8.8 Balancing a Binary Search Tree.
Source Code for Data Structures and Algorithm Analysis in C (Second Edition) – by Weiss
Multiway search trees and the (2,4)-tree
CO4301 – Advanced Games Development Week 10 Red-Black Trees continued
Chapter 10.1 Binary Search Trees
Tree.
Binary Trees "A tree may grow a thousand feet tall, but its leaves will return to its roots." -Chinese Proverb.
Tree traversal from Introduction to Trees Chapter 6 Objectives
ITEC 2620M Introduction to Data Structures
Tree data structure.
i206: Lecture 13: Recursion, continued Trees
TREES General trees Binary trees Binary search trees AVL trees
AVL Trees 4/29/15 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H.
Binary Search Trees < > = © 2010 Goodrich, Tamassia
Copyright © Aiman Hanna All rights reserved
Tree data structure.
Search Sorted Array: Binary Search Linked List: Linear Search
Trees CSE 373 Data Structures.
Trees.
The const Keyword The answer is that, yes, we don’t want the function to change the parameter, but neither do we want to use up time and memory creating.
Tree Representation Heap.
Ch. 8 Priority Queues And Heaps
v z Chapter 10 AVL Trees Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich,
Design and Analysis of Algorithms
Binary Search Trees < > =
Binary Search Tree Neil Tang 01/31/2008
CH 9 : Maps And Dictionary
Binary Search Trees < > =
Chapter 20: Binary Trees.
1 Lecture 13 CS2013.
Trees CSE 373 Data Structures.
General Tree Concepts Binary Trees
Presentation transcript:

TREES– Interesting problems Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich, Tamassia and Mount (Wiley 2004) and slides from Nancy M. Amato AND Jory Denny

Question 1 Given a binary tree, design an algorithm which creates a linked list of all the nodes at each depth (e.g. , if you have a tree with height D, you'll have D linked lists).

Question 2 Given a forest of balanced binary trees and two nodes, n1 and n2, find the closest common parent of n1 and n2. Nodes have parameters "parent", "left" and "right", and you cannot access the values of the nodes. If n1 and n2 are not on the same tree, return NULL.  Try to do this in O(log(n)) time and O(1) space. Note: A balanced tree is defined to be a tree such that the heights of the two subtrees of any node never differ by more than one.

Question 3 Find the diameter of a binary tree. Diameter is the longest path between two leaves in the tree.