# Register now to access 7 million high quality study materials (What's Course Hero?) Course Hero is the premier provider of high quality online educational resources. With millions of study documents, online tutors, digital flashcards and free courseware, Course Hero is helping students learn more efficiently and effectively. Whether you're interested in exploring new subjects or mastering key topics for your next exam, Course Hero has the tools you need to achieve your goals.

21 Pages

### wk8_trees

Course: CSC 148, Fall 2009
School: University of Toronto
Rating:

Word Count: 1576

#### Document Preview

tree TREES 1 Trees A is a restricted form of graph. It has a nite set of nodes and edges. But the edges have a direction (from parent node to child node), and a non-empty tree must satisfy the following rules: 1. One of the nodes is special the root. Every non-empty tree has a unique root. 2. Each node has exactly one parent, except the root, which has none. 3. Each node is connected to the root by a unique...

Register Now

#### Unformatted Document Excerpt

Coursehero >> Canada >> University of Toronto >> CSC 148

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
tree TREES 1 Trees A is a restricted form of graph. It has a nite set of nodes and edges. But the edges have a direction (from parent node to child node), and a non-empty tree must satisfy the following rules: 1. One of the nodes is special the root. Every non-empty tree has a unique root. 2. Each node has exactly one parent, except the root, which has none. 3. Each node is connected to the root by a unique path from the root to that node. 4. There are no cycles, that is no paths that form loops through two or more nodes. Also, the children in our trees are ordered; some people call such trees ordered trees. 2 About the diagram: One draws trees upside-down. The arrows indicate the parent-child relationship: they arent necessarily object references. Crunchy nugget: The rst two properties are sucient to dene a tree, since together they imply the third. Questions: Can you prove this? Are any other subsets of these properties sucient? 3 Denitions A node with no children is called a leaf. A node that is not a leaf is an internal node. Thus, the root is internal unless it is the only node, and a node with just one child is internal. Nodes with the same parent are siblings. The tree formed from a node together with all its descendants and the edges among them is a subtree. If m1 is the parent of m2 , m2 is the parent of m3 , . . ., and mk1 is the parent of mk , then the sequence of nodes m1 , m2 , . . . , mk is a path in the tree. The length of such a path is k 1, i.e., the number of edges on the path. The height of a tree is the length of its longest path from the root to a leaf. The depth of a node is its distance from the root: the number of edges on the path from the root to that node. The depth of the root is 0. 4 Special Kinds of Trees A tree may have a xed branching factor: a maximum number of children for any node. A binary tree has branching factor 2. Operations on trees include inserting a new node removing a node traversing a tree: visiting the nodes in some order and doing something at each, e.g., printing its label attaching a new subtree at a given node removing a subtree A tree can be implemented many ways, not necessarily with node objects and references. For now, think of it abstractly. 5 Uses of Trees Trees can be used to represent things that are in some hierarchical relationship: some family relationships, e.g. father-of. Question: what about parent-of? The class inheritance hierarchy in Java. Which directories occur inside which others in a computer le system. The relationship between method calls and their arguments. Example: a( b(c()), d(), g(h(), i()) ) The relationship between operations and operands in an arithmetic expression. Example: 3 + (4 (6 8)) + (25/2). + + 3 4 6 * 8 25 / 2 6 Binary Search Trees A binary search tree (or BST) is a binary tree where the nodes are labelled, and each nodes label is: greater than the labels of all the nodes in its left subtree, and less than the labels of all the nodes in its right subtree. Any subtree of a binary search tree is a binary search tree. Question: Is it sucent to only require that a nodes label is greater than the left childs and less than the right childs? 7 An Example of a BST 100 50 111 22 78 103 115 6 38 66 89 102 108 114 59 70 82 95 101 104 110 107 Question: Is the above BST the only way to store those elements in a BST? Question: How would you search in a BST? 8 A BST combines the best features of an array and a linked list: Because it is ordered, one can use an ecient search strategy analogous to binary search in a sorted array. But it is dynamic like a linked list, so it can grow and shrink in size easily. Question: Why not just use a sorted linked list? 9 Eciency of BST Operations BST search seems to be ecient because, like binary search, it allows us to disregard a lot more of the problem every time we go down a level in the tree. But we may get to disregard a lot or a little, depending on the shape of the tree. Think of some examples. In fact, the eciency of the operations depends on the height of the tree. What do we know about a trees height? . . . 10 Height Binary of Trees What is the maximum height of a binary tree with n nodes? What is the minimum? What kind of tree has the minimum height? 11 Height maximum number of nodes Let M (h) represent the maximum number of nodes in a binary tree of height h. Prove: For all h 0, M (h) = 2h+1 1. Base Case: Prove that M (0) = 20+1 1. A binary tree with height 0 has one node, so M (0) = 1. And 20+1 1 = 2 1 = 1. 12 Let k 0 be an arbitrary integer. Induction Hypothesis: Assume that for all 0 i k, M (i) = 2i+1 1. Induction Step: Prove that M (k + 1) = 2k+2 1. Let T be any binary tree of height k + 1. Let L and R be the two (possibly empty) subtrees of the root. Clearly, the maximum number of nodes in T , namely M (k + 1), is just 1 (for the root) plus the maximum number of nodes in L and R. But T has height k + 1, so L and R have height k. (The proof of this is left to reader.) So the IH applies to both L and R. As a result: M (k + 1) = 1 + 2 M (k) = 1 + 2 (2k+1 1), by the IH = 1 + 2k+2 2 = 2k+2 1. Conclusion: For all h 0, M (h) = 2h+1 1. 13 Number of nodes minimum height Let n be the number of nodes in some binary tree of height h. We proved that the maximum number of nodes in such a tree is 2h+1 1. So: n 2h+1 1 n + 1 2h+1 log2(n + 1) h + 1 h log2(n + 1) 1 The minimum height of a binary tree is then O(log n). 14 Eciency of Search in a BST The height of a BST containing n nodes varies from log2(n + 1) 1 to n 1. So the number of steps required to search a BST with n nodes varies from log2(n + 1) like binary search to n like linear search, depending on the shape of the tree! We can keep a BSTs height on the order of log2 n by careful rearrangement during insertion and deletion. And there are ways to do this without making insertion and deletion take much longer. However, we dont cover this in our course. 15 Abstraction again Weve gured out a lot about trees without ever seeing an implementation. Weve talked completely in terms of the abstract notion of a tree. Question: Why is this a good thing? Now on to implementations . . . 16 Implementing Trees Using References Intuitive implementation: each node is an object, and each edge is a reference. (There are still other decisions, such as how to represent the list of edges from a node to its children.) Using Arrays Question: How can you represent a tree using an array? 17 ADT or Data Structure The tree can be viewed as either an ADT, or a data structure. Example: A tree can be no more tha...

Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

