CS2420: Lecture 15 Vladimir Kulyukin Computer Science Department Utah State University.

Slides:



Advertisements
Similar presentations
B-Trees. Motivation When data is too large to fit in the main memory, then the number of disk accesses becomes important. A disk access is unbelievably.
Advertisements

Trees Chapter 11.
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. 1 Chapter 17 Sorting.
CS 171: Introduction to Computer Science II
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 11.
CS2420: Lecture 24 Vladimir Kulyukin Computer Science Department Utah State University.
CS2420: Lecture 19 Vladimir Kulyukin Computer Science Department Utah State University.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu.
CS 253: Algorithms Chapter 6 Heapsort Appendix B.5 Credit: Dr. George Bebis.
CS2420: Lecture 13 Vladimir Kulyukin Computer Science Department Utah State University.
Analysis of Algorithms CS 477/677
More sorting algorithms: Heap sort & Radix sort. Heap Data Structure and Heap Sort (Chapter 7.6)
CS2420: Lecture 30 Vladimir Kulyukin Computer Science Department Utah State University.
CS2420: Lecture 37 Vladimir Kulyukin Computer Science Department Utah State University.
Priority queues CS310 – Data Structures Professor Roch Weiss, Chapter 6.9, 21 All figures marked with a chapter and section number are copyrighted © 2006.
CS2420: Lecture 28 Vladimir Kulyukin Computer Science Department Utah State University.
CS2420: Lecture 20 Vladimir Kulyukin Computer Science Department Utah State University.
Chapter 6: Priority Queues Priority Queues Binary Heaps Mark Allen Weiss: Data Structures and Algorithm Analysis in Java Lydia Sinapova, Simpson College.
CS2420: Lecture 27 Vladimir Kulyukin Computer Science Department Utah State University.
CS2420: Lecture 10 Vladimir Kulyukin Computer Science Department Utah State University.
CS2420: Lecture 22 Vladimir Kulyukin Computer Science Department Utah State University.
Heaps & Priority Queues Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
CS2420: Lecture 17 Vladimir Kulyukin Computer Science Department Utah State University.
CS 5000: Lecture 37 Vladimir Kulyukin Department of Computer Science Utah State University.
CS2420: Lecture 18 Vladimir Kulyukin Computer Science Department Utah State University.
Rooted Trees. More definitions parent of d child of c sibling of d ancestor of d descendants of g leaf internal vertex subtree root.
Vladimir Kulyukin Computer Science Department Utah State University
CS2420: Lecture 29 Vladimir Kulyukin Computer Science Department Utah State University.
CS2420: Lecture 31 Vladimir Kulyukin Computer Science Department Utah State University.
Binary Tree Properties & Representation. Minimum Number Of Nodes Minimum number of nodes in a binary tree whose height is h. At least one node at each.
B + -Trees (Part 2) Lecture 21 COMP171 Fall 2006.
The Euler-tour technique
CS2420: Lecture 8 Vladimir Kulyukin Computer Science Department Utah State University.
CS2420: Lecture 42 Vladimir Kulyukin Computer Science Department Utah State University.
Binary Trees Chapter 6.
Binary Tree. Binary Trees – An Informal Definition A binary tree is a tree in which no node can have more than two children Each node has 0, 1, or 2 children.
Advanced Algorithms Analysis and Design Lecture 8 (Continue Lecture 7…..) Elementry Data Structures By Engr Huma Ayub Vine.
Min Chen School of Computer Science and Engineering Seoul National University Data Structure: Chapter 7.
UNCA CSCI September, 2001 These notes were prepared by the text’s author Clifford A. Shaffer Department of Computer Science Virginia Tech Copyright.
CS Data Structures Chapter 5 Trees. Chapter 5 Trees: Outline  Introduction  Representation Of Trees  Binary Trees  Binary Tree Traversals 
Binary Trees. Binary Tree Finite (possibly empty) collection of elements A nonempty binary tree has a root element The remaining elements (if any) are.
Binary Search Trees A binary tree:A binary tree: –No node has more than two child nodes (called child subtrees). –Child subtrees must be differentiated,
Chapter 6 Binary Trees. 6.1 Trees, Binary Trees, and Binary Search Trees Linked lists usually are more flexible than arrays, but it is difficult to use.
Binary Trees, Binary Search Trees RIZWAN REHMAN CENTRE FOR COMPUTER STUDIES DIBRUGARH UNIVERSITY.
Tree Data Structures. Introductory Examples Willliam Willliam BillMary Curt Marjorie Richard Anne Data organization such that items of information are.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 9.
Heaps Chapter 21. What is a heap used for? Sorting –HeapSort sorts an N-element array on O(N log N) time and uses very little extra memory Priority Queues.
Advance Data Structure 1 College Of Mathematic & Computer Sciences 1 Computer Sciences Department م. م علي عبد الكريم حبيب.
Min Chen School of Computer Science and Engineering Seoul National University Data Structure: Chapter 6.
Binary Search Trees Lecture 5 1. Binary search tree sort 2.
© University of Auckland Trees – (cont.) CS 220 Data Structures & Algorithms Dr. Ian Watson.
Heaps & Priority Queues
CMSC 341 Introduction to Trees. 2/21/20062 Tree ADT Tree definition –A tree is a set of nodes which may be empty –If not empty, then there is a distinguished.
Trees Chapter 10. CS 308 2Chapter Trees Preview: Preview: The data organizations presented in previous chapters are linear, in that items are one.
CSE 5392 Fall 2005 Week 4 Devendra Patel Subhesh Pradhan.
Trees. What is a tree? You know…  tall  green  leafy  possibly fruit  branches  roots  I’m sure you’ve seen them.
CS6045: Advanced Algorithms Sorting Algorithms. Heap Data Structure A heap (nearly complete binary tree) can be stored as an array A –Root of tree is.
1Computer Sciences. 2 HEAP SORT TUTORIAL 4 Objective O(n lg n) worst case like merge sort. Sorts in place like insertion sort. A heap can be stored as.
Week 7 - Wednesday.  What did we talk about last time?  Recursive running time  Master Theorem  Symbol tables.
Foundation of Computing Systems Lecture 4 Trees: Part I.
2 Binary Heaps What if we’re mostly concerned with finding the most relevant data?  A binary heap is a binary tree (2 or fewer subtrees for each node)
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
1 Trees. 2 Trees Trees. Binary Trees Tree Traversal.
Tree Representation and Terminology Binary Trees Binary Search Trees Pointer-Based Representation of a Binary Tree Array-Based Representation of a Binary.
CS223 Advanced Data Structures and Algorithms
Lecture 36 Section 12.2 Mon, Apr 23, 2007
Representing binary trees with lists
Binary Tree Properties & Representation
Chapter 20: Binary Trees.
Presentation transcript:

