Decision Trees DEFINITION: DECISION TREE A decision tree is a tree in which the internal nodes represent actions, the arcs represent outcomes of an action,

Slides:



Advertisements
Similar presentations
Introduction to Algorithms Quicksort
Advertisements

Lower Bounds for Sorting, Searching and Selection
22C:19 Discrete Structures Trees Spring 2014 Sukumar Ghosh.
Sorting Comparison-based algorithm review –You should know most of the algorithms –We will concentrate on their analyses –Special emphasis: Heapsort Lower.
© The McGraw-Hill Companies, Inc., Chapter 2 The Complexity of Algorithms and the Lower Bounds of Problems.
CS202 - Fundamental Structures of Computer Science II
Proofs, Recursion, and Analysis of Algorithms Mathematical Structures for Computer Science Chapter 2 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesProofs,
Discrete Structure Li Tak Sing( 李德成 ) Lectures
Introduction to Data Structure, Fall 2006 Slide- 1 California State University, Fresno Introduction to Data Structure Chapter 14 Ming Li Department of.
Branch and Bound Similar to backtracking in generating a search tree and looking for one or more solutions Different in that the “objective” is constrained.
CS2420: Lecture 13 Vladimir Kulyukin Computer Science Department Utah State University.
2 -1 Chapter 2 The Complexity of Algorithms and the Lower Bounds of Problems.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 19: Heap Sort.
2 -1 Analysis of algorithms Best case: easiest Worst case Average case: hardest.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L12 (Chapter 20) Lists, Stacks,
Data Structures Using C++ 2E Chapter 11 Binary Trees and B-Trees.
1 Section 9.2 Tree Applications. 2 Binary Search Trees Goal is implementation of an efficient searching algorithm Binary Search Tree: –binary tree in.
CPSC 335 BTrees Dr. Marina Gavrilova Computer Science University of Calgary Canada.
B-trees (Balanced Trees) A B-tree is a special kind of tree, similar to a binary tree. However, It is not a binary search tree. It is not a binary tree.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 19: Searching and Sorting Algorithms.
Chapter 19: Searching and Sorting Algorithms
Copyright © Cengage Learning. All rights reserved. CHAPTER 10 GRAPHS AND TREES.
Sorting Fun1 Chapter 4: Sorting     29  9.
Chapter 21 Binary Heap.
Discrete Structures Lecture 12: Trees Ji Yanyan United International College Thanks to Professor Michael Hvidsten.
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.
Data Structures Using C++ 2E Chapter 9 Searching and Hashing Algorithms.
Chapter 18: Searching and Sorting Algorithms. Objectives In this chapter, you will: Learn the various search algorithms Implement sequential and binary.
Discrete Mathematics Chapter 5 Trees.
LIMITATIONS OF ALGORITHM POWER
Lecture 9COMPSCI.220.FS.T Lower Bound for Sorting Complexity Each algorithm that sorts by comparing only pairs of elements must use at least 
Graphs and Trees Mathematical Structures for Computer Science Chapter 5 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesGraphs and Trees.
Sorting Lower Bounds n Beating Them. Recap Divide and Conquer –Know how to break a problem into smaller problems, such that –Given a solution to the smaller.
Chapter 11. Chapter Summary  Introduction to trees (11.1)  Application of trees (11.2)  Tree traversal (11.3)  Spanning trees (11.4)
1 Section 5.1 Analyzing Algorithms Let P be a problem and A an algorithm to solve P. The running time of A can be analyzed by counting the number of certain.
Trees Chapter 15.
Data Structure and Algorithms
Data Structures and Algorithms for Information Processing
Binary search tree. Removing a node
Trees.
Data Structures Using C++
CS202 - Fundamental Structures of Computer Science II
CS202 - Fundamental Structures of Computer Science II
Mathematical Structures for Computer Science Chapter 6
Quick-Sort 11/14/2018 2:17 PM Chapter 4: Sorting    7 9
(2,4) Trees (2,4) Trees 1 (2,4) Trees (2,4) Trees
Chapter 6 Transform and Conquer.
Quick-Sort 11/19/ :46 AM Chapter 4: Sorting    7 9
Set, Combinatorics, Probability & Number Theory
Comparison Sorting Elements are rearranged by comparing values of keys
Multi-Way Search Trees
CS202 - Fundamental Structures of Computer Science II
(2,4) Trees /26/2018 3:48 PM (2,4) Trees (2,4) Trees
CS200: Algorithm Analysis
(2,4) Trees (2,4) Trees (2,4) Trees.
Lecture 12 CS203 1.
Mathematical Structures for Computer Science Chapter 6
(2,4) Trees 2/15/2019 (2,4) Trees (2,4) Trees.
(2,4) Trees /24/2019 7:30 PM (2,4) Trees (2,4) Trees
Quick-Sort 2/23/2019 1:48 AM Chapter 4: Sorting    7 9
CS202 - Fundamental Structures of Computer Science II
(2,4) Trees (2,4) Trees (2,4) Trees.
CS202 - Fundamental Structures of Computer Science II
Data Structures Using C++ 2E
Chapter 11 Trees © 2011 Pearson Addison-Wesley. All rights reserved.
Chapter 11 Trees © 2011 Pearson Addison-Wesley. All rights reserved.
CS202 - Fundamental Structures of Computer Science II
CS210- Lecture 20 July 19, 2005 Agenda Multiway Search Trees 2-4 Trees
Presentation transcript:

