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
Choose 2 statements that correctly describe the time complexity of data structures with N data.
Softa [21]

The  statements that correctly describe the time complexity of data structures with N data are:

  • The average time complexity of the data lookup in a hash table is O(N).
  • The average time complexity of inserting data into a heap is O(logN)

<h3>What is time complexity of data structures?</h3>

Time Complexity of an algorithm is known to be the depiction of the amount of time needed by the algorithm to carry out to completion.

Note that The  statements that correctly describe the time complexity of data structures with N data are:

  • The average time complexity of the data lookup in a hash table is O(N).
  • The average time complexity of inserting data into a heap is O(logN)

Learn more about data from

brainly.com/question/17350816

#SPJ1

6 0
1 year ago
Two fingers are assigned to six letters each. What fingers are they?
Lena [83]

Answer:

The left and right index finger

Explanation:

Left index finger: R, T, F, G, C, V

Right index finger: Y, U, H, J, B, N

8 0
3 years ago
Nina is trying to learn more about how computers work. She has repeatedly read that the motherboard is the "brain” of the comput
Lady bird [3.3K]

Its

Processes the data on the computer .

5 0
3 years ago
Read 2 more answers
Which avenue may utilize video streaming, audio narration, print designs and animation?
Shtirlitz [24]

Answer:

Multimedia avenue.

Explanation:

A file type is the standard used to store data such as pictures, texts, videos, and audios. All file types have unique file extension that determine which program to use to open a particular file and to access its data e.g pictures (jpeg, png), texts (txt, docx, rtf), videos (mp4, 3gp, avi), audios (mp3, acc).

Sometimes, computer users make the mistake of opening files with the wrong software application or program, this often leads to an error due to the incompatibility of the software application with the particular file.

Basically, all software applications are designed and developed for use with specific file extensions or formats and as such, when used to open a file it isn't developed for, it result in an error.

A multimedia avenue refers to a channel that is designed and developed to accept, utilize and combine various file formats such as audio, video, text, animation effects, etc. A common example of a multimedia avenue is Microsoft PowerPoint software.

Hence, the multimedia avenue may utilize video streaming, audio narration, print designs and animation.

8 0
3 years ago
How can i fix this, if i log in my acc it keeps saying wrong nickname or pass. even though my email and pass is correct
Oksanka [162]

Answer:

미안해요. 나는 우리가 단지 부동일 중 하나를 모르지만 그것을 해결하는 방법을 모른다!.

8 0
3 years ago
Other questions:
  • How to connect to my wireless printer for dummies?
    12·1 answer
  • Which windows tool can you use to find out if the hard drive is slowing down windows performance?
    9·1 answer
  • What’s good and bad about having social media?
    14·2 answers
  • What short (two letters!) but powerful boolean operator can check whether or not one string can be found in another string?
    12·1 answer
  • What is meant by encapsulating semaphores? Bring out the need for it
    12·1 answer
  • Correct answers plz<br><img src="https://tex.z-dn.net/?f=%20%5Csqrt%7Bx-8%7D%20%3D%203" id="TexFormula1" title=" \sqrt{x-8} = 3"
    5·2 answers
  • What is the difference between the Internet and the World Wide Web? Explain in your own words.
    13·2 answers
  • Write bash script which takes array as an input of size 10 bind its even indexes to accept even values and odd indexes to accept
    5·1 answer
  • One student will be stationed near you in a coffee shop. The other student will be located two miles away from your school. You
    10·2 answers
  • Which of the following statement is correct ? A . potential difference is measured by ammeter . B . The unit of potential differ
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!