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

Slides:



Advertisements
Similar presentations
1 abstract containers hierarchical (1 to many) graph (many to many) first ith last sequence/linear (1 to 1) set.
Advertisements

©Brooks/Cole, 2003 Chapter 12 Abstract Data Type.
Binary Trees, Binary Search Trees CMPS 2133 Spring 2008.
Binary Trees, Binary Search Trees COMP171 Fall 2006.
Trees Chapter 8.
Fall 2007CS 2251 Trees Chapter 8. Fall 2007CS 2252 Chapter Objectives To learn how to use a tree to represent a hierarchical organization of information.
Trees Chapter 8. Chapter 8: Trees2 Chapter Objectives To learn how to use a tree to represent a hierarchical organization of information To learn how.
Lists A list is a finite, ordered sequence of data items. Two Implementations –Arrays –Linked Lists.
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,
Lec 15 April 9 Topics: l binary Trees l expression trees Binary Search Trees (Chapter 5 of text)
© 2006 Pearson Addison-Wesley. All rights reserved11 A-1 Chapter 11 Trees.
1 abstract containers hierarchical (1 to many) graph (many to many) first ith last sequence/linear (1 to 1) set.
Fundamentals of Python: From First Programs Through Data Structures
Data Structures Using C++ 2E Chapter 11 Binary Trees and B-Trees.
CS Data Structures Chapter 5 Trees. Additional Binary Tree Operations (1/7)  Copying Binary Trees  we can modify the postorder traversal algorithm.
Marc Smith and Jim Ten Eyck
Department of Computer Eng. & IT Amirkabir University of Technology (Tehran Polytechnic) Data Structures Lecturer: Abbas Sarraf Trees.
10. Binary Trees A. Introduction: Searching a linked list.
Chapter 5 Trees: Outline
C o n f i d e n t i a l HOME NEXT Subject Name: Data Structure Using C Unit Title: Trees.
Data Structures Arrays both single and multiple dimensions Stacks Queues Trees Linked Lists.
Trees. Tree Terminology Chapter 8: Trees 2 A tree consists of a collection of elements or nodes, with each node linked to its successors The node at the.
Advanced Algorithms Analysis and Design Lecture 8 (Continue Lecture 7…..) Elementry Data Structures By Engr Huma Ayub Vine.
CS 3610 Midterm Review.
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.
CS Data Structures Chapter 5 Trees. Chapter 5 Trees: Outline  Introduction  Representation Of Trees  Binary Trees  Binary Tree Traversals 
Lecture 10 Trees –Definiton of trees –Uses of trees –Operations on a tree.
Trees Chapter 8. Chapter 8: Trees2 Chapter Objectives To learn how to use a tree to represent a hierarchical organization of information To learn how.
Chapter 19 Implementing Trees and Priority Queues Fundamentals of Java.
Spring 2010CS 2251 Trees Chapter 6. Spring 2010CS 2252 Chapter Objectives Learn to use a tree to represent a hierarchical organization of information.
1 Trees A tree is a data structure used to represent different kinds of data and help solve a number of algorithmic problems Game trees (i.e., chess ),
Chapter 19 Implementing Trees and Priority Queues Fundamentals of Java.
Binary Trees, Binary Search Trees RIZWAN REHMAN CENTRE FOR COMPUTER STUDIES DIBRUGARH UNIVERSITY.
Tree Data Structures. Introductory Examples Willliam Willliam BillMary Curt Marjorie Richard Anne Data organization such that items of information are.
Tree Data Structures.
1 CSC 211 Data Structures Lecture 24 Dr. Iftikhar Azim Niaz 1.
Data Structures and Algorithm Analysis Trees Lecturer: Jing Liu Homepage:
Prof. Amr Goneid, AUC1 CSCE 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part 4. Trees.
Starting at Binary Trees
Chapter 9 Binary Tree and General Tree. Overview ● Two-way decision making is one of the fundamental concepts in computing.  A binary tree models two-way.
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,
TREES. What is a tree ? An Abstract Data Type which emulates a tree structure with a set of linked nodes The nodes within a tree are organized in a hierarchical.
1 10. Binary Trees Read Sec A. Introduction: Searching a linked list. 1. Linear Search /* Linear search a list for a particular item */ 1. Set.
Data Structures & Algorithm Analysis Muhammad Hussain Mughal Trees. Binary Trees. Reading: Chap.4 ( ) Weiss.
Review 1 Queue Operations on Queues A Dequeue Operation An Enqueue Operation Array Implementation Link list Implementation Examples.
Tree Traversals, TreeSort 20 February Expression Tree Leaves are operands Interior nodes are operators A binary tree to represent (A - B) + C.
Lecture - 10 on Data Structures. 6:05:57 PM Prepared by, Jesmin Akhter, Lecturer, IIT,JU.
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.
CSCE 3110 Data Structures & Algorithm Analysis Rada Mihalcea Trees. Binary Trees. Reading: Chap.4 ( ) Weiss.
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.
Trees. 2 Root leaf CHAPTER 5 3 Definition of Tree n A tree is a finite set of one or more nodes such that: n There is a specially designated node called.
Binary Tree.
Foundation of Computing Systems Lecture 4 Trees: Part I.
BINARY TREES Objectives Define trees as data structures Define the terms associated with trees Discuss tree traversal algorithms Discuss a binary.
TREES General trees Binary trees Binary search trees AVL trees Balanced and Threaded trees.
1 Trees. 2 Trees Trees. Binary Trees Tree Traversal.
Prof. Amr Goneid, AUC1 CSCE 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part 4. Trees.
CSCE 3110 Data Structures & Algorithm Analysis
Trees Chapter 15.
CSCE 210 Data Structures and Algorithms
abstract containers sequence/linear (1 to 1) hierarchical (1 to many)
Binary Trees, Binary Search Trees
Binary Tree and General Tree
Binary Trees, Binary Search Trees
Trees.
Binary Trees.
Binary Trees, Binary Search Trees
Data Structures Using C++ 2E
Introduction to Trees Chapter 6 Objectives
NATURE VIEW OF A TREE leaves branches root. NATURE VIEW OF A TREE leaves branches root.
Presentation transcript:

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

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 of a Tree Structure (recursive definition) A tree is a finite set of one or more nodes such that –there is a specially designated node called root –the remaining nodes are partitioned into n ≧ 0 disjoint set T 1, …, T n, where each of these sets is a tree –T 1, …, T n are called the sub-trees of the root Every node in the tree is the root of some subtree 4

