DATA STRUCTURE BS(IT)3rd. Tree An Introduction By Yasir Mustafa Roll No. BS(IT) 2007-11 Bahauddin Zakariya University, Multan.

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

TREES Chapter 6. Trees - Introduction  All previous data organizations we've studied are linear—each element can have only one predecessor and successor.
Binary Trees Chapter 6. Linked Lists Suck By now you realize that the title to this slide is true… By now you realize that the title to this slide is.
Binary Trees, Binary Search Trees CMPS 2133 Spring 2008.
EC-211 DATA STRUCTURES LECTURE Tree Data Structure Introduction –The Data Organizations Presented Earlier are Linear in That Items are One After.
CS 171: Introduction to Computer Science II
Computer Science 2 Data Structures and Algorithms V section 2 Introduction to Trees Professor: Evan Korth New York University.
Binary Tree Terminology Linear versus hierarchical data Tree – connected graph with no cycles Child Parent Descendant Sibling Ancestor Leaf vs. internal.
CS 206 Introduction to Computer Science II 09 / 22 / 2008 Instructor: Michael Eckmann.
© 2006 Pearson Addison-Wesley. All rights reserved11 A-1 Chapter 11 Trees.
Binary Trees. Linear data structures Here are some of the data structures we have studied so far: –Arrays –Singly-linked lists and doubly-linked lists.
Trees CMSC 433 Chapter 8.1 Nelson Padua-Perez Bill Pugh.
CSC 2300 Data Structures & Algorithms February 6, 2007 Chapter 4. Trees.
Joseph Lindo Trees Sir Joseph Lindo University of the Cordilleras.
Binary Trees. 2 Linear data structures Here are some of the data structures we have studied so far: –Arrays –Singly-linked lists and doubly-linked lists.
Trees Chapter 8. 2 Tree Terminology A tree consists of a collection of elements or nodes, organized hierarchically. The node at the top of a tree is called.
1 Trees Tree nomenclature Implementation strategies Traversals –Depth-first –Breadth-first Implementing binary search trees.
Introduction Of Tree. Introduction A tree is a non-linear data structure in which items are arranged in sequence. It is used to represent hierarchical.
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.
CMSC 341 Introduction to Trees. 8/3/2007 UMBC CMSC 341 TreeIntro 2 Tree ADT Tree definition  A tree is a set of nodes which may be empty  If not empty,
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.
Topic 17 Introduction to Trees
Compiled by: Dr. Mohammad Omar Alhawarat
Trees Chapter 8. 2 Tree Terminology A tree consists of a collection of elements or nodes, organized hierarchically. The node at the top of a tree is called.
Computer Science: A Structured Programming Approach Using C Trees Trees are used extensively in computer science to represent algebraic formulas;
CS-2852 Data Structures LECTURE 11 Andrew J. Wozniewicz Image copyright © 2010 andyjphoto.com.
Review 1 Queue Operations on Queues A Dequeue Operation An Enqueue Operation Array Implementation Link list Implementation Examples.
Trees : Part 1 Section 4.1 (1) Theory and Terminology (2) Preorder, Postorder and Levelorder Traversals.
Min Chen School of Computer Science and Engineering Seoul National University Data Structure: Chapter 6.
Trees By P.Naga Srinivasu M.tech,(MBA). Basic Tree Concepts A tree consists of finite set of elements, called nodes, and a finite set of directed lines.
Discrete Mathematics Chapter 5 Trees.
M180: Data Structures & Algorithms in Java Trees & Binary Trees Arab Open University 1.
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.
Binary Tree. Some Terminologies Short review on binary tree Tree traversals Binary Search Tree (BST)‏ Questions.
Data Structures Lakshmish Ramaswamy. Tree Hierarchical data structure Several real-world systems have hierarchical concepts –Physical and biological systems.
Binary Trees. 2 Parts of a binary tree A binary tree is composed of zero or more nodes In Java, a reference to a binary tree may be null Each node contains:
Graphs and Trees Mathematical Structures for Computer Science Chapter 5 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesGraphs and Trees.
TREES General trees Binary trees Binary search trees AVL trees Balanced and Threaded trees.
1 Trees : Part 1 Reading: Section 4.1 Theory and Terminology Preorder, Postorder and Levelorder Traversals.
Trees. Trees: – A trunk from the roots – Divides into branches – Ends in leaves.
Binary Trees.
Chapter 10 Trees © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
CSCE 210 Data Structures and Algorithms
Lecture 1 (UNIT -4) TREE SUNIL KUMAR CIT-UPES.
Binary Trees.
Fundamentals of Programming II Introduction to Trees
Recursive Objects (Part 4)
Tree.
Csc 2720 Instructor: Zhuojun Duan
Binary Trees "A tree may grow a thousand feet tall, but its leaves will return to its roots." -Chinese Proverb.
Section 8.1 Trees.
Binary Trees, Binary Search Trees
Data Structures and Database Applications Binary Trees in C#
CS223 Advanced Data Structures and Algorithms
Binary Trees.
Trees.
Binary Trees.
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
Trees.
Binary Trees.
CSE 373, Copyright S. Tanimoto, 2001 Binary Trees -
Chapter 20: Binary Trees.
Binary Trees.
Binary Trees, Binary Search Trees
8.2 Tree Traversals Chapter 8 - Trees.
Presentation transcript:

DATA STRUCTURE BS(IT)3rd

Tree An Introduction By Yasir Mustafa Roll No. BS(IT) Bahauddin Zakariya University, Multan

Tree… In computer science, a tree is a widely-used data structure that emulates a hierarchical tree structure with a set of linked nodes. It is an acyclic connected graph where each node has a set of zero or more children nodes, and at most one parent node.

Terminology… Trees are made up of nodes. Each node in a tree has zero or more child nodes, which are below it in the tree. A node that has a child is called the child's parent node. A node has at most one parent.

Terminology… (Continue) The height of a node is the length of the longest downward path to a leaf from that node. The height of the root is the height of the tree. Also called depth of the tree.

Terminology… (Continue) The topmost node in a tree is called the root node. Nodes with the same parent are called siblings. A node that has no children is called a leaf.

Tree Diagram (Binary Tree)

Tree ordering Two basic types of trees: Unordered tree : there is no order for the children of a node. Ordered tree : A tree on which an order is imposed for example, by assigning different natural numbers to each edge leading to a node's children. Binary search trees are one kind of ordered tree.

Common uses Manipulate hierarchical data Make information easy to search Manipulate sorted lists of data As a workflow for compositing digital images for visual effects

Binary Tree By Ahmad Mushtaq Roll No BS(IT) Bahauddin Zakariya University, Multan

What is Binary Tree…? Here each node can have at most two children. Child nodes are called left and right. If every non-leaf node in a binary tree has non empty left or right sub trees, the tree is called a strictly binary tree.

Size and Depth The size of a binary tree is the number of nodes in it This tree has size 12 The depth of a node is its distance from the root a is at depth zero e is at depth 2 The depth of a binary tree is the depth of its deepest node This tree has depth 4

Types of Binary Tree Rooted Binary Tree: is a rooted tree in which every node has at most two children. Full Binary Tree: is a tree in which every node other than the leaves has two children. Perfect Binary Tree: is a full binary tree in which all leaves are at the same depth or same Level. Complete Binary Tree: is a binary tree in which every level, except possibly the last, is completely filled, and all nodes are as far left as possible.

Tree Traversal To traverse (or walk) the binary tree is to visit each node in the binary tree exactly once Tree traversals are naturally recursive Since a binary tree has three “parts,” there are six possible ways to traverse the binary tree: root, left, right left, root, right left, right, root

Preorder traversal In preorder, the root is visited first Here’s a preorder traversal to print out all the elements in the binary tree:

Inorder traversal In inorder, the root is visited in the middle Here’s an inorder traversal to print out all the elements in the binary tree:

Postorder traversal In postorder, the root is visited last Here’s a postorder traversal to print out all the elements in the binary tree:

Difference between a LinkedList and a Binary Search Tree Linked List: Binary Tree: