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]
3 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]3 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
Stella is a bank executive. She is preparing a spreadsheet on the loan repayment schedules of customers. Which function can she
den301095 [7]

Answer: The function Stella can use to calculate the periodic payments of a loan is:

The Excel PMT function or NPER function.

Explanation: 1. The Excel PMT function is a financial function that returns the periodic payment for a loan.

2. The NPER function to figure out payments for a loan, given the loan amount, number of periods, and interest rate.

7 0
2 years ago
Zenmap's topology tab displays a __________ that shows the relative size and connection type of all discovered ip hosts.
VladimirAG [237]
<span>Zenmap's topology tab displays a "Bubble Chart" that shows the relative size and connection type of all discovered IP hosts.
</span>A kind of chart which shows three dimensional data is known as Bubble chart. It also can be seen as the variation of scatter plot where bubbles replace the data points.
4 0
2 years ago
Before using your Twitter account to market your personal brand, you should evaluate Your profile picture Your bio Your tweets A
AnnZ [28]
D. All of the Above.

If you are using a Twitter account for marketing your personal brand, you certainly should evaluate your entire profile, which includes your pictures, bio and tweets.  
5 0
2 years ago
TRUE OR FALSE!!! <br> Your location can be tracked via your digital footprint.
laiz [17]
Sadly this statement is true
3 0
3 years ago
How many acute angles are in a square​
babymother [125]
0, a square has 4 right angles
7 0
2 years ago
Read 2 more answers
Other questions:
  • What security protocol originally came with 802.11 equipment?
    11·1 answer
  • Learning about public speaking can help improve your ________________.
    15·1 answer
  • The protocol that enables computers on the Internet to communicate with one another is called _____.
    10·2 answers
  • 8) The higher the drag coefficient, the_____ the car will go<br> a)Siower<br> b)Faster
    9·2 answers
  • 1. Itemise the order in which BASIC executes arithmetic operation.
    13·1 answer
  • Once a virus has been removed by your anti-virus program, all traces of it are gone from your computer.
    9·1 answer
  • _______ an embedded Word table to activate the Word features.
    6·1 answer
  • Convert infix to postfix
    9·1 answer
  • Which of the following is a key aspect of any IT position? installation of fiber optic cables
    14·2 answers
  • Do you think your generation will change the world? Why or why not?
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!