Tree Some Terminology node: the item of information plus the branches to each node degree: the number of sub-trees of a node degree of a tree: the maximum of the degree of the nodes in the tree terminal nodes (or leaf): nodes that have degree zero non-terminal nodes: nodes that don’t belong to terminal nodes children: the roots of the sub-trees of a node X are X’s children parent: X is the parent of its children siblings: children of the same parent are said to be siblings ancestors: all the nodes along the path from the root to that node level (of a node): defined by letting the root be at level one (if a node is at level l, then its children are at level l+1) height (or depth): the maximum level of any node in the tree 5

An example –A is the root node –B is the parent of D and E –C is the sibling of B –D and E are the children of B –D, E, F, G, I are external nodes, or leaves –A, B, C, H are internal nodes –The level of E is 3 –The height (depth) of the tree is 4 –The degree of node B is 2 –The degree of the tree is 3 –The ancestors of node I is A, C, H –The descendants of node C is F, G, H, I A BC DEFG I H Level

Representation of Trees List Representation –we can write of Figure 5.2 as a list in which each of the sub-trees is also a list ( A ( B ( E ( K, L ), F ), C ( G ), D ( H ( M ), I, J ) ) ) –the root comes first, followed by a list of sub-trees 7

8

Left child-right sibling representation 9

10

Binary Trees Binary trees are characterized by the fact that any node can have at most two branches Definition (recursive): –A binary tree is a finite set of nodes that is either empty or consists of a root and two disjoint binary trees called the left sub-tree and the right sub-tree Thus the left sub-tree and the right sub-tree are distinguished Any tree can be transformed into a binary tree –by left child-right sibling representation AA B B 11 Question Answer

The abstract data type of binary tree 12

Skewed and complete binary trees 13

Properties of Binary Trees Lemma 5.1 [Maximum number of nodes]: –The maximum number of nodes on level i of a binary tree is 2 i-1, i ≧ 1 –The maximum number of nodes in a binary tree of depth k is 2 k -1, k ≧ 1 Lemma 5.2 [Relation between number of leaf nodes and degree-2 nodes]: –For any nonempty binary tree, T, if n 0 is the number of leaf nodes and n 2 is the number of nodes of degree 2, then n 0 = n These lemmas allow us to define full and complete binary trees 14

Full/Complete Binary Tree A full binary tree of depth k is a binary tree of death k having 2 k -1 nodes, k ≧ 0 A binary tree with n nodes and depth k is complete iff its nodes correspond to the nodes numbered from 1 to n in the full binary tree of depth k From Lemma 5.1, the height of a complete binary tree with n nodes is log 2 (n+1) 15

16

