Given the following array of integers (of capacity 20) with 12 items:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
8 | 4 | 10 | 15 | 5 | 7 | 11 | 3 | 9 | 13 | 1 | 6 |
Index of last element = 11
Does this array represent a min heap? If not, convert it to a min heap (i.e., “heapify” it). Please show all steps.
Answer)
The original array given is like:
8,4,10,15,5,7,11,3,9,13,1,6
The index of the last element is 11.
The array does not represent the min heap since the minimum element is not at the top.
We can convert the above array to the min heap to the below array:
1,3,6,5,4,7,11,15,9,13,8,10
We can build the min heap tree by converting the tree into min heap:
**Please Hit Like if you appreciate my answer. For further doubts
on the or answer please drop a comment, I'll be happy to help.
Thanks for posting.**
Given the following array of integers (of capacity 20) with 12 items: 0 1 2 3...
Tree & Hash Table & Heap Use the following integer keys 73, 58, 91, 42, 60, 130, 64, 87 to perform the followings: a) Binary Search Tree - Draw a binary search tree - Retrieve the integers keys in post-order - Retrieve the integers keys in pre-order - Draw a binary search tree after node 58 is deleted b) Create a Hash Table using the methods described below. Show the final array after all integer keys are inserted. Assumes that...
You are given an array containing integers in the sorted order: [O] [1] [2] [3] [4] [5] [6] [7] 6 9 17 29 33 41 58 61 [8] [9] [10] [11] [12] [13] 67 87 93 112 118 145 We want to find 12 in the given array, using binary search algorithm. The first comparison will be made with ----- 6 58 61 None. 12 is not in the array.
Tree & Hash Table & Heap Use the following integer keys 73, 58, 91, 42, 60, 130, 64, 87 to perform the followings: a) Binary Search Tree - Draw a binary search tree - Retrieve the integers keys in post-order - Retrieve the integers keys in pre-order - Draw a binary search tree after node 58 is deleted b) Create a Hash Table using the methods described below. Show the final array after all integer keys are inserted. Assumes that...
Write a C++ function, smallestIndex, that takes as parameters an int array and its size and returns the index of the first occurrence of the smallest element in the array. To test your function, write a main that prompts a user for a list of 15 integers and outputs the index and value of the first occurrence of the smallest value. The program should print out Enter 15 integers: The position of the first occurrence of the smallest element in...
Write a program that asks the user to input 10 integers of an array. The program then inserts a new value at position (or index) given by the user, shifting each element right and dropping off the last element. For example, in the sample input/output below, the program will insert the value 30 at index 3. All the previous numbers of the array starting from position 3 (i.e., 7 1 20 9 23 8 22 will be shifted one position...
PROGRAM DESCRIPTION Using the given class definitions for either C++, create a minimum heap that stores integers and and implements a minimum priority queue. (Your program can be "hard coded" for integers - it does not need to use templates, generics, or polymorphism.) Your data structure must always store its internal data as a heap. Your toString function should return a string with the heap values as a comma separated list, also including the size of the heap as well....
Please write in C# Write a method in C# int[]GetDuplicatesIndices(int[]array), which takes an array of integers and returns an array that holds the indices of all the duplicates. Example if the array has the following value 10, 5, 3, 7, 5, 11, 15, 13, 11, 6, 3, 19 then note that the value 5 has duplicate at index 4, value 3 has a duplicate at index 11, and value 7 has a duplicate at index 6. So the method should...
(20 points) You are given an array A of distinct integers of size n. The sequence A[1], A[2], ..., A[n] is unimodal if for some index k between 1 and n the values increase up to position k and then decrease the reminder of the way until position n. (example 1, 4, 5, 7, 9, 10, 13, 14, 8, 6, 4, 3, 2 where the values increase until 14 and then decrease until 1). (a) Propose a recursive algorithm to...
This question is about the min-heap. A min-heap with 10 elements is given in the following array format. The following three sub-questions all refer to this min-heap i 1 2 3 4 5 6 7 8 9 10 A[i] 11 22 33 44 55 66 77 88 99 100 Show the result after applying heap-decrease-key(A, 6, 12) to the min-heap at the top of this page: i 1 2 3 4 5 6 7 8 9 10 A[i] Show the...
1. Write a C or C++ program A6p2.c[pp] that accepts one command line argument which is an integer n between 2 and 4 inclusive. Generate 60 random integers between 1 and 39 inclusive and store them in a 5 by 12 two dimensional integer array (e.g.,int a[5][12];). Use pthread to create n threads to convert all 60 array elements modulo 11 (i.e. take the remainder after division by 11) in place. You should divide this update task among the n threads as evenly as possible. Print the array both before and after...