Problem Description Using the binary search tree (BST) data structure, we can sort a sequence of n elements by first calling an insertion procedure for n times to maintain a BST, and then performing an INORDER-TREE-WALK on the BST to output the elements in sorted order. To insert a node, we've discussed the TREE-INSERT procedure in class (also from page 294 of the text- book). This TREE-INSERT procedure can actually be improved to reduce the number of key comparisons so that each node's key is compared with the new node's key for at most once during each insertion. For example, given the following BST,

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
Problem Description
Using the binary search tree (BST) data structure, we can sort a sequence of n elements by first calling an
insertion procedure for n times to maintain a BST, and then performing an INORDER-TREE-WALK on the
BST to output the elements in sorted order.
To insert a node, we've discussed the TREE-INSERT procedure in class (also from page 294 of the text-
book). This TREE-INSERT procedure can actually be improved to reduce the number of key comparisons
so that each node's key is compared with the new node's key for at most once during each insertion. For
example, given the following BST,
The improved insertion procedure will make
• 2 comparisons to insert a node with key = 1
• 3 comparisons to insert a node with key = 3
• 2 comparisons to insert a node with key = 8
5.
Program Requirements
In this programming assignment, you will implement in Java this sorting algorithm using BST, by using
the improved insertion procedure. Note that each node of a BST is an object containing four attributes:
key (for the value of an element), le ft (for its left child), right (for its right child), and p (for its parent).
Please add a static counter to track the number of key comparisons made by your algorithm. Your program
will output the following
1. The size of the input array,
2. The input array,
3. The list of array elements after sorting, and
4. The number of key comparisons made.
Testing
Run your program multiple times on different input arrays. You may try to define the input array using
random numbers and also try by assigning a particular number to each element. Try to answer the following
two questions:
Q1. If the array size n is fixed, what does a worst-case input array (resulting in the maximum total
number of key comparisons) look like?
Q2. If the array size n is fixed, what does a best-case input array (resulting in the minimum total number
of key comparisons) look like?
In particular, set n = 15. Run your program by creating a worst-case input array and a best-case input
array. For each case, include the following in the “README" file.
• Take a screenshot of your program's output;
• Draw the BST after all 15 keys are inserted.
Write your answers to Q1 and Q2 for general n as part of the summary of your testing results in the
"README" file.
Transcribed Image Text:Problem Description Using the binary search tree (BST) data structure, we can sort a sequence of n elements by first calling an insertion procedure for n times to maintain a BST, and then performing an INORDER-TREE-WALK on the BST to output the elements in sorted order. To insert a node, we've discussed the TREE-INSERT procedure in class (also from page 294 of the text- book). This TREE-INSERT procedure can actually be improved to reduce the number of key comparisons so that each node's key is compared with the new node's key for at most once during each insertion. For example, given the following BST, The improved insertion procedure will make • 2 comparisons to insert a node with key = 1 • 3 comparisons to insert a node with key = 3 • 2 comparisons to insert a node with key = 8 5. Program Requirements In this programming assignment, you will implement in Java this sorting algorithm using BST, by using the improved insertion procedure. Note that each node of a BST is an object containing four attributes: key (for the value of an element), le ft (for its left child), right (for its right child), and p (for its parent). Please add a static counter to track the number of key comparisons made by your algorithm. Your program will output the following 1. The size of the input array, 2. The input array, 3. The list of array elements after sorting, and 4. The number of key comparisons made. Testing Run your program multiple times on different input arrays. You may try to define the input array using random numbers and also try by assigning a particular number to each element. Try to answer the following two questions: Q1. If the array size n is fixed, what does a worst-case input array (resulting in the maximum total number of key comparisons) look like? Q2. If the array size n is fixed, what does a best-case input array (resulting in the minimum total number of key comparisons) look like? In particular, set n = 15. Run your program by creating a worst-case input array and a best-case input array. For each case, include the following in the “README" file. • Take a screenshot of your program's output; • Draw the BST after all 15 keys are inserted. Write your answers to Q1 and Q2 for general n as part of the summary of your testing results in the "README" file.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

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
  • SEE MORE 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