Binary Tree Representations Using Array Lemma 5.3: If a complete binary tree with n nodes is represented sequentially, then for any node with index i, 1 ≦ i ≦ n, we have –parent(i) is at i/2 if i ≠ 1 if i = 1, i is at the root and has no parent –left_child(i) is at 2i if 2i ≦ n if 2i > n, then i has no left child –right_child(i) is at 2i+1 if 2i+1 ≦ n if 2i +1 > n, then i has no left child 17

[1][2][3][4][5][6][7] ABC—D—E Level 2Level 3 Level 1 A BC DH [1] [3] [4][5][6][7] [2] 18

Binary Tree Representations using Array Drawbacks Waste spaces –in the worst case, a skewed tree of depth k requires 2 k-1 spaces –of these, only k spaces will be occupied Insertion or deletion of nodes from the middle of a tree requires the movement of potentially many nodes to reflect the change in the level of these nodes 19

20

Binary Tree Representations Using Link 21

22

Binary Tree Traversals How to traverse a tree or visit each node in the tree exactly once? There are 6 possible combinations of traversal –LVR, LRV, VLR, VRL, RVL, RLV Adopt convention that we traverse left before right, only 3 traversals remain –LVR (inorder) –LRV (postorder) –VLR (preorder) left_childdataright_child L: moving left V: visiting node R: moving right 23

Binary Tree Arithmetic Expression Arithmetic Expression using binary tree –inorder traversal (infix expression) A / B * C * D + E –preorder traversal (prefix expression) + * * / A B C D E –postorder traversal (postfix expression) A B / C * D * E + –level order traversal + * E * D / C A B 24 Answer

25

26

27 Level-order traversal, which requires a queue to implement

28 Copying binary trees, similar to postorder traversal

29 Testing equality: binary trees are equivalent if they have the same data and topology

Any Questions? 30

What is 31 The time complexity of iter_inorder()?

Analysis of iter_inorder Non-recursive inorder traversal Let n be the number of nodes in the tree Time complexity: O(n) –every node of the tree is placed on and removed from the stack exactly once Space complexity: O(n) –equal to the depth of the tree which (skewed tree is the worst case) 32

Heap 33

Heap A 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 A max/min heap is a complete binary tree that is also a max/min tree Basic operations: –creation of an empty heap –insertion of a new element into a heap –deletion of the largest/smallest element from the heap 34

35

36

Priority Queues Heaps are frequently used to implement priority queues Delete the element with highest (lowest) priority Insert the element with arbitrary priority Heaps is the only way to implement priority queue An example: Huffman coding 37

38

39 Deletion from a max heap

Any Questions? 40

Can We Use 41 Array (ordered or unordered), list (ordered or unordered) to implement priority queues? What’s the complexities? A further question

42

Binary Search Trees 43

Binary Search Trees Heap is not suited for applications in which arbitrary elements are to be deleted from the element list –deletion of the max/min elementO(log 2 n) –deletion of an arbitrary elementO(n) –search for an arbitrary elementO(n) Definition of binary search tree: –every element has a unique key –the keys in a nonempty left/right sub-tree are smaller/larger than the key in the root of sub-tree –the left and right sub-trees are also binary search trees 44

45 Heap maintains the orders vertically, while binary search tree maintains them horizontally

Search(25)Search(76 )

47

48 O(height)

49

Binary Search Tree Deletion Three cases should be considered –leaf  delete –one child  delete and change the pointer to this child –two child  either the smallest element in the right sub-tree or the largest element in the left sub-tree 50

51

Height of a Binary Search Tree The height of a binary search tree with n elements can become as large as n It can be shown that when insertions and deletions are made at random, the height of the binary search tree is O(log 2 n) on the average Search trees with a worst-case height of O(log 2 n) are called balance search trees 52

Binary Search Trees Time Complexity Searching, insertion, deletion –O(h), where h is the height of the tree Worst case—skewed binary tree –O(n), where n is the number of internal nodes Prevent worst case –rebalancing scheme –AVL, 2-3, and red-black tree 53

Complete Link 54 Ina symmetric matrix Outthe tree Requirement - complete link algorithm - teamwork is encouraged - a report of how the work is split and why - time/space analyses - using C would be the best Bonus - output n clusters given n - single/average link

Deadline /4/13 23:59 Zip your code, a step-by-step README of how to execute the code and anything worthy extra credit. to

Hierarchical Clustering Hierarchical clustering takes as input a set of points Produces a set of nested clusters organized as a hierarchical tree Can be visualized as a dendrogram –a tree-like diagram that records the sequences of merges

The method is summarized below: –place all points into their own clusters –while there is more than one cluster, do merge the closest pair of clusters The behavior of the algorithm depends on how “closest pair of clusters” is defined 57

Complete Link Distance between two clusters C i and C j is the maximum distance between any object in C i and any object in C j The distance is defined by the two most dissimilar objects –