eturn -1 if item s is not ng: The BTNodeGen instance-method search(T s) in the class above is intended to return the depth of the data items in the tree if it is found, and r found in the tree. Given the tree below, show the output that will be produced if the main() fragment were run, assuming the tree, t, is the followi Output: Searching A at: Searching C at: Searching X at: Searching Et: "A" IN "B" "C" "D" "E" (depth 1) (depth 2) (depth 3)

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

What would be produced if the main fragment were run given the tree below

nswers/the-btnodegen-instance-method-searcht-s-in-the-class-above-is-intended-to-return-the-depth-of-th
it
eturn -1 if
The BTNodeGen<T> instance-method search(T s) in the class above is intended to return the depth of the data items in the tree if
item s is not found in the tree. Given the tree below, show the output that will be produced if the main() fragment were run, assuming the tree, t, is the followi
ng:
â
@2
F3
20
W...
S
Output:
Searching A at:
Searching C at:
Searching X at:
Searching E t:
T 3
$
4
#
R
2
E
Without actually re-writing the code, briefly describe two changes needed to make search(T s) give the correct output.
20
F3
۳
000
000
F4
Gill
ي
$
4
»DS F
54
5
%
DOO
R
"A" (depth 1)
"B" "C" (depth 2)
//
"D" "E"
(depth 3)
F4
%
€ 5
Gill
J.
F5
0
A
F5
T .... Y
។
G
MacBook Air
&
6 1 7 V8
ل
FÓ
ل ::
F6
H 1 J
44
F7
MacBook Air
&
غ
U ....
E
لد.
*
T. Y. U
A
[₂
AA
F7
|
*
DII
FB
ܚ ܘ
(
9
K
)
1
१
DD
F9
ن
)
0
DII
F8
6 77 V8 A 9
O [P] {
L
-.N
7
F10
( )
9
ك :
F9
9 E
0
+ 11
}
で
C[ C ] S
F10
is found, and r
F12
phone intervie
7/28/22, 1:00 F
-0.0
-N
0 [P]
て
dele
Ask a
answe
て
EE
F11
[
Transcribed Image Text:nswers/the-btnodegen-instance-method-searcht-s-in-the-class-above-is-intended-to-return-the-depth-of-th it eturn -1 if The BTNodeGen<T> instance-method search(T s) in the class above is intended to return the depth of the data items in the tree if item s is not found in the tree. Given the tree below, show the output that will be produced if the main() fragment were run, assuming the tree, t, is the followi ng: â @2 F3 20 W... S Output: Searching A at: Searching C at: Searching X at: Searching E t: T 3 $ 4 # R 2 E Without actually re-writing the code, briefly describe two changes needed to make search(T s) give the correct output. 20 F3 ۳ 000 000 F4 Gill ي $ 4 »DS F 54 5 % DOO R "A" (depth 1) "B" "C" (depth 2) // "D" "E" (depth 3) F4 % € 5 Gill J. F5 0 A F5 T .... Y ។ G MacBook Air & 6 1 7 V8 ل FÓ ل :: F6 H 1 J 44 F7 MacBook Air & غ U .... E لد. * T. Y. U A [₂ AA F7 | * DII FB ܚ ܘ ( 9 K ) 1 १ DD F9 ن ) 0 DII F8 6 77 V8 A 9 O [P] { L -.N 7 F10 ( ) 9 ك : F9 9 E 0 + 11 } で C[ C ] S F10 is found, and r F12 phone intervie 7/28/22, 1:00 F -0.0 -N 0 [P] て dele Ask a answe て EE F11 [
20
F3
000
000
F4
} // removeHelper
public BTNodeGen search(T d) {
// iterative search
// has side-effect of printing Found/Not Found info to screen
BTNodeGen<T> ptr = root;
int compare;
if (ptr == null)
• compare = 0;
else compare = d.compareTo(ptr.getData());
while (ptr != null && compare != 0) {
- if (compare < 0) {
}
else {
System.out.print(" left ");
ptr = ptr.getLeft();
if (ptr == null)
compare = 0;
else compare = d.compareTo(ptr.getData());
} // while
if (ptr == null)
else
System.out.print(" right ");
ptr = ptr.getRight();
System.out.println(" [Not Found!]");
System.out.println(" [Found!]");
return ptr;
} //search
// local data
protected BTNodeGen<T> root;
public static void main(String[] args) {
BSTGen<String> t = new BSTGen<String>();
t.add("a");
t.add("b");
t.add("x");
t.add("w");
t.add("z");
t.add("k");
t.display();
} // main
t.search("z");
t.remove("a");
} // BSTGen
t.display();
t.remove("x");
t.display();
F5
F6
AA
4
>
Page
3
>
Transcribed Image Text:20 F3 000 000 F4 } // removeHelper public BTNodeGen search(T d) { // iterative search // has side-effect of printing Found/Not Found info to screen BTNodeGen<T> ptr = root; int compare; if (ptr == null) • compare = 0; else compare = d.compareTo(ptr.getData()); while (ptr != null && compare != 0) { - if (compare < 0) { } else { System.out.print(" left "); ptr = ptr.getLeft(); if (ptr == null) compare = 0; else compare = d.compareTo(ptr.getData()); } // while if (ptr == null) else System.out.print(" right "); ptr = ptr.getRight(); System.out.println(" [Not Found!]"); System.out.println(" [Found!]"); return ptr; } //search // local data protected BTNodeGen<T> root; public static void main(String[] args) { BSTGen<String> t = new BSTGen<String>(); t.add("a"); t.add("b"); t.add("x"); t.add("w"); t.add("z"); t.add("k"); t.display(); } // main t.search("z"); t.remove("a"); } // BSTGen t.display(); t.remove("x"); t.display(); F5 F6 AA 4 > Page 3 >
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Mergesort
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