# 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.

1 Page

### lecture13

Course: CPSC 331, Fall 2009
School: Wilfrid Laurier
Rating:

Word Count: 798

#### Document Preview

Science Outline Computer 331 Binary Search Trees Insertion and Deletion 1 BST Insertion BST Deletion Case 1 Case 2 Case 3 Case 4 Complexity Discussion References 2 Mike Jacobson Department of Computer Science University of Calgary Lecture #13 3 4 Mike Jacobson (University of Calgary) Computer Science 331 Lecture #13 1 / 17 Mike Jacobson (University of Calgary) Computer Science 331 Lecture #13 2 /...

Register Now

#### Unformatted Document Excerpt

Coursehero >> Canada >> Wilfrid Laurier >> CPSC 331

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.
Science Outline Computer 331 Binary Search Trees Insertion and Deletion 1 BST Insertion BST Deletion Case 1 Case 2 Case 3 Case 4 Complexity Discussion References 2 Mike Jacobson Department of Computer Science University of Calgary Lecture #13 3 4 Mike Jacobson (University of Calgary) Computer Science 331 Lecture #13 1 / 17 Mike Jacobson (University of Calgary) Computer Science 331 Lecture #13 2 / 17 BST Insertion BST Insertion Insertion: An Example 6 A Recursive Insertion Algorithm // Non-recursive public function calls recursive worker function public void insert(E key, V value) { root = insert(root, key, Value); } protected bstNode<E,V> insert(bstNode<E,V> T, E newKey, V newValue) { if (T == null) else if (newKey.compareTo(T.key) < 0) else if (newKey.compareTo(T.key) > 0) else return T; } Computer Science 331 Lecture #13 3 / 17 Mike Jacobson (University of Calgary) Computer Science 331 Lecture #13 4 / 17 3 10 1 5 7 Idea: Nodes Visited (inserting 9): Start at 6 : Next node Next node Next node Mike Jacobson (University of Calgary) BST Insertion BST Insertion Analysis: Partial Correctness Prove that insert is partially correct for all trees T of height h. Base cases are correct (by inspection): empty tree replaced by new node containing newKey and newValue if T.key == newKey, a KeyFoundExcpetion is thrown Assume that the algorithm is correct for all trees of height h 1 : if newKey < T.key, key/value inserted in left subtree if newKey > T.key, key/value inserted in right subtree in either case, algorithm is called recursively on a subtree of height at most h 1 and new subtree is correct by assumption the new T is still a BST, because both children are BSTs and the new element was added to the correct subtree Mike Jacobson (University of Calgary) Computer Science 331 Lecture #13 5 / 17 Termination and Bound on Running Time Let hi denote the height of the subtree with root x at level i of the recursion. Consider the function f (i) = hi + 1 : Worst case running time is (h) : Mike Jacobson (University of Calgary) Computer Science 331 Lecture #13 6 / 17 BST Deletion BST Deletion Case 1 Deletion: Four Important Cases First Case: Key Not Found 6 6 3 10 3 10 1 5 7 1 5 7 Idea: Key is/has . . . 1 2 3 4 Not Found (Eg: Delete 8) At a Leaf (Eg: Delete 7) One Child (Eg: Delete 10) Two Children (Eg: Delete 6) Computer Science 331 Lecture #13 7 / 17 Nodes Visited (delete 8): Start at 6 : Next node Next node Next node Mike Jacobson (University of Calgary) Mike Jacobson (University of Calgary) Computer Science 331 Lecture #13 8 / 17 BST Deletion Case 1 BST Deletion Case 2 Algorithm and Analysis protected bstNode<E,V> delete(bstNode<E,V> T, E key) { if (T != null) { if (key.compareTo(T.key) < T.left 0) = delete(T.left, key); else if (key.compareTo(T..key) > 0) T.right = delete(T.right,key); else if ... // found node with given key } else throw new KeyNotFoundException(); return T; } Second Case: Key is at a Leaf 6 3 10 1 5 7 Idea: Nodes Visited (delete 7): Start at 6 : Next node Next node Mike Jacobson (University of Calgary) Computer Science 331 Lecture #13 10 / 17 Correctness and Efciency For This Case: tree is not modied if key is not found (base case will be reached) worst-case cost (h) (same as search) Mike Jacobson (University of Calgary) Computer Science 331 Lecture #13 9 / 17 BST Deletion Case 2 BST Deletion Case 3 Algorithm and Analysis Third Case: Key is at a Node with One Child 6 Extension of Algorithm: else if () 1 3 10 5 7 Correctness and Efciency For This Case: Idea: Nodes Visited (delete 10): Start at 6 : Next node Mike Jacobson (University of Calgary) Computer Science 331 Lecture #13 11 / 17 Mike Jacobson (University of Calgary) Computer Science 331 Lecture #13 12 / 17 BST Deletion Case 3 BST Deletion Case 4 Algorithm and Analysis Fourth Case: Key is at a Node with Two Children 6 Extension of Algorithm: else if (T.left == null) else if (T.right == null) Correctness and Efciency For This Case: Idea: Nodes Visited (delete 6): Start at 6 : 1 3 10 5 7 Mike Jacobson (University of Calgary) Computer Science 331 Lecture #13 13 / 17 Mike Jacobson (University of Calgary) Computer Science 331 Lecture #13 14 / 17 BST Deletion Case 4 Complexity Discussion Algorithm and Analysis Extension of Algorithm: else { More on Worst Case All primitive operations (search, insert, delete) have worst-case compl...

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:

Allan Hancock College - INFT - 73334
/* The program *//* To compile and run the program: cc pulse.c -o pulse ./pulse(See output!)*/#include &lt;stdio.h&gt;#include &lt;signal.h&gt;#include &lt;unistd.h&gt;#include &lt;stdlib.h&gt;int main(void){ int pid1; int pid2; pid1 = fork();
Wilfrid Laurier - CPSC - 331
Outline1 2Computer Science 331Asymptotic NotationProperties and Application Types of Asymptotic Notation Big-Oh Notation Big-Omega Notation Big-Theta Notation Little-oh Notation Little-omega Notation Useful Properties and Functions Recommended
ECCD - MATH - 1005
MATH 1005C Test 3March 9, 2007 [Marks] [2] Questions 1-4 are multiple choice. Circle the correct answer. Only the answer will be marked. 1. [ln(n)]2 = n n lim (a) 0 (b) 1 (c) (d) 1 2 (e) Does not existSolution: (a) [2]2. The sequence {rn } conv
Allan Hancock College - INFT - 73334
/* Week 9 Java Network Programming Example 1: This simple server accepts one connection and then echoes everything received on that connection back to the sender. You may run it as the follows: &gt;java STServer &lt;port&gt; &amp; (say port is 3456
Wilfrid Laurier - CPSC - 331
OutlineComputer Science 331Algorithms for Searching1The &quot;Searching&quot; Problem Unsorted Arrays Linear Search Sorted Arrays Linear Search Binary Search2Mike JacobsonDepartment of Computer Science University of Calgary 3Lecture #21Mike Jac
Wilfrid Laurier - CPSC - 331
OutlineComputer Science 331Abstract Data Types, Interfaces, and the Java Collections Framework1Abstract Data Types and Interfaces Abstract Data Types Interfaces Java Collections Framework Introduction to the Java Collections Framework Notes on
Allan Hancock College - INFT - 73334
/* TCPtecho.c - main, TCPtecho, reader, writer, mstime */#include &lt;sys/types.h&gt;#include &lt;sys/param.h&gt;#include &lt;sys/ioctl.h&gt;#include &lt;sys/time.h&gt;#include &lt;sys/socket.h&gt;#include &lt;errno.h&gt;#include &lt;unistd.h&gt;#include &lt;stdlib.h&gt;#include &lt;string.
ECCD - MATH - 1005
1. Let f (x) = series of f .MATH 1005B - Solutions 60; 1; 2 x &lt; 0 0x2 , and f (x + 2) = f(x) for all x. Find the FourierThe Fourier series of f , with L = 2, is given by 1 nx nx i a0 X h + an cos + bn sin ; 2 2 2 n=1 with bn dx 2 2 0 nx
Wilfrid Laurier - CPSC - 331
Outline1 2Computer Science 331Stacks Mike JacobsonDepartment of Computer Science University of CalgaryDefinition Applications Parenthesis Matching Evaluation of Recursive Programs Implementation Array-Based Implementation Linked List-Based Imp
ECCD - MATH - 3057
MATH 30571Homework 3(due at 10:35 am on November 10, 2006) Problems 1-8 are on integration, Tylor and Laurent series. Special instructions: provide intermediate derivations. Problem 1. Compute (a)z 2 - 3|z| + Im z dz where (t) = 2eit , 0 t
Allan Hancock College - INFT - 73334
/* This program shows how to start a thread in an object byimplementing the Runnable interface. */public class ThreadDemo implements Runnable { protected Thread execution; public void begin () { if (execution = null) { execution =
Wilfrid Laurier - CPSC - 331
Outline1Computer Science 331Introduction to Red-Black Trees2Definition Definition and Example of a Red-Black Tree Implementation Details Height-Balance Black-Height of a Node The Main Theorem: Worst Case Height Bound First Lemma: Bounding Size
ECCD - MATH - 5406
Carleton University School of Mathematics and Statistics MATH 5406: Partial Dierential Equations Winter 2005 FINAL EXAMINATION Date: 13 April 2005; 14:0017:00 This is a closed book exam. Notes, books, etc are not allowed. No calculators allowed. Y
Allan Hancock College - INFT - 73334
/* Create a pipe, which has 2 ends: read end and write end. * Create 2 processes: parent and child. Child will read * from the reading end, parent will send stuff down the * writing end of the pipe. * * No arguments to this program. */#includ
Wilfrid Laurier - CPSC - 331
OutlineComputer Science 331Getting from Pseudocode to a Bound on Running Time1Objective and Strategy Running Time for Various Kinds of Programs A Single Statement A Sequence of Subprograms A Conditional Statement A Loop A Nested Loop A Simple
ECCD - MATH - 3057
MATH 30571Homework 1(due at 10:35 am on September 29, 2006) Problems 1-10 are on algebra of the complex plane; Problems 11-14 are on topology of the complex plane. Special instructions: provide intermediate derivations. Problem 1. Express the fo
Allan Hancock College - INFT - 73334
/* TCPmtechod.c - threaded echo server * * Usage: TCPechod [port] */#include &lt;unistd.h&gt;#include &lt;stdlib.h&gt;#include &lt;stdio.h&gt;#include &lt;string.h&gt;#include &lt;pthread.h&gt;#include &lt;sys/types.h&gt;#include &lt;sys/signal.h&gt;#include &lt;sys/socket.h&gt;#incl
East Los Angeles College - MJ - 665
Deriving Specifications from Requirements: an ExampleMichael Jackson AT&amp;T Bell Laboratories and MAJ Consulting Ltd 101 Hamilton Terrace London NW8 9QX England jacksonma@attmail.att.com mj@doc.ic.ac.uk Pamela Zave AT&amp;T Bell Laboratories Room 2B-413 M
Wilfrid Laurier - CPSC - 331
Outline1The Dictionary ADT Binary Trees Definition Additional Terminology Relationship Between Size and Depth Binary Search Trees Definition Searching Finding an Element with Minimal Key ExerciseComputer Science 331Binary Search Trees: Definiti
ECCD - MATH - 3057
MATH 30571Homework 4(due at 10:35 am on November 24, 2006) Problems 1-5 are on the residues and 6-8 are on conformal mappings. Special instructions: provide intermediate derivations. Problem 1. Compute the residues of (a) z2 at z0 = 0; sin2 z (b
Wilfrid Laurier - CPSC - 331
Computer Science 331 - Fall 2008 Assignment #3InstructionsThis assignment concerns lecture material that was introduced in this course on or before Friday,October 17. Please read the entire assignment before you begin work on any part of it. This
Allan Hancock College - INFT - 11135
Chapter 3Web TechnologyWeb PublishingStatic documents HTML, ASCII text, Postscript, PDF GIF, JPEG, MOV, Quicktime, AVI AU, WAV, MP3, RealAudio executable content Java, Javascript, Active-X, Dynamic HTML Dynamically-generated (on-the-fly) C
ECCD - MATH - 1005
MATH 1005 - 2003 Exam Solutions1. (d) 2. (b) 3. (a) 4. (c) 5. (c) 6. (d) 7. (b) 8. (b) 9. (e) 10. (a) 11. (e) 12. (b) 13. (d) 14. (b) 15. (b) 16. (a) 17. (c) 18. (b) 19. (b) 20. (c) 21. (b) 22. (e) 23. (c) 24. (e) 25. (e) 26. (c)2 27. (e) 28. (d)
ECCD - MATH - 1005
MATH 1005C Test 1January 26, 2007 NAME: [Marks] [5] 1. Solve the initial-value problem 2y = cos(x) , y(0) = -2. y ID#:[6]2. Solve the initial-value problem y =x2 + y 2 , y(-1) = 2. xy2 [6] 3. Find the general solution of xy + 3y = x + 1.[6
Allan Hancock College - INFT - 11110
Week 7A Breather + A Start on ObjectsHalfway Through We are halfway through the course! You now know the basics of programming: basic data types operators and expressions assignment statements selection statements: IF .. ELSE loops: WHILE
ECCD - MATH - 5406
MATH 54061Homework 2(due at 11:35 am on February 6, 2007) Problem 1. Find where the following equation is elliptic, hyperbolic and parabolic: (l + x)uxx + 2xyuxy y 2 uyy = 0, l R. Solution. The determinant a2 a1 a2 is 12 a2 12 a1 a2 = y (x +
Allan Hancock College - INFT - 11110
INFT11-110 Software Development 1 INFT71-110 Programming ConceptsDr. Warren Toomey Faculty of Information Technology 051What to expect from this subjectThis is a preparatory subject for a University degree in Information Technology:The subject
ECCD - MATH - 5406
MATH 54061Homework 1(due at 11:35 am on January 23, 2006) Problem 1. Integrate the following Cauchy problem for the rst-order equation ut + uux + u = 0, u(x, 0) = f (x). Solution. With the usual notation q = ut and p = ux , the equation is q +u(
Wilfrid Laurier - CPSC - 331
Computer Science 331 Solutions to Selected Tutorial #3 QuestionsQuestionsConsider the following code segment: / Pre-condition: A is a non-null array of integers / that contains at least one element / Post-condition: max is the largest element in t
Allan Hancock College - INFT - 11135
Chapter 0The Big PictureInternet History1969: ARPA R&amp;D projectpacket-switching network robust reliable vendor-independent decentralized operation1975: experimental-&gt;operationalInternet History (cont'd) 1983: tcp/ip milit
ECCD - MATH - 5406
MATH 54061Homework 3(due at 11:35 am on March 13, 2007) Problem 1. Solve the boundary/initial value problem u 2u = k 2 , 0 &lt; x &lt; L, t &gt; 0, t x u(0, t) = A, u(L, t) = B, t &gt; 0, u(x, 0) = f (x), 0 &lt; x &lt; L, where A and B are constants. Solution: B
Wilfrid Laurier - CPSC - 331
Outline1Computer Science 331Proofs of Correctness of Algorithms2Denition and Motivation Denition Motivation Parts of a Proof Partial Correctness Termination Strategy and Examples Strategy Important Cases ReferencesMike JacobsonDepartment of
Allan Hancock College - INFT - 11135
Chapter 2Application ProtocolsDomain Name Servicedefines a hierarchical naming standard for the Internettop-level-domains (TLDs) &quot;old-style&quot; .com, .edu, .net, .mil, .gov ccTLDs .au, .us, .gb rumsti.com, com.au second-level-domains
ECCD - MATH - 1005
MATH 1005B - Solutions 4Find the general solution: 1. y 00 + 2x(y 0 )2 = 0. Since y does not appear explicitly in the equation, let z = y 0 . Then y 00 = z 0 , and the equation becomes z 0 + 2xz 2 = 0, which is rst-order and separable. Thus, Z dx 1
Wilfrid Laurier - CPSC - 331
THE UNIVERSITY OF CALGARY FACULTY OF SCIENCEFINAL EXAMINATION COMPUTER SCIENCE 331WINTER SESSION: LECTURE 02 April 20, 2007 Time: 2 hrs.NAME: Please DO NOT write your ID number on this page.Instructions:Answer all questions in the space prov
ECCD - MATH - 3057
MATH 30571Name: ID#:Test 2(November 17, 2006) Problem 1. Find the integral of f (z): (a)f (z) = ez , from z = 1 to z = i. Does the value of the integral depend on the path? Ans: I = ei e1 = 1 e and does not depend on the path. (b)f (z) = |z|
Allan Hancock College - INFT - 11135
Network Access and Transmission MethodsTan Alam School of IT Bond UniversityLAN TopologiesPhysical Topology the physical/geographical layout of the network or segment. Logical Topology how information flows on the networkPhysical Bus Topolo
Wilfrid Laurier - CPSC - 331
CPSC 331 - Term Test #2 Solutions November 19, 2008Name:Please DO NOT write your ID number on this page.Instructions: Answer all questions in the space provided. Point form answers are acceptable if complete enough to be understood. No Aids Allo
ECCD - MATH - 1005
MATH 1005B - Notes 5 Systems of EquationsA system of two, linear, homogeneous equations with constant coecients has the form x0 = ax + by y 0 = cx + dy; where a; b; c and d are constants, and x and y are functions of t. The system may be expressed i
Wilfrid Laurier - CPSC - 331
CPSC 331 Term Test #1 February 12, 2007Name:Please DO NOT write your ID number on this page.Instructions: Answer all questions in the space provided. Point form answers are acceptable if complete enough to be understood. No Aids Allowed. There
Allan Hancock College - INFT - 11135
THE OSI &amp; TCP/IP MODELSTan Alam School of IT Bond UniversityThe OSI ModelLinkhttp:/topicmaps.bond.edu.au/mda/i nternet/osimodel/@/users/rho/InTechI/Physical LayerProtocols at this layer generate and detect voltage (or in the case of f
East Los Angeles College - ARTICLE - 216
#!/bin/sh# we have less than 3 arguments. Print the help text:if [ \$# -lt 3 ] ; thencat &lt;HELPren - rename a number of files using sed regular expressionsUSAGE: ren 'regexp' 'replacement' files.EXAMPLE: rename all *.HTM files in *.html: ren
ECCD - MATH - 3057
MATH 3057: Functions of a Complex Variable Fall 2006 Instructor: Dr. Rouslan Krechetnikov Contact: Office: 2205 HP Phone: 520-2600, ext. 2141 E-mail: rkrechet@math.carleton.ca Office hours: TH 4:00-6:00 pm Website: http:/math.carleton.ca/~rkrechet/co
Wilfrid Laurier - CPSC - 331
Computer Science 331 - Fall 2008 Assignment #5InstructionsThis assignment concerns lecture material that has been introduced in this course on or before Monday, November 17. Please read the entire assignment before you begin work on any part of it
Allan Hancock College - INFT - 11135
Web TechnologyExtensible Markup Language XML (1998) is an application of SGML Standard Generalized Markup Language (1986): ISO8879 influenced by HTML (SGML Document Type Definifion) Structure description language Meta-language: language to
ECCD - MATH - 1005
MATH 1005B - Notes 1 Reduction of OrderConsider a linear, second-order, homogeneous equation in standard form, y 00 + p(x)y 0 + q(x)y 0 = 0: Suppose that one solution y1 is known. Then a second, independent solution y2 is obtained by letting y2 (x)
Wilfrid Laurier - CPSC - 331
Computer Science 331 Fall 2008 Assignment #4InstructionsThis assignment concerns lecture material that has been introduced in this course on or before Monday, October 27. Please read the entire assignment before you begin work on any part of it.
Allan Hancock College - INFT - 11135
Information SecurityRisk AssessmentA thorough analysis of an organization's vulnerability to security breaches and an identification of its potential losses. A risk assessment should answer the following questions: What resources or assets are at
ECCD - MATH - 1005
MATH 1005B - Problems 4Find the general solution: 1. y 00 + 2x(y 0 )2 = 0 2. yy 00 + (y 0 )2 = 0
Wilfrid Laurier - CPSC - 331
Computer Science 331 Solutions to Selected Tutorial #2 QuestionsQuestion 3Requirements specication for gcd method gcd(int a, int b) pre-condition: a and b are of type int responsibilities: compute the greatest common divisor of integers a and b
ECCD - MATH - 3057
MATH 30571Homework 4(due at 10:35 am on November 24, 2006) Problems 1-5 are on the residues and 6-8 are on conformal mappings. Special instructions: provide intermediate derivations. Problem 1. Compute the residues of (a) z2 at z0 = 0; sin2 z (b
Allan Hancock College - INFT - 11135
JavaScriptTan Alam School of IT Bond UniversityIntroduction JavaScript is used in millions of Web pages to improve the design, validate forms, and much more. JavaScript was developed by Netscape and is the most popular scripting language on the i
Wilfrid Laurier - CPSC - 331
Computer Science 331 Solutions to Selected Tutorial #5 QuestionsQuestion 1Use asymptotic notation to state bounds on the worst-case running times for the Bubble Sort and the gcd algorithms We have computed the number of operations for the worst-ca
ECCD - MATH - 1005
MATH 1005C Test 1 SolutionsJanuary 26, 2007 [Marks] [5] 1. Solve the initial-value problem 2y = cos(x) , y(0) = 2. ySolution: 2yy = cos(x) y 2 = sin(x) + c y = sin(x) + c. y(0) = 2 2 = c c = 4 y = sin(x) + 4. [6] 2. Solve the initial-valu
ECCD - MATH - 5406
MATH 5406: Partial Differential Equations Winter 2007 Instructor: Dr. Rouslan Krechetnikov Contact: Office: 2205 HP Phone: 520-2600, ext. 2141 E-mail: rkrechet@math.carleton.ca Office hours: TUE 4:00-6:00 pm Website: http:/math.carleton.ca/~rkrechet/
ECCD - MATH - 5406
MATH 54061Homework 1(due at 11:35 am on January 23, 2006) Problem 1. Integrate the following Cauchy problem for the rst-order equation ut + uux + u = 0, u(x, 0) = f (x). Problem 2. Obtain the complete integral of the following equation u2 + yuy
ECCD - MATH - 3057
MATH 30571Homework 3(due at 10:35 am on November 10, 2006) Problems 1-8 are on integration, Taylor and Laurent series. Special instructions: provide intermediate derivations. Problem 1. Compute (a)z 2 3|z| + Im z dz where (t) = 2eit , 0 t
Allan Hancock College - INFT - 11110
Semester 001 mid-term solutions Question 1 a) for (int i = 40; i &gt;= 0; i = i 10) listBox1.addItem(i); b) c) for (double i = 0.3; i &lt; 10 &amp; i &gt; -10; i = i * -2) listBox1.addItem(i); for (char c = `a'; c &lt;= `d'; c+) { listBox1.addItem(String.valueOf(c)
ECCD - MATH - 3057
MATH 30571Homework 2(due at 10:35 am on October 13, 2006) Problems 1-14 on series, dierentiation, and exponential (trigonometric) function. Special instructions: provide intermediate derivations. Problem 1. Do the following sequences converge, a
Allan Hancock College - INFT - 063
Lecturer: Assignment 3: Submitted by:Dr. Warren Toomey MyKea Network Ali Al Maktoum Almunther Al MaktoumContentsContents.i Sales Office LAN.1 The Sales Department:.2 The Office Department:.2 Summary.2 Management and Administration LAN Costs.4 Su
ECCD - MATH - 5406
MATH 54061Homework 3(due at 11:35 am on March 13, 2007) Problem 1. Solve the boundary/initial value problem u 2u = k 2 , 0 &lt; x &lt; L, t &gt; 0, t x u(0, t) = A, u(L, t) = B, t &gt; 0, u(x, 0) = f (x), 0 &lt; x &lt; L, where A and B are constants. Problem 2.