East Los Angeles College - EG - 2116
Journal of Arid Environments (2002) 50: 413428 doi:10.1006/jare.2001.0909, available online at http:/www.idealibrary.com onNebkha dunes in the Molopo Basin, South Africa and Botswana: formation controls and their validity as indicators of soil degradatio
Weber - ENGR - 2250
Laboratory 8Pre-Engineering 2250RLC Transient CircuitsPurpose:Introduce RLC circuits to develop a familiarity with rise time, overshoot, and settling time.Equipment and Components: Prototyping board, Multimeter, Signal Generator, Oscilloscope. Resis
Georgia Tech - ECE - 4006
Surface Mount 1% &amp; 5% Thick Film Chip ResistorsDESCRIPTION: The resistors are constructed on a high grade ceramic body (aluminum oxide). Internal metal electrodes are added at each end and connected by a resistive paste which is applied to the top surfac
East Los Angeles College - CS - 285
stpBA StoryboardingstpBA Storyboarding allows a business analyst or analyst developer to storyboard and validate requirements through GUI Storyboarding. The tool generates screen flow diagrams, HTML storyboards, specifications and test scripts. This tuto
Washington University in St. Louis - ECON - 504
Econ 504 (2009) Microeconomics IIHaluk Ergin &amp; David Levine Optimal AuctionsThe Envelope Theorem Source: Milgrom and Segal (2002)The Envelope TheoremLet A be an arbitrary set with generic element A. Let x, y denote generic elements of [0, 1]. Given a
UCSB - ESM - 219
Numbers in Microbiology NOTE: see references provided for original citations for each of these numbers. I. (Moat and Foster &quot;Microbial Physiology&quot;, 3rd ed., 1995 pg 11.) E. coli reproduces once every 40 minutes Dry weight of an average cell is 2.5 x 10-13
Intermediate Mathematical Physics I Physics/Math 5030 Fall 2008 Instructor: Prof. Mike Ritzwoller, 303-492-7075, F721 Gamow Tower. Email: ritzwoller@ciei.colorado.edu Text: Mathematical Methods for Physics and Engineering (Riley, Hobson, Bence) Time: MWF
University of Toronto - STA - 302
64.0 4.0 2.0 73.0 4.0 4.0 61.0 4.0 2.0 76.0 4.0 4.0 72.0 6.0 2.0 80.0 6.0 4.0 71.0 6.0 2.0 83.0 6.0 4.0 83.0 8.0 2.0 89.0 8.0 4.0 86.0 8.0 2.0 93.0 8.0 4.0 88.0 10.0 2.0 95.0 10.0 4.0 94.0 10.0 2.0 100.0 10.0 4.0
Charleston Law - HOME - 295
GNU Emacs Reference Card(for version 20)Motionentity to move over character word line go to line beginning (or end) sentence paragraph page sexp function go to buer beginning (or end) scroll scroll scroll scroll scroll to next screen to previous screen
Lake County - CI - 430
Each sample below respresents a set of student test data. Choose the measure of central tendency that you believe would be most helpful in thinking about how the class as a whole performed. Justify your answer. 60 60 60 60 70 70 79 79 79 80 58 59 60 61 6
East Los Angeles College - RL - 011019
19 october 2001One computing centre for IN2P3-CNRS &amp; DSM-CEA 45 people National : 18 laboratories, 40 experiments, 2500 people International : Tier-1 / Tier-A status 0,5 PBytes Data Bases, Hierarchical storageBudget: ~ 6-7 M Euros/year Plus ~ 2 M for pe
East Los Angeles College - RL - 020621
CCIN2P3 Tier A StatusDominique Boutigny LAPP CNRS/IN2P3BaBarGrid Meeting Ferrara June 21, 2002Tier A Usage (1) High activity between November and February then very quiet for 2 month and ramping up again in May (up to 4850 jobs in queue last week) In
Purdue - ASM - 345
ELECTRO-PROPORTIONAL VALVESDIRECTIONAL CONTROLSP10-47C Spool, 4-Way, 3-Position, Closed CenterDESCRIPTIONA proportional solenoid-operated, 4-way, 3-position, spool-type, closed center, screwin hydraulic cartridge valve.OPERATIONWhen de-energized, the
Purdue - ENGR - 116
Name:_(PRINT - Last Name, First Name, MI)Lab Section: _ Team Number: _ ENGR 126H Fall 2007 PRACTICAL EXAM 21. The test duration is 110 minutes; any material submitted after the allotted time has expired will NOT be accepted. 2. Save all your work in yo
Purdue - ECE - 468
Purdue - ECE - 468
Purdue - ECE - 468
Allan Hancock College - ELEC - 5514
MPLAB C18 C COMPILER USER'S GUIDE 2005 Microchip Technology Inc.DS51288JNote the following details of the code protection feature on Microchip devices: Microchip products meet the specification contained in their particular Microchip Data Sheet. Microc
Purdue - ECE - 468
The latest research indicates using a combination of biometric avenues for human identification is more effective, and far more challenging.Multibiometric SystemsBY ANIL K. JAIN AND ARUN ROSSTraditionally, passwords (knowledge-based security) and ID c
University of Hawaii - Hilo - GG - 410
Tips for Preparing and Delivering Scientific Talks and Using Visual AidsCONTENTSq q qqqqqIntroduction The Commitment Preparation r Assessing the Audience r Fitting Into the Program r Content r Drafting the Talk r Death (or Worse) to Those Who Run O
Mich Tech - CS - 6461
Reputation Management in P2P SystemsPradipta Mitra Nov 18, 20031We will look at .Overview of P2P Systems Problems in P2P Systems Reputation Management Limited Reputation Sharing Simulation Results Global Reputation Sharing 2P2P SystemsIndividual C
Weber - ENGR - 2250
Laboratory 7Pre Engineering 2250RC and RL circuitsPurpose:Introduce students to the behavior of circuits made up of resistors and inductors.Equipment and Components: Prototyping board, Multimeter, Power supply, Signal Generator, Oscilloscope Resisto
stonybrook.edu - MAT - 118
Stu from MAT118 that you know but dont need to memorize The winner of a plurality election receives the most rst-place votes. In the Borda count, points given based on rst choice, second choice, etc. In Instant Runo (or plurality with elimination), candi
Rose-Hulman - CHEM - 270
Page 1 of 1McLean, Howard LFrom: Sent: To: Cc: Subject: McLean, Howard L Friday, March 09, 2007 4:48 PM Ceravolo, Paul N McLean, Howard L Chem270 Introduction to RocksAttachments: Appedix IV Properties of most common minerals.pdf Paul Identity the thre
University of Colorado Denver - MATH - 077
MATH 1401R04 Recitation Tuesday &amp; Thursday 12:00 pm.12:50 pm Room: LM127Teaching Assistant: Yongxia Kuang InClass Instructor: Gary OlsonOffice: CUDenver Building, 6th Floor Room 629 Phone: 3035566267 Email Address: yongxia.kuang@mail.cudenver.edu MERC
University of Colorado Denver - MATH - 1401
MATH 1401- 4: Calculus I. Topics include: Limits, Differentiation and Integration. Required text: Smith and Minton, Calculus: Concepts and Connections, McGraw Hill, 2006, ISBN: 0-07-282623-1. If you purchased your test book new, an access code for MathZon
University of Colorado Denver - MATH - 077
University of Colorado Denver - MATH - 067
University of Colorado Denver - MATH - 061
University of Colorado Denver - MATH - 061
University of Colorado Denver - MATH - 061
University of Colorado Denver - MATH - 061
University of Colorado Denver - MATH - 057
University of Colorado Denver - MATH - 057
University of Colorado Denver - MATH - 057
East Los Angeles College - BSC - 3101
%!PS-Adobe-2.0 %Creator: dvipsk 5.58f Copyright 1986, 1994 Radical Eye Software %Title: primer.dvi %Pages: 39 %PageOrder: Ascend %BoundingBox: 0 0 612 792 %EndComments %DVIPSCommandLine: dvips -o primer.ps primer %DVIPSParameters: dpi=600, compressed, com
University of Colorado Denver - MATH - 054
MIT - M - 060
~ MOTOROLA MICROPROCESSOR &amp; MEMORY TECHNOLOGY GROUP M68000 Hi-Performance Microprocessor Division M68060 Software Package Production Release P1.00 - October 10, 1994 M68060 Software Package Copyright 1993, 1994 Motorola Inc. All rights reserved.THE SOFTW
University of Illinois, Urbana Champaign - M - 122
Math 122Test 2 Version 1Fall 2008Name Seat # Do not open this test booklet until told to do so. Turn o all cell phones. For multiple-choice questions, precisely one answer is correct. Circle this correct answer. For all other questions, you must show
Iowa State - HON - 322
Lake County - CS - 273
CS 273: Intro to Theory of Computation, Spring 2007 Solutions for Problem Set 11. Here are state diagrams for three DFAs. Specify exactly what set of strings each accepts, using good mathematical notation. Briey explain why the DFA accepts this set of st
UC Riverside - CS - 120
Lab 7 Designing Sequential CircuitsObjectives To get familiar with the Xilinx Schematic Editor Tool. To get familiar with the Xilinx Simulation Tool. To design and implement simple combinational logic circuits using the Schematic Editor and Simulator. To
Georgia Tech - ECE - 3025
ECE 3025: Electromagnetics Solutions to TEST 2 (Fall 2006)(1) Short Answer Section (a) dot product (b) conductor (1) dielectric (2) series resistance (2)(c) shunt conductance (1) (2) Vector Math: The answer is given below(B - A) (C - A) Of course, ther
Kansas State University - D - 644
OMG Unified Modeling Language SpecificationVersion 1.3, June 1999Copyright 1997, 1998, 1999 Object Management Group, Inc. Copyright 1997, 1998, 1999 Hewlett-Packard Company Copyright 1997, 1998, 1999 IBM Corporation Copyright 1997, 1998, 1999 ICON Compu
Maryland - EDMS - 657
EDMS 657 Assignment 3: Principal axis factoring with oblique rotation (Part A) and ordinal factor analysis (Part B)Grading: This assignment is worth a total of 25 points. Format: Neatly handwritten work is acceptable. Show all work and explain answers wh
Paradise Valley Community College - PSY - 240
PSY 240 Aging Across CulturesParadise Valley Community College Phoenix, ArizonaAging Across Cultures I. Basic Concepts on Aging 1. Chronological aging represents only an approximate measure of the normative development or changes within an individual or
Paradise Valley Community College - IBS - 154
IBS 154 Pacific Rim Countries International Business Development Dianna LastParadise Valley Community College Phoenix, ArizonaSYLLABUS COURSE: IBS 154 Pacific Rim Countries: International Business Environment xxxxxSECTION: ROOM: xxxxx MEETS: xxxxxxxx,
Paradise Valley Community College - OAS - 125
OAS 125 The Professional Office International Business Etiquette Unit Paradise Valley Community College Phoenix, ArizonaThis unit has been developed for OAS 125 - The Professional Office. It is designed to help the student develop an awareness of interna
Paradise Valley Community College - HIS - 104
From &quot;Big Stick&quot; to &quot;Dollar&quot; to &quot;Missionary&quot; Diplomacy: The Hunt for Consistency in United States Foreign Policy in Mexico 1908-1916Internationalization of the Curriculum ModulePrepared by: Jim Barrett History 104 Paradise Valley Community College Phoen
Paradise Valley Community College - ENH - 110
International curriculum Module Development Module: The Poetry and Prose of Octavio Paz: An OverviewLois Roma-Deeley Spring 1997Paradise Valley Community CollegePhoenix, Arizona(writings) have on contemporary American literature; and/or the effect int
Dallas - PDFS - 200609
22G lo ba l P o l i t i c sSeptember 2006 Volume 3ISSue 1Terror failed: Im gellinAppreciate successes instead of harping on security inconveniencessurveillance and inside operations led the organization to arrest 7 men in Miami accused of attemptin
Dallas - PDFS - 200811
A M o d e s t P ro P o s A lG lo ba l P o l i t i c s15Poli-tick tockTime is running out for the Republican PartyEven the conservative media is hopping on the Obama bandwagon. The Chicago Tribune is backing a Democrat (Obama) for the first time in th
University of Florida - EML - 4314
EML 4314C Controls Design Laboratory Filter Frequency Response Objective The objective of this experiment is to determine the frequency response of a low-pass filter. Theoretical Background Low-pass filters are used to remove unwanted high-frequency noise
Penn State - RER - 198
A TYPOLOGY OF MULTI-SCALE MAPPING OPERATORSdeveloping a comprehensive list of available multi-scale mapping operators for the ScaleMaster diagram CONTEXT: multi-scale mappingMulti-scale mapping describes the cartographic practice of producing integrated
East Los Angeles College - EC - 501
The Subjective Approach to Ambiguity: A Critical AssessmentNabil I. Al-Najjar, and Jonathan WeinsteinFirst draft: September 2008; This version: October 8, 2008Abstract We provide a critical assessment of the (subjective) ambiguity literature, which we
Alaska Anch - ECON - 210
SCIENCES COMPASSREVIEW: ECOLOGYREVIEWAndrew Balmford,1* Aaron Bruner,2 Philip Cooper,3 Robert Costanza,4 Stephen Farber,5 Rhys E. Green,1,6 Martin Jenkins,7 Paul Jefferiss,6 Valma Jessamy,3 Joah Madden,1 Kat Munro,1 Norman Myers,8 Shahid Naeem,9 Jouni
University of Hawaii - Hilo - FILES - 225
Philippine Language (620)University of Hawaii at Mnoa College of EducationBachelor of Education in Secondary Education Core RequirementsSocial Science (DS) (2 courses 6 credits) CHOOSE TWO DEPTS. AND SELECT ONE COURSE FROM EACH DEPT. (see UHM Catalog o
Allan Hancock College - USA - 1903
Hillquit: Disintegration of the SLP and Establishment of the SPA [Oct. 1903]1The Disintegration of the SLP and the Establishment of the Socialist Party of America.by Morris HillquitA section from his book History of Socialism in the United States. (Ne
Cal Poly - STAT - 252
Quiz 1Stat 252 Spring 2008ReinHow much more expensive are four bedroom homes than three bedroom homes? Minitab was used to summarize data on the prices of three and four bedroom homes in San Luis Obispo County in 1998 and to calculate a 95% confidence
Wisconsin - CS - 537