Question

In: Computer Science

Q1. In all algorithm, always explain how and why they work. If not by a proof,...

Q1. In all algorithm, always explain how and why they work. If not by a proof, at least by a clear explanation. ALWAYS, analyze the running time complexity of your algorithms. Do not write a program. Write pseudo codes or explain in words.

(A) Find an efficient data structure supporting the following operations. Insert(S, x), Delete−Max(S), and Delete−100'th(S) which deletes from H the 100 largest element in the structure. Assume that the number of elements is more than 100. Also assume that the numbers are pairwise distinct and so the 100”th largest element is well defined.

(B): Recall the problem in which you have k sorted array each of size n, which need to make one single sorted array. Find another fast way to unite the arrays that does not use Priority Queue.

Solutions

Expert Solution

(A) Find an efficient data structure supporting the following operations. Insert(S, x), Delete−Max(S), and Delete−100'th(S) which deletes from H the 100 largest element in the structure. Assume that the number of elements is more than 100. Also assume that the numbers are pairwise distinct and so the 100”th largest element is well defined.

Ans:

You can use max Heap data Structure to store the value. Max heap always keep the largest elements at the top. Priority Queue is one of the applications of Heap where you can store the data pairwise and get the largest element at the top.

In C++ it is really easy to implement using the STL library. In other languages, you can find the alternative as well.

Just insert all the elements in max heap pop top 100 elements and here you go, your work is done.

(B): Recall the problem in which you have k sorted array each of size n, which need to make one single sorted array. Find another fast way to unite the arrays that does not use Priority Queue.

Ans:

Given, k sorted arrays each of size n.

Creating a single sorted array by combining all the arrays makes an array of size (n * k).

To sort this in an efficient way i.e. with less time complexity and less space complexity, we can use the merge sort algorithm.

The array is first divided into 2 arrays with size k/2. Later the array is further divided into k/4 on both the arrays. This recursive process is done until the size of array becomes 1. Finally, it follows a bottom up process by combining the elements to give a sorted array.

The algorithm is explained below.

ALGORITHM

  1. Create a recursive function which takes k arrays and returns the output array
  2. In the function, if the value of k is 1, return the input array else, merge the two arrays in linear time and then return it.
  3. If the value of k is greater is than 2, split the array into two equal parts and then apply the function recursively until k size is either 1 or 2.
  4. Output the sorted array.

Hope I answered the question.

If you have any doubts, or queries, feel free to ask

I'll respond to you as soon as I can.

Have a nice day


Related Solutions

Remarks: In all algorithm, always explain how and why they work. If not by proof, at...
Remarks: In all algorithm, always explain how and why they work. If not by proof, at least by a clear explanation. ALWAYS, analyze the running time complexity of your algorithms. In all algorithms, always try to get the fastest possible. A correct algorithm with a slow running time may not get full credit. Do not write a program. Write pseudo-codes or explain in words Question 1: Say that we want to maintain both a Queue and a Priority Queue. This...
For each algorithm, always explain how and why they work. If not by a proof, at...
For each algorithm, always explain how and why they work. If not by a proof, at least by a clear explanation. ALWAYS, analyze the running time complexity of your algorithms. Do not write a program. Write pseudo codes or explain in words Q2: Give a data structure that implements a Min-Heap and the command Max(S) that returns the maximum in the heap. Try and make the last operation as fast as possible. Q3: (a)Show how to implement a Queue by...
In all algorithm, always explain how and why they work. ALWAYS, analyze the complexity of your...
In all algorithm, always explain how and why they work. ALWAYS, analyze the complexity of your algorithms. In all algorithms, always try to get the fastest possible. A correct algorithm with slow running time may not get full credit. In all data structures, try to minimize as much as possible the running time of any operation. 1.Show that if a binary tree has a vertex with a single child, then this can not be an optimal Huffman tree. 2. Question...
DATA STRUCTURES: For each algorithm, always explain how and why they work. If not by a...
DATA STRUCTURES: For each algorithm, always explain how and why they work. If not by a proof, at least by a clear explanation. ALWAYS, analyze the running time complexity of your algorithms. Do not write a program. Write pseudo codes or explain in words Q1: We want to maintain both a Queue and a Priority Queue. When you do Enqueue you also add the item to the Priority Queue and when you do Dequeue you also remove the item from...
Q1. Explain how (EinScan-SE?) 3D Scanner work ?
Q1. Explain how (EinScan-SE?) 3D Scanner work ?
I need to provide proof that these statements are FALSE. But I don't always understand why...
I need to provide proof that these statements are FALSE. But I don't always understand why they are false. 1. "drugs that block L-type Ca channels, reduce the contraction-efficiency of cardiac muscle, but not of skeletal muscles." (dont the skeletal muscles just need the tiniest bit of Ca to use the DHP channels?) 2. "the length of a skeletal muscle twitch is about 10-100 ms" (is this maybe for all muscle types? and not just for skeletal muscles?) thx in...
Explain how does Baker’s algorithm works? Explain all the types of pointers it has and their...
Explain how does Baker’s algorithm works? Explain all the types of pointers it has and their complete functions. [25 points]
Explain why prices are always flexible.
Explain why prices are always flexible.
The cryptocurrency ‘bitcoin’ uses a blockchain that utilises the ‘proof of work’ concept. Explain this concept...
The cryptocurrency ‘bitcoin’ uses a blockchain that utilises the ‘proof of work’ concept. Explain this concept – your explanation should focus on: • what ‘the work’ is • why is it needed • the operational implication in terms of processing time, and • the distributed nature of the blockchain processing.
subject : Leading your work team Q1.Explain the difference between leadership and management Q2.Explain why leadership...
subject : Leading your work team Q1.Explain the difference between leadership and management Q2.Explain why leadership is important within own team Q3.Describe a range of different leadership styles Q4.Identify the most commonly used leadership style(s) within an organisation Q5.Explain the likely effect this leadership style(s) has on a team’s performance Q6. Identify own leadership style and its potential impact on a team
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT