國立清華大學電機工程學系. Outline

Size: px
Start display at page:

Download "國立清華大學電機工程學系. Outline"

Transcription

1 國立清華大學電機工程學系 2410 ata Structure hapter 5 Trees (Part I) Outline Introduction inary Trees inary Tree Traversal dditional inary Tree Operations Threaded inary Trees Heaps ch5.1-2

2 Genealogical harts no inbreeding is allowed ch5.1-3 Simple Tree a subtree very Node can have many children nodes but can only have one parent node LVL egree The maximum no. of children nodes root 1 2 F G H I J 3 K L M 4 ch5.1-4

3 irect Representation of a Tree a subtree root F G H I J K L M Possible node structure for a tree of degree k ata hild1 hild2 hild k Wasteful! ch5.1-5 List Representation of Tree Representing a Tree as a List ( ( ((K,L), F), (G), (H(M), I, J) )) 0 F 0 G 0 I J 0 K L 0 H M 0 This type of node indicates a sub-tree ch5.1-6

4 Lemma 5.1 Lemma If T is a k-ary tree (I.e., a tree of degree k) with n nodes, each having a fixed size as shown in previous slide, then n(k-1) + 1 of the nk child fields are 0, n 1 Proof: The number of non-0 child fields in an n-node tree is exactly n-11 The total number of child fields in a k-ary tree with n nodes is nk Hence, the number of 0 fields is nk-(n-1) = n(k-1)+1 ch5.1-7 Left hild-right Sibling 嫡長子 - 庶子 Representation ata left child right sibling F G H I J F G H I J K L M K L M ch5.1-8

5 egree-two Tree F G H I J K L F G H K L M M I J ch5.1-9 inary Tree efinition binary tree is a finite set of nodes that either is empty or consists of a root and two disjoint binary trees called left subtree and right subtree Skewed Tree omplete Tree F G H I ch5.1-10

6 T of inarytree template <class KeyType> class inarytree // objects: finite set of nodes either empty or consisting of a root node, // left inarytree and right inarytree public: inarytree(); // creates an empty binary tree oolean Ismpty(); // if the binary tree is empty, return TRU (1); else return FLS (0) inarytree( inarytree bt1, lement<keytype> item, inarytree bt2); // creates a binary tree whose left subtree is bt1, whose right subtree is bt2 // and whose root node contains item inarytree Lchild(); // if Ismpty(), return error; else return the left subtree of *this lement<keytype> ata(); // if Ismpty(), return error; else return the data in the root node of *this inarytree Rchild(); // if Ismpty(), return error; else return the right subtree of *this ; ch Maximum Number of Nodes Lemma 5.2 (1) The maximum no. of nodes on level i of a binary tree is 2 i-1, i 1 (2) The maximum number of nodes in a binary tree of depth k is 2 k -1, k 1 Proof by induction Induction base: root is the only node on level i=0 Induction hypothesis: max. no. of nodes on level i-1 is 2 i-2 Induction step: max. no. of nodes on level i is 2 i-1 k k-1 (maximum no. of nodes on level i) = 2 i = 2 k -1 i=1 i=0 ch5.1-12

7 Leaf Nodes vs. egree-2 Nodes Lemma 5.3 For any nonempty binary tree, T, if n 0 is the number of leaf nodes and n 2 the number of nodes of degree 2 then n 0 = n Proof Let n be the total number of nodes Let n 1 be the number of nodes of degree 1 We have n = n 0 +n 1 +n 2 If is the number of branches, n = + 1 and = n 1 + 2n 2 Hence we obtain n = + 1 = n 1 + 2n Finally, we can reach n 0 = n ch Full inary Tree With Sequential Node Number Let n be the number of nodes The depth will be ceiling(log 2 (n+1)) Lemma 5.4 If a complete binary tree with n nodes is represented sequentially, then for any node with index i, 1 i n, we have (1) parent(i) is at i/2 if i 1 (2) Lefthild(i) is at 2i if 2i n. If 2i>n, then i has no left child. (3) Righthild(i) is at 2i+1 if 2i+1 n. If 2i+1>n, then i has no right child ch5.1-14

8 rray Representation of Tree rray H I F G rray - F G H I ch Linked Representation class Tree; // forward declaration class TreeNode friend class Tree; Lefthild data Righthild private: TreeNode *Lefthild; char data; TreeNode *Righthild; ; data class Tree public: // Tree operations private: TreeNode *root; ; Lefthild Righthild ch5.1-16

9 List Representation of Tree 0 0 H I F root G F 0 0 G 0 0 H 0 0 I 0 ch Outline Introduction inary Trees inary Tree Traversal dditional inary Tree Operations Threaded inary Trees Heaps ch5.1-18

10 inary Tree With rithmetic xpression * + Inorder Traversal / * * + * Postorder Traversal / * * + / Preorder Traversal +**/ ch Inorder Traversal of a inary Tree void Tree::inorder() // river calls workhorse for traversal of entire tree. The driver is declared // as a public member function of Tree inorder(root); void Tree::inorder(TreeNode *urrentnode) // workhorse traverses the subtree rooted at urrentnode (which is a pointer to // a node in a binary tree). The workhorse is declared as a private member // function of Tree if (urrentnode) inorder( urrentnode Lefthild); cout << urrentnode data); inorder ( urrentnode Righthild); left sub-tree current right sub-tree ch5.1-20

11 Trace of Inorder Traversal + * * / ch Preorder Traversal of a inary Tree void Tree::preorder() // river calls workhorse for traversal of entire tree. The driver is declared // as a public member function of Tree preorder(root); void Tree::preorder(TreeNode *urrentnode) // workhorse traverses the subtree rooted at urrentnode (which is a pointer to // a node in a binary tree). The workhorse is declared as a private member // function of Tree if (urrentnode) cout << urrentnode data); preorder( urrentnode Lefthild); preorder ( urrentnode Righthild); left sub-tree current right sub-tree ch5.1-22

12 Postorder Traversal of a -Tree void Tree::postorder() // river calls workhorse for traversal of entire tree. The driver is declared // as a public member function of Tree postorder(root); void Tree::postorder(TreeNode *urrentnode) // workhorse traverses the subtree rooted at urrentnode (which is a pointer to // a node in a binary tree). The workhorse is declared as a private member // function of Tree if (urrentnode) postorder( urrentnode Lefthild); postorder ( urrentnode Righthild); cout << urrentnode data); left sub-tree current right sub-tree ch Iterative Inorder Traversal void Tree::NonRecInorder() // non-recursive inorder traversal using a stack * * Stack<TreeNode*> s; // declare and initialize iti stack TreeNode *urrentnode = root; / while(1) while (urrentnode) // move down the Lefthild fields all the way s.dd(urrentnode); // add to stack urrentnode = urrentnode Lefthild; if (! s.ismpty() ) // stack is not empty urrentnode =*s.elete ( urrentnode ); // pop from stack cout << urrentnode data << endl; urrentnode = urrentnode Righthild; // to explore Right SubTree else break; + ch5.1-24

13 Traversal Using Iterator class InorderIterator Inorder Traversal Using Iterator public: char *Next(); InorderIterator(Tree tree): t (tree) urrentnode = t.root; private: + const Tree& t; Stack<TreeNode*> s; New data member (not needed in a list iterator) * TreeNode *urrentnode; ; char *InorderIterator::Next() * while (urrentnode) s.dd(urrentnode); / urrentnode = urrentnode Lefthild; if (! s.ismpty() ) urrentnode = *s.elete( urrentnode ); char& temp = urrentnode data; urrentnode = urrentnode Righthild; // update urrentnode return &temp; else return(0); // tree has been traversed, no more elements ch Level-Order Traversal void Tree::LevelOrder() // Traverse the binary tree in level order Queue<TreeNode*> q; // queue is needed here TreeNode *urrentnode = root; while ( urrentnode ) cout << urrentnode data << endl; if ( urrentnode Lefthild ) q.dd(urrentnode Lefthild); if (urrentnode Righthild) q.dd(urrentnode Righthild); urrentnode = *q.elete(urrentnode); * * + readth-first Traversal (FS) Level-order traversal: + * * / / ch5.1-26

14 Three Ways of Tree Traversal Without Stacks dd a parent field to each node oubly linked dtree Use Lefthild and Righthild To maintain the paths back to the root shown in the next slide Threaded inary Tree To be introduced later ch Traversal Without Stack void Tree::NoStackInorder() // Inorder traversal of binary tree using a fixed amount of additional storage if (! root ) return; // empty binary tree TreeNode *top = 0, *LastRight = 0, *p, *q, *r, *r1; p = q = root; while (1) while (1) if ( (! p Lefthild) && (! p Righthild ) ) // leaf node cout << p data; break; if ( (! p Lefthid ) // visit p and move to p Righthild cout << p data; r = p Righthild; p Righthild = q; 7 q = p; p = r; else // move to p Lefthild r = p Lefthild; p Lefthild = q; q = p; p = r; // end of inner while TO ONTINU q p 1 r ch5.1-28

15 while (1) previous page // p is a leaf Traversal node, move upward Without to a node whose right subtree Stack not explored yet TreeNode *av = p; while (1) if (p==root) return; if (! q Lefthild) // q is linked via Righthild r = q Righthild; q Righthild = p; p = q; q = r; else if (! q Righthild ) // q is linked via Lefthild r = q Lefthild; q Lefthild = p; p = q; q = r; cout << p data; else // check if p is a Righthild of q if ( q == LastRight ) r = top; LastRight = r Lefthild; top = r Righthild; // unstack r Lefthild = r Righthild = 0; r = q Righthild; q Righthild = p; p = q; q = r; else // p is Lefthild of q cout << q data; // visit q av Lefthild = LastRight; av Righthild = top; top = av; LastRight = q; r = q Lefthild; q Lefthild = p; // restore link to p r1 = q Righthild; q Righthild = r; p = r1; break; ch Outline Introduction inary Trees inary Tree Traversal dditional inary Tree Operations Threaded inary Trees Heaps ch5.1-30

16 opying inary Trees // opy constructor Tree::Tree( const Tree& s) // driver root = copy(s.root); TreeNode *Tree::copy(TreeNode *orignode) // Workhorse // The function returns a pointer to an exact copy of the binary tree rooted // at orginode if ( originode ) ThreeNode *temp = new TreeNode; temp data = orignode data; temp Lefthild = copy(orignode Lefthild); temp Righthild = copy(orignode Righthild); return temp; else return 0; ch Propositional alculus oolean Formula is often constructed by a set of variables x 1, x 2, x 3, 3 operators such as * (N) + (OR), and ~ (NOT) holds the value of true or false onstruction Rules of Propositional alculus (1) variable is an expression (2) if x and y are expressions, then x*y, x+y, and ~x are expressions (3) Parentheses can be used to alter the normal order of evaluation xample: P = x1 + (x2 * ~ x3) valuation when x1=false, x2=true, x3=false, then P = true ch5.1-32

17 Satisfiability Problem Satisfiability Problem for formulas of propositional calculus asks if there is an assignment of values to the variables that causes the value of the expression to be true xample P = x1 * ~x2 + ~x1 * x3 + ~x3 + + ~ * * x3 x1 ~ ~ x3 x2 x1 ch First Version of Satisfiability Problem enum oolean FLS, TRU ; enum TypesOfata NOT, N, OR, TRU, FLS class SatTree; // forward declaration class SatNode friend class SatTree; private: SatNode *Lefthild; TypesOfata data; oolean value; SatNode *Righthild; class SatTree public: void PostOrderval(); void rootvalue() cout << root value; ; private: SatNode *root; void PostOrderval ( SatNode *); ; for all 2 n possible value combinations for the n variables generate the next combination; replace the variable by their values; evaluate the formula by traversing the tree by PostOrderval(); if ( formula.rootvalue()) cout << combination; return; cout << no satisfiable combination ; ch5.1-34

18 valuating Formula void SatTree::PostOrderval() // river PostOrderval ( root ); void SatTree::PostOrderval(SatNode *s) // Workhorse if (s) PostOrderval ( s Lefthild ); PostOrderval ( s Righthild ); switch ( s data) case NOT: s value =! s Righthild value; break; case N: s value = s Lefthild value && s Righthild value; case OR: break; s value = s Lefthild value s Righthild value; break; case TRU: s value = TRU; break; case FLS: s value = FLS; break; ch Outline Introduction inary Trees inary Tree Traversal dditional inary Tree Operations Threaded inary Trees Heaps ch5.1-36

19 Threaded Tree LeftTread Lefthild data Righthild RightThread TRU FLS To utilize 0-links: left thread: inorder predecessor right thread: inorder successor H 2 I 3 F G ch class ThreadedNode friend class ThreadedTree; friend class ThreadedInorderIterator; private: oolean LeftThread; ThreadedNode *Lefthild; char data; ThreadedNode *Righthild; lass for Threaded inary lass For Threaded inary Trees oolean RightThread; ; class ThreadedTree friend class ThreadedInorderIterator; public: // Tree manipulation operations follow private: ThreadedNode *root; ; class ThreadedInorderIterator public: char *next(); ThreadedInorderIterator(ThreadedTree tree): t (tree) urrentnode = t.root; ; private: ThreadedTree t; ThreadedNode *urrentnode; ch5.1-38

