1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
rewona [7]
4 years ago
7

Give an O(log m + log n)-time algorithm that takes two sorted lists of sizes m and n, respectively, as input and returns the ith

smallest element in the union of the two lists. Justify your algorithm and analyze its running time.
Computers and Technology
1 answer:
olga2289 [7]4 years ago
7 0

Binary search is used similarly. K'th element is found in more productive way.

<u>Explanation:</u>

arr1 and arr2 are the middle elements which are compared, let us compute as mid1 and mid2. Let us predict arr1 [mid1] k, the elements are not needed after mid2 elements.  arr2 are set as last element for arr2 [mid2].  New sub problems are defined. When one array is half the size.

C++ code for the algorithm.

#include <iostream>

using namespace std;    

int kth(int *arr1, int *arr2, int *end1, int *end2, int k)

{

if (arr1 == end1)

return arr2[k];

if (arr2 == end2)

return arr1[k];

int mid1 = (end1 - arr1) / 2;

int mid2 = (end2 - arr2) / 2;

if (mid1 + mid2 < k)

{

if (arr1[mid1] > arr2[mid2])

return kth(arr1, arr2 + mid2 + 1, end1, end2,

k - mid2 - 1);

else

return kth(arr1 + mid1 + 1, arr2, end1, end2,

k - mid1 - 1);

}

else

{

if (arr1[mid1] > arr2[mid2])

return kth(arr1, arr2, arr1 + mid1, end2, k);

else

return kth(arr1, arr2, end1, arr2 + mid2, k);

}    

int main()

{

int arr1[5] = {2, 3, 6, 7, 9};

int arr2[4] = {1, 4, 8, 10};    

int k = 5;

cout << kth(arr1, arr2, arr1 + 5, arr2 + 4, k - 1);

return 0;

}

You might be interested in
Which letter is located at position (7,4) on this coordinate grid? A) B) C) D)
aleksklad [387]

It is letter d

gdstcccccccvdagjsbhbj cna cas

8 0
3 years ago
What do we call the input and output devices that are connected externally to the computer?
Anna35 [415]

Explanation:

computer peripheral is an external device that provides input and output for the computer. for example keyboard and mouse are input peripherals while mouse and printer are output peripherals...

5 0
3 years ago
Read 2 more answers
PP 11.1 – Write a program that creates an exception class called StringTooLongException, designed to be thrown when a string is
Scrat [10]

Answer

The answer and procedures of the exercise are attached in the following archives.

Step-by-step explanation:

You will find the procedures, formulas or necessary explanations in the archive attached below. If you have any question ask and I will aclare your doubts kindly.  

6 0
3 years ago
The total number of errors divided by the total number of bits transmitted is the definition of __________. committed informatio
kodGreya [7K]

The answer in the blank is bit error rate, for it is where errors usually occurs and this happens during the digital data transmission. Because of the errors that it is being managed, it divides those errors by the total number of bits that are being transmitted during the process. It happens within a given period.

8 0
4 years ago
Will a logic error be found if a program is compiled?
natali 33 [55]
No. The computer dose not understand what you are attempting to do, therefore it will not understand how to check for logic errors. The compiler will only check for syntax errors.
6 0
3 years ago
Other questions:
  • a. Is there any functional difference between the class being instantiated in the following two ways? Balanced bal = new Balance
    15·1 answer
  • One factor affecting digital camera quality is the number of pixels, measured in ____, used to store the data for each image.
    8·2 answers
  • A virus or worm can have a payload that installs a(n) __________ door or trap-door component in a system, which allows the attac
    14·2 answers
  • You have a desktop computer that supports both IEEE 1394 and USB 2.0. You are purchasing some devices that will connect to these
    13·1 answer
  • How would you compare and contrast the impact of the printing press with the impact of the internet?
    15·1 answer
  • How do I retrieve the number from an old home phone? Someone called my home phone (it is not a cellular phone) and they did not
    7·1 answer
  • Jack started a job as a consultant with an IT firm he will be interacting with various customers and employees from different pa
    13·1 answer
  • Consider the following method, which is intended to return the number of local maximum values in an array Local maximum values a
    6·1 answer
  • What are the differences between switches and routers? cse question
    8·1 answer
  • Does survey monkey remembers you already took survey?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!