CS2420: Lecture 15 Vladimir Kulyukin Computer Science Department Utah State University

Outline Trees (Chapter 4)

Binary Tree Heights and Leaves For any binary tree with L leaves and height H

Binary Tree Properties Property 1: A binary tree with N > 0 nodes has exactly N-1 edges. Proof: Every node, except the root, receives exactly one edge from its parent.

Binary Tree Properties Property 2: If T is a binary tree of height h≥0, T has at least h+1 and at most 2 h nodes. Proof: Since T is of height h, T has h+1 levels. There must be at least one node on each level. So the number of nodes is at least h+1. Each level j has at most 2 j nodes. Thus, the number of nodes is at most 2 h+1 – 1.

Property 2: Lower Bound

Property 2: Upper Bound

Property 2: Upper and Lower Bounds on N

Binary Tree Properties

Binary Tree: Formula-Based Representation Formula-based representation –This assumes that the array counting starts with 1. –Parent(i) = i/2 –LeftChild(i) = 2i –RightChild(i) = 2i+1

Binary Tree: Linked Representation Linked representation –Each node is a structure containing data, and two pointers (LeftChild, RightChild).

BT Node: 2 Node Structures KEYDATA LEFT CHILD PTR RIGHT CHILD PTR KEY= DATA LEFT CHILD PTR RIGHT CHILD PTR