20 Memory Representation of Threaded Tree F G H I ch Finding the Inorder Successor char *ThreadedInorderIterator::Next() // Find the inorder successor of urrentnode in a threaded binary tree ThreadedNode *temp = urrentnode Righthild; // rightchild or successor if (! urrentnode RightThread ) while (! temp LeftThread ) temp = temp Lefthild; urrentnode = temp; if ( urrentnode == t.root ) return 0; // last node has been reached else return (&urrentnode data); void ThreadedInorderIterator::Inorder() for (char *ch = Next(); ch; ch = Next() ) cout << *ch << endl; F G H I ch5.1-40

21 Inserting Node In Threaded Tree s r insert r s r s r insert r s r ch Inserting Operation void ThreadedTree::InsertRight( ThreadedNode *s, ThreadedNode *r) // Insert r as the right child of s r Righthild = s Righthild; r RightThread = s RightThread; r Lefthild = s; r LeftThread = TRU; // Lefthild is a thread s Righthild = r; // ttach r to s s RightThread = FLS; if (! r RightThread) ThreadedNode *temp = InorderSucc(r) ; // returns the inorder successor of r temp Lefthild = r; s s r insert r r ch5.1-42

22 Outline Introduction inary Trees inary Tree Traversal dditional inary Tree Operations Threaded inary Trees Heaps ch Priority Queue Priority Queue lements deleted is the one with the highest priority n element with arbitrary priority may be inserted This is called max priority queue min priority queue is defined similarly template<class Type> class MaxPQ public: virtual void insert(const lement<type>&) = 0; virtual lement<type>* eletemax( lement<type>&) = 0; ; ch5.1-44

23 Heap Max Heap is frequently used to implement a priority queue efinition max(min) tree is a tree in which the key value in each node is no smaller (larger) than the key values in its children (if any) max heap is a complete binary tree that is also a max tree min heap is a complete binary tree that is also a min tree ch lass efinition of Max Heap template <class KeyType> class MaxHeap : public MaxPQ<KeyType> // objects: complete binary tree of n > 0 elements organized in a way that // the value in each node is at least as large as those in its children public: MaxHeap( int sz = efaultsize); // reate an empty heap that can hold a maximum of sz elements oolean IsFull(); // If the number of elements in the heap is equal to the maximum size of the // heap, return TRU(1); otherwise, return FLS(0) void Insert(lement<KeyType> item); // If IsFull(), then error, else insert item into the heap oolean Ismpty() // If number of elements in heap is 0, return TRU(1); else return FLS(0) lement<keytype>* elete(keytype& x); private: lement<type> *heap; int n; // current size of max heap int MaxSize; // Maximum allowable size of heap ch5.1-46

24 Insertion To a Max Heap after adding a node new still a complete binary tree Final tree after inserting 5 Final tree after inserting 21 ch Insertion To a Max Heap template <class Type> void MaxHeap<Type>::Insert( const lement<type>& x) // insert x into the max heap original 20 if (n==maxsize) HeapFull(); return; n++; for(int i=n; 1;) 15 2 if (i==1) break; // at root if (x.key <= heap[i/2].key) break; x.key // move from parent to i heap[i] = heap[i/2]; adding 5 x 是節點物件,x.key 是關鍵值 adding 21 i=i/2; i heap[i] = x; // write in the data ch5.1-48

25 eletion From a Max Heap after deleting the root element 15 null after moving 15 after moving to the vacancy 10 to the vacancy null Final tree still complete binary tree ch eletion From a Max Heap after deleting the root element null after moving 19 to the vacancy null after moving 10 to the vacancy ch5.1-50

26 eletion From a Max Heap template <class Type> lement<type>* MaxHeap<Type>::eleteMax(lement<Type>& x) // elete from the max heap if (n==0) Heapmpty(); return 0; x = heap[1]; lement<type> k = heap[n]; n--; for ( int i=1; j=2; j<=n;) if (j<n) if (heap[j].key < heap[j+1].key) j++; // j points to the larger child if (k.key >= heap[j].key) break; heap[i] = heap[j]; // move child up i = j; j *= 2; // move i and j down heap[i] = k; return &x; i: vacant position j: larger child height of a heap = log 2 (n+1) complexity = O(log n) ch The nd of Trees Part I Next Topic: Trees Part II

國立清華大學電機工程學系. Outline

國立清華大學電機工程學系. Outline 國立清華大學電機工程學系 EE4 Data Structure Chapter 5 Trees (Part II) Outline Binary Search Trees Selection Trees Forests Set Representation Counting Binary Tree ch5.- Definition Binary Search Tree (BST) binary search

More information

Data Structure - Binary Tree 1 -

Data Structure - Binary Tree 1 - Data Structure - Binary Tree 1 - Hanyang University Jong-Il Park Basic Tree Concepts Logical structures Chap. 2~4 Chap. 5 Chap. 6 Linear list Tree Graph Linear structures Non-linear structures Linear Lists

More information

CHAPTER 5. Trees CHAPTER 5 1/70

CHAPTER 5. Trees CHAPTER 5 1/70 CHAPTER 5 Trees All the programs in this file are selected from Ellis Horowitz, Sartaj Sahni, and Susan Anderson-Freed Fundamentals of Data Structures in C /2nd Edition, Silicon Press, 2008. CHAPTER 5

More information

CHAPTER 5 TREES PART I

CHAPTER 5 TREES PART I CHPTER 5 TREES PRT I Iris Hui-Ru Jiang Fall 2008 Part I 2 Contents inary trees Threaded binary trees Heaps inary search trees Selection trees Forests Disjoint sets Readings Chapter 5 Section 3.4, 7.6 Genealogical

More information

Tree Data Structures CSC 221

Tree Data Structures CSC 221 Tree Data Structures CSC 221 Specialized Trees Binary Tree: A restriction of trees such that the maximum degree of a node is 2. Order of nodes is now relevant May have zero nodes (emtpy tree) Formal Definition:

More information

Topic Binary Trees (Non-Linear Data Structures)

Topic Binary Trees (Non-Linear Data Structures) Topic Binary Trees (Non-Linear Data Structures) CIS210 1 Linear Data Structures Arrays Linked lists Skip lists Self-organizing lists CIS210 2 Non-Linear Data Structures Hierarchical representation? Trees

