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
Analyze the following code. Number[] numberArray = new Integer[2]; numberArray[0] = new Double(1.5); Question 9 options: A) Sinc
sleet_krkn [62]

Answer:

B) At runtime, new Integer[2] is assigned to numberArray. This makes each element of numberArray an Integer object. So you cannot assign a Double object to it.

Explanation:

The Number class in Java is the superclass for the numbers. Once it is set to the Integer object, the values in <u>numberArray</u> must be all integers, we know that arrays can hold one type of value in Java. Assigning a double value is not allowed in this situation.

7 0
3 years ago
The relation LIBRARY records books currently on loan to students. Each book has one ISBN_NO The library has several copies of ea
Nataly [62]
I think the answer is E
3 0
3 years ago
What is the effect of this program?
Mrac [35]

Answer:

The answer is (C)

Let’s run the algorithm on a small input to see the working process.

Let say we have an array {3, 4, 1, 5, 2, 7, 6}. MAX = 7

  • Now for i=0,  i < 7/2, here we exchange the value at ith index with value at (MAX-i-1)th index.
  • So the array becomes {6, 4, 1,  5, 2, 7, 3}. //value at 0th index =3 and value at (7-0-1)th index is 6.
  • Then for i=1, i < 7/2, the value at index 1 and (7-1-1)=5 are swapped.
  • So the array becomes {6, 7, 1,  5, 2, 4, 3}.
  • Then for i=2, i < 7/2, the value at index 2 and (7-2-1)=4 are swapped.
  • So the array becomes {6, 7, 2,  5, 1, 4, 3}.
  • Then for i=3, i not < 7/2, so stop here.
  • Now the current array is {6, 7, 2,  5, 1, 4, 3} and the previous array was{3, 4, 1, 5, 2, 7, 6}.

Explanation:

So from the above execution, we got that the program reverses the numbers stored in the array.

8 0
3 years ago
2a
zmey [24]

Answer:

See explaination

Explanation:

2a)

A hacker group hacked into the Bay Area Rapid Transit system, this was done to protest BART’s shut down of wireless communication in some BART stations. Such attacks is done mostly to stand for some situation which happened previously. Hence, we can say it is a form a hacktivism. It was not ethical as it disrupted the system for some time.But this is also a form of protest which is been done by some group of peoples.

2b)

If a foreign government launches a hacking attack, it can be considered a war.

If this type of attack happens then the repercussions may result to the war.

2c)

We gave an analogy between merchants accepting some amount of shoplifting, on the one hand, and merchants and credit card companies accepting some amount of credit card fraud, on the other hand.

THe streght so called can be pointed out as the money is rolling in the market and the business keeps on going.

The weakness can be described as the loss which is being incurred by the company.

7 0
3 years ago
What are the data types used in C programming with examples
Zepler [3.9K]
I don’t really understand what you are trying to ask. Try posting a picture along with your question
5 0
3 years ago
Other questions:
  • If you plan on operating several applications at s time, the amount of RAM should be considered when purchasing a computer
    10·2 answers
  • Does clearing your hard drive make your computer faster reddit
    13·1 answer
  • The major difference between a calculator and a computer, when performing calculations, is that a
    10·1 answer
  • Debbie’s colleague hasn’t provided her the required details to complete an important report. She is upset by this, and she sends
    14·2 answers
  • Complete the following table.
    6·1 answer
  • Which part(s) of CAIN is realized through the use of message digest functions and hashes?
    14·1 answer
  • Why is the cost of a software project not directly related to the cost of development?
    13·1 answer
  • if a second system failure occurs while the first recovery is in progress, what needs tobe done after the system recovers for th
    11·1 answer
  • Types of Hazards Mitigation Measures
    8·2 answers
  • Write l for law of enrtia,ll for law of Acceleration and lll for law of enteraction.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!