The BST can still store keys of the same value, in this case, we put a key that is less than a node to its left, and put a key that is greater than or equal to a node to its right. Here is the algorithm for inserting a new key z in to a binary search tree T : (a) We propose to improve Tree-Insert by testing before line 5 to determine whether z.key==x.key and by testing before line 11 to determine whether z.key==y.key. If equality holds, we implement one of the following strategies (a1 and a2). For each of the strategy (a1 and a2), find the asymptotic runtime of inserting n items with identical keys into an initially empty binary search tree. (The strategies are described for line 5, in which we compare the keys of z and x, and substitute y for x to arrive at the strategies for line 11.) (a1) Keep a list of nodes with equal keys at x, and insert z into the list. (a2) Randomly set x to either x.left or x.right. (Give the worst-case runtime and informally derive the expected runtime.) [Note: for (a1) and (a2), we are expecting the runtime represented as a function of n].

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

The BST can still store keys of the same value, in this case, we put a key that is less than a node to its left, and put a key that is greater than or equal to a node to its right. Here is the algorithm for inserting a new key z in to a binary search tree T :

(a) We propose to improve Tree-Insert by testing before line 5 to determine whether z.key==x.key and by testing before line 11 to determine whether z.key==y.key. If equality holds, we implement one of the following strategies (a1 and a2). For each of the strategy (a1 and a2), find the asymptotic runtime of inserting n items with identical keys into an initially empty binary search tree. (The strategies are described for line 5, in which we compare the keys of z and x, and substitute y for x to arrive at the strategies for line 11.)
(a1) Keep a list of nodes with equal keys at x, and insert z into the list.

(a2) Randomly set x to either x.left or x.right. (Give the worst-case runtime and informally derive the expected runtime.)
[Note: for (a1) and (a2), we are expecting the runtime represented as a function of n].

Algorithm 1: Tree-Insert(T, z)
1 y = NIL;
2
x T.root;
3 while x # NIL
4
5
6
7
8 z.parent = y;
9 if y==NIL
10
11 elseif z.key<y.key
12 y.left=z;
13 else y.right=z;
y=x;
if z.key<x.key
x = x.left;
else x = x.right
T.root = z; //tree T was empty
Transcribed Image Text:Algorithm 1: Tree-Insert(T, z) 1 y = NIL; 2 x T.root; 3 while x # NIL 4 5 6 7 8 z.parent = y; 9 if y==NIL 10 11 elseif z.key<y.key 12 y.left=z; 13 else y.right=z; y=x; if z.key<x.key x = x.left; else x = x.right T.root = z; //tree T was empty
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Types of trees
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education