Lecture 17 Non-Linear data structures Richard Gesick.

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

Binary Trees, Binary Search Trees CMPS 2133 Spring 2008.
CS 171: Introduction to Computer Science II
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (4) Data Structures 11/18/2008 Yang Song.
BST Data Structure A BST node contains: A BST contains
© 2006 Pearson Addison-Wesley. All rights reserved11 A-1 Chapter 11 Trees.
CS 240: Data Structures Monday, July 30 th Binary Search Trees.
Binary Search Trees Chapter 7 Objectives
1 BST Trees A binary search tree is a binary tree in which every node satisfies the following: the key of every node in the left subtree is.
By : Budi Arifitama Pertemuan ke Objectives Upon completion you will be able to: Create and implement binary search trees Understand the operation.
Data Structures Arrays both single and multiple dimensions Stacks Queues Trees Linked Lists.
Types of Binary Trees Introduction. Types of Binary Trees There are several types of binary trees possible each with its own properties. Few important.
1 Trees Tree nomenclature Implementation strategies Traversals –Depth-first –Breadth-first Implementing binary search trees.
Chapter 19: Binary Trees. Objectives In this chapter, you will: – Learn about binary trees – Explore various binary tree traversal algorithms – Organize.
CISC220 Fall 2009 James Atlas Lecture 13: Trees. Skip Lists.
Tree (new ADT) Terminology:  A tree is a collection of elements (nodes)  Each node may have 0 or more successors (called children)  How many does a.
Binary Trees, Binary Search Trees RIZWAN REHMAN CENTRE FOR COMPUTER STUDIES DIBRUGARH UNIVERSITY.
Tree Data Structures.
Computer Science: A Structured Programming Approach Using C Trees Trees are used extensively in computer science to represent algebraic formulas;
 Trees Data Structures Trees Data Structures  Trees Trees  Binary Search Trees Binary Search Trees  Binary Tree Implementation Binary Tree Implementation.
CSED101 INTRODUCTION TO COMPUTING TREE 2 Hwanjo Yu.
Trees Isaac Sheff. Nodes Building blocks of trees “Parent” node may have “Child” nodes Can be both parent and child Can’t be its own ancestor Can’t have.
Topics Definition and Application of Binary Trees Binary Search Tree Operations.
Computer Science 112 Fundamentals of Programming II Introduction to Trees.
Binary Search Trees Data Structures Ananda Gunawardena
Binary Trees In computer science, a binary tree is a tree data structure in which each node has at most two children, which are referred to as the left.
Discrete Mathematics Chapter 5 Trees.
1 Chapter 7 Objectives Upon completion you will be able to: Create and implement binary search trees Understand the operation of the binary search tree.
1 Binary Trees and Binary Search Trees Based on Dale & Co: Object-Oriented Data Structures using C++ (graphics)
1 Lecture 21: Binary Search Tree delete etc. operations Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.
ADT Binary Search Tree Ellen Walker CPSC 201 Data Structures Hiram College.
Lecture - 11 on Data Structures. Prepared by, Jesmin Akhter, Lecturer, IIT,JU Threaded Trees Binary trees have a lot of wasted space: the leaf nodes each.
Binary Search Trees (BST)
Rooted Tree a b d ef i j g h c k root parent node (self) child descendent leaf (no children) e, i, k, g, h are leaves internal node (not a leaf) sibling.
Data Structures: A Pseudocode Approach with C, Second Edition 1 Chapter 7 Objectives Create and implement binary search trees Understand the operation.
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.
Foundation of Computing Systems Lecture 4 Trees: Part I.
More Binary Search Trees, Project 2 Bryce Boe 2013/08/06 CS24, Summer 2013 C.
Hello Everyone!!! 1. Tree And Graphs 2 Features of Trees  Tree Nodes Each node have 0 or more children A node have must one parent  Binary tree Tree.
Definitions Read Weiss, 4.1 – 4.2 Implementation Nodes and Links One Arrays Three Arrays Traversals Preorder, Inorder, Postorder K-ary Trees Converting.
BINARY TREES Objectives Define trees as data structures Define the terms associated with trees Discuss tree traversal algorithms Discuss a binary.
Trees By JJ Shepherd. Introduction Last time we discussed searching and sorting in a more efficient way Divide and Conquer – Binary Search – Merge Sort.
TREES From root to leaf. Trees  A tree is a non-linear collection  The elements are in a hierarchical arrangement  The elements are not accessible.
Binary Search Trees Chapter 7 Objectives
Fundamentals of Programming II Introduction to Trees
Binary Trees and Binary Search Trees
Recursive Objects (Part 4)
BST Trees
CISC220 Fall 2009 James Atlas Lecture 13: Binary Trees.
Sections 8.7 – 8.8 Balancing a Binary Search Tree.
Week 6 - Wednesday CS221.
Binary Search Tree (BST)
Tree.
Section 8.1 Trees.
Data Structures & Algorithm Design
ITEC 2620M Introduction to Data Structures
Binary Trees, Binary Search Trees
Binary Trees.
Abstract Data Structures
Binary Trees.
Trees Definitions Implementation Traversals K-ary Trees
Design and Analysis of Algorithms
Binary Trees, Binary Search Trees
Trees.
Chapter 20: Binary Trees.
Binary Trees.
Trees Trees.
Non-Linear data structures
Binary Trees, Binary Search Trees
NATURE VIEW OF A TREE leaves branches root. NATURE VIEW OF A TREE leaves branches root.
Presentation transcript:

Lecture 17 Non-Linear data structures Richard Gesick

Non-Linear data structures 2 primary types: Trees Graphs All trees are graphs, but not all graphs are trees Recursion is useful and is the easiest way to process them. It helps keep track of what's been processed and what remains 14-2

Graphs Graphs can have multiple references in and multiple references out (whereas tree node only has one reference in) Graphs can be directed or undirected and cyclic or acyclic 14-3

Trees Single parent 0 or more children A node with no children is called a "leaf" The topmost node is called the "root" N-ary trees Binary trees 14-4

N-ary Trees The best example of an n-ary tree is your computer’s directory system. It has a single starting point and then 0 or more branches. 14-5

Binary Trees and Binary Search Trees Binary search trees allow for fast insertion and removal of elements They are specially designed for fast searching A binary tree consists of two nodes, each of which has two child nodes All nodes in a binary search tree fulfill the property that: Descendants to the left have smaller data values than the node data value Descendants to the right have larger data values than the node data value 14-6

BST Tree Nodes All nodes in a binary search tree fulfill the property that: Descendants to the left have smaller data values than the node data value Descendants to the right have larger data values than the node data value 14-7

A BST 14-8

BST Balanced tree: each node has approximately as many descendants on the left as on the right If a binary search tree is balanced, then adding an element takes O(log(n)) time If the tree is unbalanced, insertion can be slow Perhaps as slow as insertion into a linked list 14-9

Tree Traversal Tree traversal schemes include Preorder traversal Inorder traversal Postorder traversal 14-10

Recursive Processing Example void PrintTree(Node current) { if (current != null) { Console.WriteLine(current.data); PrintTree(current.left); PrintTree(current.right); } 14-11

A tree struc- ture? 14-12

A graph? 14-13