Mathematical Structures for Computer Science Chapter 5 Graphs and Trees Mathematical Structures for Computer Science Chapter 5 Copyright © 2006 W.H. Freeman & Co. MSCS Slides Graphs and Trees

Decision Trees DEFINITION: DECISION TREE A decision tree is a tree in which the internal nodes represent actions, the arcs represent outcomes of an action, and the leaves represent final outcomes. The following figure represents the various possibilities for five coin tosses under the constraint that two heads in a row do not occur. Each internal node of the tree represents an action (a coin toss), and the arcs to the children of internal nodes represent the outcomes of that action (heads or tails). The leaves of the tree represent the final outcomes, that is, the different ways that five tosses could occur. Section 5.3 Decision Trees

Searching The binary search algorithm acts on a sorted list and distinguishes between three possible outcomes of the comparison: x = L[i]: algorithm terminates, x has been found x < L[i]: algorithm proceeds to the left half of the list x > L[i]: algorithm proceeds to the right half of the list Section 5.3 Decision Trees

Lower Bounds on Searching The number of nodes at each level in a full binary tree follows a geometric progression: 1 node at level 0, 21 nodes at level 1, 22 nodes at level 2, and so on. 1 + 2 + 22 + 23 ... 2d = 2d + 1  1 Any binary tree of depth d has at most 2d + 1  1 nodes. Any binary tree with m nodes has depth log m. THEOREM ON THE LOWER BOUND FOR SEARCHING Any algorithm that solves the search problem for an n-element list by comparing the target element x to the list items must do at least └log n┘ + 1 comparisons in the worst case. Since binary search does no more work than this required minimum amount, binary search is an optimal algorithm in its worst-case behavior. Section 5.3 Decision Trees

The binary search algorithm requires that data already be sorted. Binary Search Tree The binary search algorithm requires that data already be sorted. Arbitrary data can be organized into a structure called a binary search tree, which can then be searched using a different algorithm called, binary tree search. To build a binary search tree, the first item of data is made the root of the tree. Successive items are inserted by comparing them to existing nodes, beginning with the root. If the item is less than a node, the next node tested is the left child; otherwise it is the right child. When no child node exists, the new item becomes the child. Section 5.3 Decision Trees

Binary Search Tree Example The data items 5, 8, 2, 12, 10, 14, 9 are to be organized into a binary search tree. A binary search tree, by the way it is constructed, has the property that the value at each node is greater than all values in its left subtree (the subtree rooted at its left child) and less than all values in its right subtree. A binary tree search compares item x with a succession of nodes, beginning with the root. If x equals the node item, the algorithm terminates; if x is less than the item, the left child is checked next; if x is greater than the item, the right child is checked next. If no child exists, the algorithm terminates because x is not on the list. Section 5.3 Decision Trees

Sorting Decision trees can also model algorithms that sort a list of items by a sequence of comparisons between two items from the list. The internal nodes of such a decision tree are labeled L[i]:L[j ] to indicate a comparison of list item i to list item j. The outcome of such a comparison is either L[i] < L[j ] or L[i] > L[j ]. If L[i] < L[j ], the algorithm proceeds to the comparison indicated at the left child of this node; if L[i] > L[j ], the algorithm proceeds to the right child. If no child exists, the algorithm terminates because the sorted order has been determined. Section 5.3 Decision Trees

Sorting Example The figure below shows the decision tree for a sorting algorithm acting on a list of three elements. Section 5.3 Decision Trees

d = log p  log n! Lower Bound on Sorting A decision tree argument can also be used to establish a lower bound on the worst-case number of comparisons required to sort a list of n elements. The leaves of such a tree represent the final outcomes, that is, the various ordered arrangements of the n items. There are n! such arrangements, so if p is the number of leaves in the decision tree, then p ≤ n!. The worst case will equal the depth of the tree. But it is also true that if the tree has depth d, then p ≤ 2d: d = log p  log n! THEOREM ON THE LOWER BOUND FOR SORTING Any algorithm that sorts an n-element list by comparing pairs of items from the list must do at least ┌log n!┐ comparisons in the worst case. Section 5.3 Decision Trees