Download presentation
Presentation is loading. Please wait.
Published byLuke Hamilton Modified over 9 years ago
1
DATA STRUCTURE BS(IT)3rd
2
Tree An Introduction By Yasir Mustafa Roll No. BS(IT) 2007-11 Bahauddin Zakariya University, Multan
3
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.
4
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.
5
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.
6
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.
7
Tree Diagram (Binary Tree)
8
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.
9
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
10
Binary Tree By Ahmad Mushtaq Roll No 07-45 BS(IT) 2007-11 Bahauddin Zakariya University, Multan
11
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.
12
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
13
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.
14
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
15
Preorder traversal In preorder, the root is visited first Here’s a preorder traversal to print out all the elements in the binary tree:
16
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:
17
Postorder traversal In postorder, the root is visited last Here’s a postorder traversal to print out all the elements in the binary tree:
18
Difference between a LinkedList and a Binary Search Tree Linked List: Binary Tree:
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.