More information

binary tree empty root subtrees Node Children Edge Parent Ancestor Descendant Path Depth Height Level Leaf Node Internal Node Subtree

binary tree empty root subtrees Node Children Edge Parent Ancestor Descendant Path Depth Height Level Leaf Node Internal Node Subtree Binary Trees A binary tree is made up of a finite set of nodes that is either empty or consists of a node called the root together with two binary trees called the left and right subtrees which are disjoint

More information

Data Structure. Chapter 5 Trees (Part II) Angela Chih-Wei Tang. National Central University Jhongli, Taiwan

Data Structure. Chapter 5 Trees (Part II) Angela Chih-Wei Tang. National Central University Jhongli, Taiwan Data Structure Chapter 5 Trees (Part II) Angela Chih-Wei Tang Department of Communication Engineering National Central University Jhongli, Taiwan 2010 Spring Threaded Binary Tree Problem: There are more

More information

Chapter 20: Binary Trees

Chapter 20: Binary Trees Chapter 20: Binary Trees 20.1 Definition and Application of Binary Trees Definition and Application of Binary Trees Binary tree: a nonlinear linked list in which each node may point to 0, 1, or two other

More information

[ DATA STRUCTURES ] Fig. (1) : A Tree

[ DATA STRUCTURES ] Fig. (1) : A Tree [ DATA STRUCTURES ] Chapter - 07 : Trees A Tree is a non-linear data structure in which items are arranged in a sorted sequence. It is used to represent hierarchical relationship existing amongst several

More information

Binary Trees. Height 1

Binary Trees. Height 1 Binary Trees Definitions A tree is a finite set of one or more nodes that shows parent-child relationship such that There is a special node called root Remaining nodes are portioned into subsets T1,T2,T3.

More information

Trees. Q: Why study trees? A: Many advance ADTs are implemented using tree-based data structures.

Trees. Q: Why study trees? A: Many advance ADTs are implemented using tree-based data structures. Trees Q: Why study trees? : Many advance DTs are implemented using tree-based data structures. Recursive Definition of (Rooted) Tree: Let T be a set with n 0 elements. (i) If n = 0, T is an empty tree,

More information

DATA STRUCTURES USING C

DATA STRUCTURES USING C DATA STRUCTURES USING C The British Constitution Crown Church of England Cabinet House of Commons House of Lords Supreme Court Ministers County Metropolitan Council police Rural District County Borough

More information

CSI33 Data Structures

CSI33 Data Structures Outline Department of Mathematics and Computer Science Bronx Community College November 13, 2017 Outline Outline 1 C++ Supplement.1: Trees Outline C++ Supplement.1: Trees 1 C++ Supplement.1: Trees Uses

More information

Bioinformatics Programming. EE, NCKU Tien-Hao Chang (Darby Chang)

Bioinformatics Programming. EE, NCKU Tien-Hao Chang (Darby Chang) Bioinformatics Programming EE, NCKU Tien-Hao Chang (Darby Chang) 1 Tree 2 A Tree Structure A tree structure means that the data are organized so that items of information are related by branches 3 Definition

More information

Binary Trees. Directed, Rooted Tree. Terminology. Trees. Binary Trees. Possible Implementation 4/18/2013

Binary Trees. Directed, Rooted Tree. Terminology. Trees. Binary Trees. Possible Implementation 4/18/2013 Directed, Rooted Tree Binary Trees Chapter 5 CPTR 318 Every non-empty directed, rooted tree has A unique element called root One or more elements called leaves Every element except root has a unique parent

More information

Tree Structures. Definitions: o A tree is a connected acyclic graph. o A disconnected acyclic graph is called a forest

Tree Structures. Definitions: o A tree is a connected acyclic graph. o A disconnected acyclic graph is called a forest Tree Structures Definitions: o A tree is a connected acyclic graph. o A disconnected acyclic graph is called a forest o A tree is a connected digraph with these properties: There is exactly one node (Root)

More information

Binary Trees, Binary Search Trees

Binary Trees, Binary Search Trees Binary Trees, Binary Search Trees Trees Linear access time of linked lists is prohibitive Does there exist any simple data structure for which the running time of most operations (search, insert, delete)

More information

Trees. (Trees) Data Structures and Programming Spring / 28

Trees. (Trees) Data Structures and Programming Spring / 28 Trees (Trees) Data Structures and Programming Spring 2018 1 / 28 Trees A tree is a collection of nodes, which can be empty (recursive definition) If not empty, a tree consists of a distinguished node r

More information

Lec 17 April 8. Topics: binary Trees expression trees. (Chapter 5 of text)

