Homework 3: CS 425 Due Wednesday, March 4th 2020 1. In Lab 4, you developed a program to build a Max Heap, and then Heap Sort. Update the program by adding two additional functions: (a) AddData(A, N,...

1 answer below »
No reference style needed. Please ask Neha to give me a quote if he/she is able to complete the assignment. I can also provide class notes.


Homework 3: CS 425 Due Wednesday, March 4th 2020 1. In Lab 4, you developed a program to build a Max Heap, and then Heap Sort. Update the program by adding two additional functions: (a) AddData(A, N, V) where V is the new value added. (b) Delete a data Delete by giving the index of the data position Make sure to display the array after calling each of the function. 2. Write a program to implement Binary Search Algorithm, which will return the index of the data searched (V). The function will take the array A, size of array, N and a search key V as inputs and will return the data position number. If the data is not found, it will return -1. Call this function from main, and try searching for various data. 3. Given the following data: 1, 4, 7, 12, 20, 34, 56, 60, 71, 82, 90, 111, 124, 156 Illustrate how will you search for the following values, and how many searches will be required for each of them, when you use Binary Search Algorithm. a) V = 200 b) V = 12 c) V = 90 4. a) Construct a Binary Search Tree using the following data: 45, 34, 12, 67, 50, 30, 8, 61, 24 b) Now illustrate how you will find out 24 from the tree, and how many searches will be needed. c) Give the inorder, preorder and post order tree traversal sequences. d) Illustrate how you will delete the root, and reconstruct the binary search tree. 5. A C++ program is kept in blackboard to implement Binary Search Tree. You are required to run that by adding at least 10 random data, then display the tree and draw in a piece of paper. There is a function kept in this program which is not utilized. Try calling this function suitably to search for a data. The program is called BinarySearchTree.cpp
Answered Same DayApr 28, 2021

Answer To: Homework 3: CS 425 Due Wednesday, March 4th 2020 1. In Lab 4, you developed a program to build a Max...

Pushpendra answered on Apr 30 2021
130 Votes
1.
a.
Initial Heap array is : 45, 34, 25, 12, 13
Operation Insert: 20
Now array is : 45,34,25,12,13,20
I 1 2 3 4 5 6 Runtime Explanation of Algorithm

A[I] 45 34 25 12 13 20 1 Apply Bottom-up approach
MaxHeapify(6)
Cycle 1 45 34 25 12 13 20 1 Parent Node=6/2=3
A[3]>A[6], So stop here.
Max Heap is: 45, 34, 25, 12, 13, 20 Total runtime= 2
45
34 25
12 13
45
34 25
12 13 20
b.
Array : 45, 34, 25, 12, 13, 20
Delete at Position 3
I 1 2 3 4 5 Runtime Explanation of Algorithm
A[I] 45 34
(I)
20 12
(L)
13
(R)
N = 6, I = N/2 = 2
MaxHeapify(2)
Cycle 1 45 34 20 12 13 2 I=2, L=4, R=5
Check largest children, between A[L] and A[R],
A[R] is largest, check if A[5] > A[2], swap them,
and MaxHeapify(5), and if A[5]here.


45 34 20 12 13
Max Heap is: 45, 34, 20, 12, 13 Total runtime= 2
2.
Array : 16, 34, 8 , 20, 5
Insert 16 as a root
Insert 34: 34<16(Insert in right)
45
34 20
12 13
16,1
Insert 8: 8<16 (Insert in left)
Insert 8: 20>16 (Insert in Right of 16)
20<34(Insert in left of 34)
Insert 5: 5<16 (Insert in Left of 16)
5<8 (Insert in left of 8)
16,1
34,2
16,1
8,3 34,2
16,1
8,3 34,2
20,4
16,1
8,3 34,2
5,5 20,4
Search 38;
1st Cycle : 38>16 so search in right sub-tree
2nd-Cycle: 38>34 so search in right sub-tree
There is no any subtree so data not found.
Search 8:
1st- Cycle: 8<16 so search in left sub-tree
2nd-Cycle: 8==8, So data found at position 2
3.
1, 4, 7, 12, 20, 34, 56, 60, 71, 82, 90, 111, 124, 156

I start searching from the middle data. If...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here