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
What does ""fair use"" mean regarding copyrighted works?
Nady [450]

In regards copyrighted works, fair use is simply known as legal dogma that allows the right to free expression by allowing the unlicensed use of copyright-protected works by individuals as regards to some certain situations.

Fair Use of copying of copyrighted material can only be used in a short and revelatory us, example to criticize, or caricature of a copyrighted work. It is often known to be a legal defense that protects individuals of copyrighted material from copyright infringement.

  • Fair use allows a person/people to use a copyrighted work without acknowledgement or permission of copyright owner and it can be used  to criticize, comment, news reporting, teaching, research etc. It is not seen as infringement under the law.

Conclusively, we can say that In regards copyrighted works, fair use is simply known as legal dogma that allows the right to free expression by allowing the unlicensed use of copyright-protected works by individuals as regards to some certain situations.

Learn more from:

brainly.com/question/1534807

5 0
2 years ago
An array of integers can be assigned to a memory address in the ...
fenix001 [56]

Answer:

A :)

Explanation:

8 0
2 years ago
Reed Hastings created Netflix. His inspiration came from the fact that he had to pay a sizeable late fee for returning a DVD bey
noname [10]

Answer:

Which statement accurately describes his key to success?

Explanation:

The success in Netflix lies in offering:

1. Entertainment;

2. fun;

3. originality;

4. innovation and

5. happiness.

Netflix learning is:

1. Bet on your content.

2. Brand Personality.

3. Visual universe.

4. Customization

5. Big Data helps Netflix continue to grow and improve customer service.

3 0
3 years ago
A file manager is used for all of the following except ____. A. to move files and folders B. to reorder files and folders C. to
Alex73 [517]

Answer:

A .to move files and folders

5 0
3 years ago
Read 2 more answers
Which of the following statements about RAID is correct? Group of answer choices All RAID configurations provide fault tolerance
olchik [2.2K]

Answer:

A RAID 1 configuration of 4 disks has higher storage capacity than a RAID 0 configuration

Explanation:

Redundant Array of Independent Disks(RAID) are multiple physical drives arranged in logical units to provide data redundancy and increased performance. They are

RAID 1 configuration duplicates data storage, albeit of lower performance than RAID 0. Also called disk mirroring because it mirrors data on two or more disks, it provides at least two drives that are used interchangeably or together.

4 0
2 years ago
Other questions:
  • In this exercise we examine in detail how an instruction is executed in a single-cycle datapath. Problems in this exercise refer
    6·1 answer
  • What will be the output of the following Python code? class A: def test1(self): print(" test of A called ") class B(A): def test
    15·1 answer
  • Which of the following laptop features allows users to overcome keyboard size restrictions?
    11·1 answer
  • (1) Prompt the user to enter a string of their choosing. Output the string.
    11·1 answer
  • What is the name of the unique identifier assigned to any personal computer that is connected to the internet?
    11·1 answer
  • How do you award a brainliest
    8·2 answers
  • PLEASE HELP ASAP!!! 99 POINTS FOR 3 MULTIPLE CHOICE QUESTIONS!!! PLEASE ANSWER ALL!!!
    8·1 answer
  • Submit your 400-word essay that analyzes and evaluates three different examples of digital media. need some help
    14·1 answer
  • In Windows 7's Jump List, what can we do?
    6·1 answer
  • A data use agreement is required when a researcher uses a limited data set (lds). an lds must have:_________
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!