Lec 17 April 8. Topics: binary Trees expression trees. (Chapter 5 of text) Lec 17 April 8 Topics: binary Trees expression trees Binary Search Trees (Chapter 5 of text) Trees Linear access time of linked lists is prohibitive Heap can t support search in O(log N) time. (takes O(N)

More information

Binary Trees. Examples:

Binary Trees. Examples: Binary Trees A tree is a data structure that is made of nodes and pointers, much like a linked list. The difference between them lies in how they are organized: In a linked list each node is connected

More information

Data Structure Lecture#10: Binary Trees (Chapter 5) U Kang Seoul National University

Data Structure Lecture#10: Binary Trees (Chapter 5) U Kang Seoul National University Data Structure Lecture#10: Binary Trees (Chapter 5) U Kang Seoul National University U Kang (2016) 1 In This Lecture The concept of binary tree, its terms, and its operations Full binary tree theorem Idea

More information

TREES. Trees - Introduction

TREES. Trees - Introduction TREES Chapter 6 Trees - Introduction All previous data organizations we've studied are linear each element can have only one predecessor and successor Accessing all elements in a linear sequence is O(n)

More information

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR STUDENT IDENTIFICATION NO MULTIMEDIA COLLEGE JALAN GURNEY KIRI 54100 KUALA LUMPUR FIFTH SEMESTER FINAL EXAMINATION, 2014/2015 SESSION PSD2023 ALGORITHM & DATA STRUCTURE DSEW-E-F-2/13 25 MAY 2015 9.00 AM

More information

國立清華大學電機工程學系. Outline

國立清華大學電機工程學系. Outline 國立清華大學電機工程學系 EE Data Structure Chapter Graph (Part I) Outline The Graph Abstract Data Type Introduction Definitions Graph Representations Elementary Graph Operations Minimum Cost Spanning Trees ch.- River

More information

Tree: non-recursive definition. Trees, Binary Search Trees, and Heaps. Tree: recursive definition. Tree: example.

Tree: non-recursive definition. Trees, Binary Search Trees, and Heaps. Tree: recursive definition. Tree: example. Trees, Binary Search Trees, and Heaps CS 5301 Fall 2013 Jill Seaman Tree: non-recursive definition Tree: set of nodes and directed edges - root: one node is distinguished as the root - Every node (except

More information

A Hierarchical Structure. Lecture11: Tree I. Tree Data Structures. Unix/Linux file systems. Bohyung Han CSE, POSTECH

A Hierarchical Structure. Lecture11: Tree I. Tree Data Structures. Unix/Linux file systems. Bohyung Han CSE, POSTECH Unix/Linux file systems Hierarchical Structure (2015F) Lecture11: Tree I ohyung Han S, POSTH bhhan@postech.ac.kr 2 Tree ata Structures n abstract model of a hierarchical structure 2 dimensional structure

More information

Trees, Heaps, and Priority Queues

Trees, Heaps, and Priority Queues Chapter 17 Trees, Heaps, and Priority Queues Objectives To know how to represent and access the elements in a binary tree ( 17.2.1-17.2.2). To insert an element to a binary tree ( 17.2.3). To traverse

More information

Graphs V={A,B,C,D,E} E={ (A,D),(A,E),(B,D), (B,E),(C,D),(C,E)}

Graphs V={A,B,C,D,E} E={ (A,D),(A,E),(B,D), (B,E),(C,D),(C,E)} Graphs and Trees 1 Graphs (simple) graph G = (V, ) consists of V, a nonempty set of vertices and, a set of unordered pairs of distinct vertices called edges. xamples V={,,,,} ={ (,),(,),(,), (,),(,),(,)}

More information

Objectives. In this session, you will learn to:

Objectives. In this session, you will learn to: TRS Objectives n this session, you will learn to: Store data in a tree istinguish types of inary tree Traverse a inary Tree norder PreOrder PostOrder onstruct a inary Tree onstruct an expression inary

More information

Tree. A path is a connected sequence of edges. A tree topology is acyclic there is no loop.

Tree. A path is a connected sequence of edges. A tree topology is acyclic there is no loop. Tree A tree consists of a set of nodes and a set of edges connecting pairs of nodes. A tree has the property that there is exactly one path (no more, no less) between any pair of nodes. A path is a connected

More information

國立清華大學電機工程學系. Outline

國立清華大學電機工程學系. Outline 國立清華大學電機工程學系 EE2410 Data Structure Chapter 4 Linked List (Part II) Outline Equivalence Class Sparse Matrices Doubly Linked Lists Generalized Lists Virtual Functions and Dynamic Binding ch4.2-2 1 Equivalence

More information

Module 04 Trees Contents

Module 04 Trees Contents Module 04 Trees Contents Chethan Raj C Assistant Professor Dept. of CSE 1. Trees Terminology 2. Binary Trees, Properties of Binary trees 3. Array and linked Representation of Binary Trees 4. Binary Tree

More information

Programming II (CS300)

Programming II (CS300) 1 Programming II (CS300) Chapter 11: Binary Search Trees MOUNA KACEM mouna@cs.wisc.edu Fall 2018 General Overview of Data Structures 2 Introduction to trees 3 Tree: Important non-linear data structure

More information

Data Structures. Trees. By Dr. Mohammad Ali H. Eljinini. M.A. Eljinini, PhD

Data Structures. Trees. By Dr. Mohammad Ali H. Eljinini. M.A. Eljinini, PhD Data Structures Trees By Dr. Mohammad Ali H. Eljinini Trees Are collections of items arranged in a tree like data structure (none linear). Items are stored inside units called nodes. However: We can use

More information

Chapter 5. Binary Trees

Chapter 5. Binary Trees Chapter 5 Binary Trees Definitions and Properties A binary tree is made up of a finite set of elements called nodes It consists of a root and two subtrees There is an edge from the root to its children

More information

Data Structure Chapter 6

Data Structure Chapter 6 ata Structure hapter Non-inary Trees r. Patrick han School of omputer Science and ngineering South hina University of Technology Outline Non-inary (eneral) Tree (h.) Parent Pointer mplementation (h.) ist

More information

Abstract Data Structures IB Computer Science. Content developed by Dartford Grammar School Computer Science Department

Abstract Data Structures IB Computer Science. Content developed by Dartford Grammar School Computer Science Department Abstract Data Structures IB Computer Science Content developed by Dartford Grammar School Computer Science Department HL Topics 1-7, D1-4 1: System design 2: Computer Organisation 3: Networks 4: Computational

More information

FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 ( Marks: 1 ) - Please choose one The data of the problem is of 2GB and the hard

FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 ( Marks: 1 ) - Please choose one The data of the problem is of 2GB and the hard FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 The data of the problem is of 2GB and the hard disk is of 1GB capacity, to solve this problem we should Use better data structures

More information

! Tree: set of nodes and directed edges. ! Parent: source node of directed edge. ! Child: terminal node of directed edge

! Tree: set of nodes and directed edges. ! Parent: source node of directed edge. ! Child: terminal node of directed edge Trees (& Heaps) Week 12 Gaddis: 20 Weiss: 21.1-3 CS 5301 Spring 2015 Jill Seaman 1 Tree: non-recursive definition! Tree: set of nodes and directed edges - root: one node is distinguished as the root -

More information

! Tree: set of nodes and directed edges. ! Parent: source node of directed edge. ! Child: terminal node of directed edge

! Tree: set of nodes and directed edges. ! Parent: source node of directed edge. ! Child: terminal node of directed edge Trees & Heaps Week 12 Gaddis: 20 Weiss: 21.1-3 CS 5301 Fall 2018 Jill Seaman!1 Tree: non-recursive definition! Tree: set of nodes and directed edges - root: one node is distinguished as the root - Every

More information

Trees. CSE 373 Data Structures

Trees. CSE 373 Data Structures Trees CSE 373 Data Structures Readings Reading Chapter 7 Trees 2 Why Do We Need Trees? Lists, Stacks, and Queues are linear relationships Information often contains hierarchical relationships File directories

More information

A Hierarchical Structure. Lecture11: Trees I. Tree Data Structures. Unix/Linux file systems. Bohyung Han CSE, POSTECH

A Hierarchical Structure. Lecture11: Trees I. Tree Data Structures. Unix/Linux file systems. Bohyung Han CSE, POSTECH Unix/Linux file systems Hierarchical Structure (2013F) Lecture11: Trees I ohyung Han S, POSTH bhhan@postech.ac.kr 2 Tree ata Structures n abstract model of a hierarchical structure 2 dimensional structure

More information

CSI33 Data Structures

CSI33 Data Structures Outline Department of Mathematics and Computer Science Bronx Community College October 19, 2016 Outline Outline 1 Chapter 7: Trees Outline Chapter 7: Trees 1 Chapter 7: Trees Uses Of Trees Chapter 7: Trees

More information

We have the pointers reference the next node in an inorder traversal; called threads

We have the pointers reference the next node in an inorder traversal; called threads Leaning Objective: In this Module you will be learning the following: Threaded Binary Tree Introduction: Threaded Binary Tree is also a binary tree in which all left child pointers that are NULL (in Linked

More information

Trees. Introduction to Data Structures Kyuseok Shim SoEECS, SNU.

Trees. Introduction to Data Structures Kyuseok Shim SoEECS, SNU. Trees Introduction to Data Structures Kyuseok Shim SoEECS, SNU. 5.1 Introduction 5.1.1 Terminology Tree : a finite set of one or more nodes there is a specially designated node called the root the remaining

More information

Chapter 12: Searching: Binary Trees and Hash Tables. Exercises 12.1

Chapter 12: Searching: Binary Trees and Hash Tables. Exercises 12.1 Chapter 12: Searching: Binary Trees and Hash Tables Exercises 12.1 1. 4, 6 2. 4, 1, 2, 3 3. 4, 6, 5 4. 4, 1, 0 5. 4, 6, 7, 8 6. template linearsearch(elementtype x[], ElementType

More information

Binary Tree. Preview. Binary Tree. Binary Tree. Binary Search Tree 10/2/2017. Binary Tree

Binary Tree. Preview. Binary Tree. Binary Tree. Binary Search Tree 10/2/2017. Binary Tree 0/2/ Preview Binary Tree Tree Binary Tree Property functions In-order walk Pre-order walk Post-order walk Search Tree Insert an element to the Tree Delete an element form the Tree A binary tree is a tree

More information

COSC 2007 Data Structures II Final Exam. Part 1: multiple choice (1 mark each, total 30 marks, circle the correct answer)

COSC 2007 Data Structures II Final Exam. Part 1: multiple choice (1 mark each, total 30 marks, circle the correct answer) COSC 2007 Data Structures II Final Exam Thursday, April 13 th, 2006 This is a closed book and closed notes exam. There are total 3 parts. Please answer the questions in the provided space and use back

More information

Introduction to Binary Trees

Introduction to Binary Trees Introduction to inary Trees 1 ackground ll data structures examined so far are linear data structures. Each element in a linear data structure has a clear predecessor and a clear successor. Precessors

More information

CSE 214 Computer Science II Heaps and Priority Queues

CSE 214 Computer Science II Heaps and Priority Queues CSE 214 Computer Science II Heaps and Priority Queues Spring 2018 Stony Brook University Instructor: Shebuti Rayana shebuti.rayana@stonybrook.edu http://www3.cs.stonybrook.edu/~cse214/sec02/ Introduction

More information

(2,4) Trees. 2/22/2006 (2,4) Trees 1

(2,4) Trees. 2/22/2006 (2,4) Trees 1 (2,4) Trees 9 2 5 7 10 14 2/22/2006 (2,4) Trees 1 Outline and Reading Multi-way search tree ( 10.4.1) Definition Search (2,4) tree ( 10.4.2) Definition Search Insertion Deletion Comparison of dictionary

More information

Trees. A tree is a directed graph with the property

Trees. A tree is a directed graph with the property 2: Trees Trees A tree is a directed graph with the property There is one node (the root) from which all other nodes can be reached by exactly one path. Seen lots of examples. Parse Trees Decision Trees

More information

H.O.#12 Fall 2015 Gary Chan. Binary Tree (N:12)

H.O.#12 Fall 2015 Gary Chan. Binary Tree (N:12) H.O.#12 Fall 2015 Gary Chan Binary Tree (N:12) Outline Binary tree terminology Tree traversals: preorder, inorder and postorder Dictionary and binary search tree Binary search tree operations Search min

More information

6-TREE. Tree: Directed Tree: A directed tree is an acyclic digraph which has one node called the root node

6-TREE. Tree: Directed Tree: A directed tree is an acyclic digraph which has one node called the root node 6-TREE Data Structure Management (330701) Tree: A tree is defined as a finite set of one or more nodes such that There is a special node called the root node R. The remaining nodes are divided into n 0

More information

Trees. Truong Tuan Anh CSE-HCMUT

Trees. Truong Tuan Anh CSE-HCMUT Trees Truong Tuan Anh CSE-HCMUT Outline Basic concepts Trees Trees A tree consists of a finite set of elements, called nodes, and a finite set of directed lines, called branches, that connect the nodes

More information

Lecture 37 Section 9.4. Wed, Apr 22, 2009

Lecture 37 Section 9.4. Wed, Apr 22, 2009 Preorder Inorder Postorder Lecture 37 Section 9.4 Hampden-Sydney College Wed, Apr 22, 2009 Outline Preorder Inorder Postorder 1 2 3 Preorder Inorder Postorder 4 Preorder Inorder Postorder Definition (Traverse)

More information

CE 221 Data Structures and Algorithms

CE 221 Data Structures and Algorithms CE 221 Data Structures and Algorithms Chapter 4: Trees (Binary) Text: Read Weiss, 4.1 4.2 Izmir University of Economics 1 Preliminaries - I (Recursive) Definition: A tree is a collection of nodes. The

More information

CSE 326: Data Structures Binary Search Trees

CSE 326: Data Structures Binary Search Trees nnouncements (1/3/0) S 36: ata Structures inary Search Trees Steve Seitz Winter 0 HW # due now HW #3 out today, due at beginning of class next riday. Project due next Wed. night. Read hapter 4 1 Ts Seen

More information

Complete Binary Trees

Complete Binary Trees Trees part 2. Full Binary Trees A binary tree is full if all the internal nodes (nodes other than leaves) has two children and if all the leaves have the same depth A A full binary tree of height h has

More information

Binary Trees. For example: Jargon: General Binary Trees. root node. level: internal node. edge. leaf node. Data Structures & File Management

Binary Trees. For example: Jargon: General Binary Trees. root node. level: internal node. edge. leaf node. Data Structures & File Management Binary Trees 1 A binary tree is either empty, or it consists of a node called the root together with two binary trees called the left subtree and the right subtree of the root, which are disjoint from

More information

A set of nodes (or vertices) with a single starting point

A set of nodes (or vertices) with a single starting point Binary Search Trees Understand tree terminology Understand and implement tree traversals Define the binary search tree property Implement binary search trees Implement the TreeSort algorithm 2 A set of

More information

Binary Tree Node Relationships. Binary Trees. Quick Application: Expression Trees. Traversals

Binary Tree Node Relationships. Binary Trees. Quick Application: Expression Trees. Traversals Binary Trees 1 Binary Tree Node Relationships 2 A binary tree is either empty, or it consists of a node called the root together with two binary trees called the left subtree and the right subtree of the

More information

a graph is a data structure made up of nodes in graph theory the links are normally called edges

a graph is a data structure made up of nodes in graph theory the links are normally called edges 1 Trees Graphs a graph is a data structure made up of nodes each node stores data each node has links to zero or more nodes in graph theory the links are normally called edges graphs occur frequently in

More information

Data Structures. Binary Trees. Root Level = 0. number of leaves:?? leaves Depth (Maximum level of the tree) leaves or nodes. Level=1.

Data Structures. Binary Trees. Root Level = 0. number of leaves:?? leaves Depth (Maximum level of the tree) leaves or nodes. Level=1. Data Structures inary Trees number of leaves:?? height leaves Depth (Maximum level of the tree) leaves or nodes Root Level = 0 Level=1 57 feet root 2 Level=2 Number of nodes: 2 (2+1) - 1 = 7 2 inary Trees

More information

Trees: examples (Family trees)

Trees: examples (Family trees) Ch 4: Trees it s a jungle out there... I think that I will never see a linked list useful as a tree; Linked lists are used by everybody, but it takes real smarts to do a tree Trees: examples (Family trees)

More information

ITEC2620 Introduction to Data Structures

ITEC2620 Introduction to Data Structures T2620 ntroduction to ata Structures Lecture 4a inary Trees Review of Linked Lists Linked-Lists dynamic length arbitrary memory locations access by following links an only traverse link in forward direction

More information

INF2220: algorithms and data structures Series 1

INF2220: algorithms and data structures Series 1 Universitetet i Oslo Institutt for Informatikk A. Maus, R.K. Runde, I. Yu INF2220: algorithms and data structures Series 1 Topic Trees & estimation of running time (Exercises with hints for solution) Issued:

More information

Copyright 1998 by Addison-Wesley Publishing Company 147. Chapter 15. Stacks and Queues

Copyright 1998 by Addison-Wesley Publishing Company 147. Chapter 15. Stacks and Queues Copyright 1998 by Addison-Wesley Publishing Company 147 Chapter 15 Stacks and Queues Copyright 1998 by Addison-Wesley Publishing Company 148 tos (-1) B tos (1) A tos (0) A A tos (0) How the stack routines

More information

CSCI-401 Examlet #5. Name: Class: Date: True/False Indicate whether the sentence or statement is true or false.

CSCI-401 Examlet #5. Name: Class: Date: True/False Indicate whether the sentence or statement is true or false. Name: Class: Date: CSCI-401 Examlet #5 True/False Indicate whether the sentence or statement is true or false. 1. The root node of the standard binary tree can be drawn anywhere in the tree diagram. 2.

More information

3 Trees: traversal and analysis of standard search trees. Summer Term 2010

3 Trees: traversal and analysis of standard search trees. Summer Term 2010 3 Trees: traversal and analysis of standard search trees Summer Term 2010 Robert Elsässer Binary Search Trees Binary trees for storing sets of keys (in the internal nodes of trees), such that the operations

More information

Principles of Computer Science

Principles of Computer Science Principles of Computer Science Binary Trees 08/11/2013 CSCI 2010 - Binary Trees - F.Z. Qureshi 1 Today s Topics Extending LinkedList with Fast Search Sorted Binary Trees Tree Concepts Traversals of a Binary

More information

Trees Algorhyme by Radia Perlman

Trees Algorhyme by Radia Perlman Algorhyme by Radia Perlman I think that I shall never see A graph more lovely than a tree. A tree whose crucial property Is loop-free connectivity. A tree which must be sure to span. So packets can reach

More information

Lecture 6: Analysis of Algorithms (CS )

Lecture 6: Analysis of Algorithms (CS ) Lecture 6: Analysis of Algorithms (CS583-002) Amarda Shehu October 08, 2014 1 Outline of Today s Class 2 Traversals Querying Insertion and Deletion Sorting with BSTs 3 Red-black Trees Height of a Red-black

More information

Topic 14. The BinaryTree ADT

Topic 14. The BinaryTree ADT Topic 14 The BinaryTree ADT Objectives Define trees as data structures Define the terms associated with trees Discuss tree traversal algorithms Discuss a binary tree implementation Examine a binary tree

More information

Binary Search Trees. What is a Binary Search Tree?

Binary Search Trees. What is a Binary Search Tree? Binary Search Trees What is a Binary Search Tree? A binary tree where each node is an object Each node has a key value, left child, and right child (might be empty) Each node satisfies the binary search

More information

CH 8. HEAPS AND PRIORITY QUEUES

CH 8. HEAPS AND PRIORITY QUEUES CH 8. HEAPS AND PRIORITY QUEUES ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA AND MOUNT (WILEY 2004) AND SLIDES FROM NANCY

More information

CMSC 341 Leftist Heaps

CMSC 341 Leftist Heaps CMSC 341 Leftist Heaps Based on slides from previous iterations of this course Today s Topics Review of Min Heaps Introduction of Left-ist Heaps Merge Operation Heap Operations Review of Heaps Min Binary

More information

CH. 8 PRIORITY QUEUES AND HEAPS

CH. 8 PRIORITY QUEUES AND HEAPS CH. 8 PRIORITY QUEUES AND HEAPS ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA AND MOUNT (WILEY 2004) AND SLIDES FROM NANCY

More information

IX. Binary Trees (Chapter 10)

IX. Binary Trees (Chapter 10) IX. Binary Trees (Chapter 10) -1- A. Introduction: Searching a linked list. 1. Linear Search /* To linear search a list for a particular Item */ 1. Set Loc = 0; 2. Repeat the following: a. If Loc >= length

More information

Name CPTR246 Spring '17 (100 total points) Exam 3

Name CPTR246 Spring '17 (100 total points) Exam 3 Name CPTR246 Spring '17 (100 total points) Exam 3 1. Linked Lists Consider the following linked list of integers (sorted from lowest to highest) and the changes described. Make the necessary changes in

More information

CMSC 341 Lecture 14: Priority Queues, Heaps

CMSC 341 Lecture 14: Priority Queues, Heaps CMSC 341 Lecture 14: Priority Queues, Heaps Prof. John Park Based on slides from previous iterations of this course Today s Topics Priority Queues Abstract Data Type Implementations of Priority Queues:

More information

Priority Queues. 1 Introduction. 2 Naïve Implementations. CSci 335 Software Design and Analysis III Chapter 6 Priority Queues. Prof.

Priority Queues. 1 Introduction. 2 Naïve Implementations. CSci 335 Software Design and Analysis III Chapter 6 Priority Queues. Prof. Priority Queues 1 Introduction Many applications require a special type of queuing in which items are pushed onto the queue by order of arrival, but removed from the queue based on some other priority

More information

Lecture Notes 16 - Trees CSS 501 Data Structures and Object-Oriented Programming Professor Clark F. Olson

Lecture Notes 16 - Trees CSS 501 Data Structures and Object-Oriented Programming Professor Clark F. Olson Lecture Notes 16 - Trees CSS 501 Data Structures and Object-Oriented Programming Professor Clark F. Olson Reading: Carrano, Chapter 15 Introduction to trees The data structures we have seen so far to implement

More information

Garbage Collection: recycling unused memory

Garbage Collection: recycling unused memory Outline backtracking garbage collection trees binary search trees tree traversal binary search tree algorithms: add, remove, traverse binary node class 1 Backtracking finding a path through a maze is an

More information

Binary Trees. College of Computing & Information Technology King Abdulaziz University. CPCS-204 Data Structures I

Binary Trees. College of Computing & Information Technology King Abdulaziz University. CPCS-204 Data Structures I Binary Trees College of Computing & Information Technology King Abdulaziz University CPCS-204 Data Structures I Outline Tree Stuff Trees Binary Trees Implementation of a Binary Tree Tree Traversals Depth

More information

Binary Trees

Binary Trees Binary Trees 4-7-2005 Opening Discussion What did we talk about last class? Do you have any code to show? Do you have any questions about the assignment? What is a Tree? You are all familiar with what

More information

COSC160: Data Structures Heaps. Jeremy Bolton, PhD Assistant Teaching Professor

COSC160: Data Structures Heaps. Jeremy Bolton, PhD Assistant Teaching Professor COSC160: Data Structures Heaps Jeremy Bolton, PhD Assistant Teaching Professor Outline I. Priority Queue II. Heaps I. Binary Heaps II. Skew Heaps Balancing a Tree Binary trees lack a depth constraint.

More information

Data Structures and Algorithms(6)

Data Structures and Algorithms(6) Ming Zhang "ata Structures and Algorithms" ata Structures and Algorithms(6) Instructor: Ming Zhang Textbook Authors: Ming Zhang, Tengjiao Wang and Haiyan Zhao Higher ducation Press, 2008.6 (the "leventh

More information

CSCI212 Computer Science. Binary Trees/Heaps/Binary Search Trees

CSCI212 Computer Science. Binary Trees/Heaps/Binary Search Trees CSCI212 Computer Science Binary Trees/Heaps/Binary Search Trees Tree Terminology 0 A tree is a non-linear abstract data type that stores elements hierarchically. 0 With the exception of the top element

More information

Introduction to Computers and Programming. Concept Question

Introduction to Computers and Programming. Concept Question Introduction to Computers and Programming Prof. I. K. Lundqvist Lecture 7 April 2 2004 Concept Question G1(V1,E1) A graph G(V, where E) is V1 a finite = {}, nonempty E1 = {} set of G2(V2,E2) vertices and

More information

Tree traversals and binary trees

Tree traversals and binary trees Tree traversals and binary trees Comp Sci 1575 Data Structures Valgrind Execute valgrind followed by any flags you might want, and then your typical way to launch at the command line in Linux. Assuming

More information

Data Structures Question Bank Multiple Choice

Data Structures Question Bank Multiple Choice Section 1. Fundamentals: Complexity, Algorthm Analysis 1. An algorithm solves A single problem or function Multiple problems or functions Has a single programming language implementation 2. A solution

More information

BST Implementation. Data Structures. Lecture 4 Binary search trees (BST) Dr. Mahmoud Attia Sakr University of Ain Shams

BST Implementation. Data Structures. Lecture 4 Binary search trees (BST) Dr. Mahmoud Attia Sakr University of Ain Shams Lecture 4 Binary search trees (BST) Dr. Mahmoud Attia Sakr mahmoud.sakr@cis.asu.edu.eg Cairo, Egypt, October 2012 Binary Search Trees (BST) 1. Hierarchical data structure with a single reference to root

More information

CMSC 341 Lecture 10 Binary Search Trees

CMSC 341 Lecture 10 Binary Search Trees CMSC 341 Lecture 10 Binary Search Trees John Park Based on slides from previous iterations of this course Review: Tree Traversals 2 Traversal Preorder, Inorder, Postorder H X M A K B E N Y L G W UMBC CMSC

More information

8. Write an example for expression tree. [A/M 10] (A+B)*((C-D)/(E^F))

8. Write an example for expression tree. [A/M 10] (A+B)*((C-D)/(E^F)) DHANALAKSHMI COLLEGE OF ENGINEERING DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING EC6301 OBJECT ORIENTED PROGRAMMING AND DATA STRUCTURES UNIT IV NONLINEAR DATA STRUCTURES Part A 1. Define Tree [N/D 08]

More information

CS 206 Introduction to Computer Science II

CS 206 Introduction to Computer Science II CS 206 Introduction to Computer Science II 10 / 10 / 2016 Instructor: Michael Eckmann Today s Topics Questions? Comments? A few comments about Doubly Linked Lists w/ dummy head/tail Trees Binary trees

More information

COMP : Trees. COMP20012 Trees 219

COMP : Trees. COMP20012 Trees 219 COMP20012 3: Trees COMP20012 Trees 219 Trees Seen lots of examples. Parse Trees Decision Trees Search Trees Family Trees Hierarchical Structures Management Directories COMP20012 Trees 220 Trees have natural

More information

TREES Lecture 10 CS2110 Spring2014

TREES Lecture 10 CS2110 Spring2014 TREES Lecture 10 CS2110 Spring2014 Readings and Homework 2 Textbook, Chapter 23, 24 Homework: A thought problem (draw pictures!) Suppose you use trees to represent student schedules. For each student there

More information

MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct.

MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct. MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct. In linked list the elements are necessarily to be contiguous In linked list the elements may locate at far positions

More information