Only 4 parts can be solved at a time. Post remaining questions separately.
a. Assuming linked list at every index of the array
k mod 5 | Keys |
0 | 45->90 |
1 | 56->11 |
2 | 22 |
3 | 23->58->48 |
4 | 89 |
b. Average Comparisons= [(1+ 2) + (1+ 2) + 1+ (1+ 2 + 3) + 1]/9= 14/9
c. Worst Case comparison: 3 as maximum no. of keys are 3 in some index of the hash table (4 if NULL need to be visited)
d. Assuming sorting in ascending order and the smallest key is selected and put in the beginning.
After the first iteration:
11, 89,23, 58,22,56,45,48,90
After second iteration
11,22,23,58,89,56,45,48,90
After third iteration
11,22,23,58,89,56,45,48,90
After 4th iteration
11,22,23,45,89,56,58,48,90
After 5th iteration
11,22,23,45,48,56,58,89,90
After 6th,7th and last iteration, it remains same
11,22,23,45,48,56,58,89,90
JH: Student Name: 4) Given the following array, do the following (show all the work). A...
(g - 6 pts) Construct a hash table of the given array using a hash function H(K) = K mod 5. (h - 6 pts) For the hash table of (g), determine the average number of comparisons for a successful search and the worst case number of comparisons for an unsuccessful search. (i - 9 pts) Consider the elements of the array assigned to you are known only one at a time. Construct a sequence of priority queues (as max...
[12, 21, 12, 26, 11, 13, 26, 30, 12, 2, 3, 13] (d - 7 pts) For the binary search tree obtained in (c), determine the average number of comparisons for a successful search and the average number of comparisons for an unsuccessful search. (e - 7 pts) Use the sorted array of (b) to construct a binary search tree. (f - 7 pts) For the binary search tree obtained in (e), determine the average number of comparisons for a...
For the input 26, 56, 45, 17, 58, 80, 15. 16, 13, 39 and hash function h(k) = k mod 13 1) Construct the close hash table 2) Find the largest number of key comparisons in successful search in this table 3) Find the average number of key comparisons in successful search in this table
Question 10: Given an array of data: array1 10 5 15 2 7 21 Write the code for the selection sort to sort the data and draw a table showing how the data is sorted using selection sort. Write the code for Binary search algorithm to find the value 15 from the sorted array. Draw the tree diagram showing the binary search of the list.
4) [15 points total (5 points each)] Assume you are given a sorted array A of n numbers, where A is indexed from 1 up to n, anda number num which we wish to insert into A, in the proper sorted position. The function Search finds the minimum index i such that num should be inserted into Ali]. It searches the array sequentially until it finds the location i. Another function MakeRoom moves A[i], .., AIn] to Ali+1]...AIn+1] same sort...
C++ Sorting and Searching 1. Mark the following statements as true or false. a. A sequential search of a list assumes that the list elements are sorted in ascending order. b. A binary search of a list assumes that the list is sorted. 2. Consider the following list: 63 45 32 98 46 57 28 100 Using a sequential search, how many comparisons are required to determine whether the following items are in the list or not? (Recall that comparisons...
1. (10 pts) What is the order of each of the following tasks in the worst case (the worst case of the best algorithm for the task) (in Big-Oh notation)? • Searching a pointer-based link listed of n integers for a particular value. Answer: Searching a sorted array of n integers for a particular value. Answer: • Searching an unsorted array of n integers for a particular value. Answer: • Inserting a new value into a sorted array of n...
Consider an ordered array A of size n and the following ternary search algorithm for finding the index i such that A[i] = K. Divide the array into three parts. If A[n/3] > K. the first third of the array is searched recursively, else if A[2n/3] > K then the middle part of the array is searched recursively, else the last thud of the array is searched recursively. Provisions are also made in the algorithm to return n/3 if A[n/3]...
2.1 Searching and Sorting- 5 points each 1. Run Heapsort on the following array: A (7,3, 9, 4, 2,5, 6, 1,8) 2. Run merge sort on the same array. 3. What is the worst case for quick sort? What is the worst case time com- plexity for quick sort and why? Explain what modifications we can make to quick sort to make it run faster, and why this helps. 4. Gi pseudocode for an algorithm that will solve the following...
The name of the C++ file must be search.cpp Write a program that will read data from a file. The program will allow the user to specify the filename. Use a loop that will check if the file is opened correctly, otherwise display an error message and allow the user to re-enter a filename until successful. Read the values from the file and store into an integer array. The program should then prompt the user for an integer which will...