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
The process of converting information, such as text, numbers, photos, or music, into digital data that can be manipulated by ele
SCORPION-xisa [38]

Answer:

The process of converting information, such as text, numbers, photos, or music, into digital data that can be manipulated by electronic devices is called Digitization

Explanation:

It is the process of converting “information in to a digital form”. Here the information are organized into bits. Mostly these data will be converted into the form of image. But these can be edited by converting once again into necessary format and even back to image too. There are specific tools which the user needs to install for editing the digital documents.

The reason why we need digitization is that

a) We want to convert hard copy into soft copy and store it in system.  

b) We would like to edit the data in the hard copy and preserve as a fresh copy.

4 0
3 years ago
If you are writing an article on your favorite cuisine, which form of illustration would best fit the article?
andrezito [222]
The best article to use for this is a website that describes the food.
6 0
2 years ago
Read 2 more answers
Universal containers has two teams: Sales and Services. Both teams interact with the same records. Sales users use ten fields on
Oxana [17]

Answer:

Two profiles, one record type, two page layouts.

Explanation:

Record types and functions allow you to present forward different business processes, pick-list values, as well as page layouts to diverse range of users based on their profiles.

Going by the question, we can conclude that the minimum necessary configuration in order to meet the requirement in the question above are:Two profiles, one record type, two page layouts.

6 0
3 years ago
What did early computers use to store each bit?
Damm [24]

Answer:

A vacuum tube

4 0
3 years ago
Read 2 more answers
Input an int between 0 and 100 and print the numbers between it and 100, including the number itself and the number 100. If the
Murrr4er [49]

import java.util.Scanner;

public class JavaApplication42 {

   public static void main(String[] args) {

       Scanner scan = new Scanner(System.in);

       int count = 0;

       System.out.println("Enter an integer between 0 and 100");

       int num = scan.nextInt();

       if (num <= 0 || num >= 100){

           System.out.println("error");

       }

       else{

           while(num <= 100){

               if (count == 20){

                   System.out.println("");

                   count = 0;

               }

               else{

                   System.out.print(num+" ");

                   count++;

                   num++;

               }

           }

       }

   }

   

}

I hope this helps!

6 0
3 years ago
Other questions:
  • Which osi reference model layer includes all programs on a computer that interact with the network?
    13·1 answer
  • Read the scenario below. Explain why this is not fair use of copyright materials. What should you do instead of using the entire
    10·1 answer
  • Differences between windows xp and windows vista
    14·1 answer
  • What is the "online disinhibition effect"?​
    7·1 answer
  • Often technical personnel who are not familiar with security techniques think that restricting access to ports on a router or fi
    5·1 answer
  • If a function doesn’t return a value, the word _________ will appear as its return type.
    6·1 answer
  • In the digital age we have less time to absorb and make sense of new information
    12·2 answers
  • For what purposes do students collect data? Check all that apply.
    7·2 answers
  • In what ways is the human brain like a computer? In what ways is it different?
    14·2 answers
  • 25 points select 3 options!!!!!!!!!!!!!!!!!!!!!!!!!
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!