Non-Linear data structures

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

Chapter 10: Trees. Definition A tree is a connected undirected acyclic (with no cycle) simple graph A collection of trees is called forest.
S. Sudarshan Based partly on material from Fawzi Emad & Chau-Wen Tseng
SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.
Binary Trees, Binary Search Trees CMPS 2133 Spring 2008.
Binary Trees, Binary Search Trees COMP171 Fall 2006.
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
Tree Traversals & Maps Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
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.
Types of Binary Trees Introduction. Types of Binary Trees There are several types of binary trees possible each with its own properties. Few important.
Advanced Algorithms Analysis and Design Lecture 8 (Continue Lecture 7…..) Elementry Data Structures By Engr Huma Ayub Vine.
Recursion Bryce Boe 2013/11/18 CS24, Fall Outline Wednesday Recap Lab 7 Iterative Solution Recursion Binary Tree Traversals Lab 7 Recursive Solution.
Lecture 17 Non-Linear data structures Richard Gesick.
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.
1 Binary Trees Informal defn: each node has 0, 1, or 2 children Informal defn: each node has 0, 1, or 2 children Formal defn: a binary tree is a structure.
Tree Data Structures.
Trees, Binary Trees, and Binary Search Trees COMP171.
Binary Search Tree Traversal Methods. How are they different from Binary Trees?  In computer science, a binary tree is a tree data structure in which.
 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.
Computer Science 112 Fundamentals of Programming II Introduction to 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 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 STRUCTURE BS(IT)3rd. Tree An Introduction By Yasir Mustafa Roll No. BS(IT) Bahauddin Zakariya University, Multan.
1 Trees General Trees  Nonrecursive definition: a tree consists of a set of nodes and a set of directed edges that connect pairs of nodes.
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.
Trees By JJ Shepherd. Introduction Last time we discussed searching and sorting in a more efficient way Divide and Conquer – Binary Search – Merge Sort.
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.
Binary Search Trees Chapter 7 Objectives
Fundamentals of Programming II Introduction to Trees
Recursive Objects (Part 4)
BST Trees
Sections 8.7 – 8.8 Balancing a Binary Search Tree.
Week 6 - Wednesday CS221.
Binary Search Tree (BST)
Binary Search Tree Chapter 10.
Tree.
Section 8.1 Trees.
Data Structures & Algorithm Design
ITEC 2620M Introduction to Data Structures
Binary Trees, Binary Search Trees
Chapter 22 : Binary Trees, AVL Trees, and Priority Queues
Binary Trees.
Binary Trees Based on slides by Alyssa Harding & Marty Stepp
Binary Trees.
Trees Definitions Implementation Traversals K-ary Trees
CSE 373, Copyright S. Tanimoto, 2002 Binary Trees -
Design and Analysis of Algorithms
Binary Trees, Binary Search Trees
Non-Linear Structures
CSE 373, Copyright S. Tanimoto, 2001 Binary Trees -
Chapter 20: Binary Trees.
Binary Trees, Binary Search Trees
Data Structures Using C++ 2E
Chapter 11 Trees © 2011 Pearson Addison-Wesley. All rights reserved.
NATURE VIEW OF A TREE leaves branches root. NATURE VIEW OF A TREE leaves branches root.
Presentation transcript:

Non-Linear data structures Lecture 21 Non-Linear data structures CSE 1322 6/28/2019

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 6/28/2019

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 6/28/2019

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 6/28/2019

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. 6/28/2019

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 6/28/2019

BST Tree Nodes This is important and is worthy of being repeated: 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 6/28/2019

Build the Tree Insert the following data into a BST that has a root node of 15: 25, 8, 4, 10, 30, 20, 6, 2, 12, 17, 36, 24, 9, 28 15 8 25 4 10 20 30 2 6 9 12 17 24 28 36 6/28/2019

A BST 6/28/2019

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 6/28/2019

Tree Traversal Tree traversal schemes include Preorder traversal –generates prefix order for expression tree Inorder traversal – generates the data in sorted order Postorder traversal – useful for deleting nodes from the tree These are depth first processes. You will encounter other processes in data structures. 6/28/2019

Tree Traversal Using L for the left child, R for the right child and RT for the root, Preorder traversal is RT L R Inorder traversal is L RT R Postorder traversal is L R RT 15 8 25 4 10 20 30 2 6 9 12 17 24 28 36 Inorder: 2, 4, 6, 8, 9, 10, 12, 15, 17, 20, 24, 25, 28, 30, 36 PreOrder: 15, 8, 4, 2, 6, 10, 9, 12, 25, 20, 17, 24, 30, 28, 36 PostOrder: 2, 6, 4, 9, 12, 10, 8, 17, 24, 20, 28, 36, 30, 25, 15 6/28/2019

Recursive Processing Example void PrintTree(Node current) { if (current != null) PRINT(current.data); PrintTree(current.left); PrintTree(current.right); } 6/28/2019

A tree struc- ture? 6/28/2019

A graph? 6/28/2019