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
Anestetic [448]
3 years ago
8

Let $A = \{ a_1, . . . , a_n \}$ and $B = \{b_1, . . . , b_m\}$ be two sets of numbers. Consider the problem of finding their in

tersection, i.e., the set C of all the numbers that are in both A and B. Design a presorting-based algorithm in **pseudo code** for solving this problem and determine its efficiency class.
Computers and Technology
1 answer:
Digiron [165]3 years ago
6 0
<h2>Answer: Pseudo code</h2>

Initialize intersection I as empty.

Find smaller of m and n and sort the smaller array.

function  printIntersection(int arr1[ ], int arr2[ ], int m, int n)  

{  

   // Before finding intersection, make sure arr1[0..m-1]  

   // is smaller  

   if (m > n)  

   {  

       int *tempp = arr1;  

       arr1 = arr2;  

       arr2 = tempp;  

 

       int temp = m;  

       m = n;  

       n = temp;  

   }  

 

   // Now arr1[ ] is smaller  

 

   // Sort smaller array arr1[0..m-1]  

   sort(arr1, arr1 + m);  

 

   // Search every element of bigger array in smaller  

   // array and print the element if found  

   for (int i=0; i<n; i++)  

       if (binarySearch(arr1, 0, m-1, arr2[i]) != -1)  

           cout << arr2[i] << " ";  

}

3) For every element x of larger array, do following

…….b) Binary Search x in smaller array. If x is present, then copy it to I.

int binarySearch(int arr[], int l, int r, int x)  

{  

   if (r >= l)  

   {  

       int mid = l + (r - l)/2;  

 

       // If the element is present at the middle itself  

       if (arr[mid] == x)  return mid;  

 

       // If element is smaller than mid, then it can only  

       // be presen in left subarray  

       if (arr[mid] > x)  

         return binarySearch(arr, l, mid-1, x);  

 

       // Else the element can only be present in right subarray  

       return binarySearch(arr, mid+1, r, x);  

   }  

 

   // We reach here when element is not present in array  

   return -1;  

}

4) Return I.

Explanation:

Time complexity of this method is min(mLogm + nLogm, mLogn + nLogn) which can also be written as O((m+n)Logm, (m+n)Logn). This approach works better than the different approaches like hashing when difference between sizes of two arrays is significant.

You might be interested in
after teaching a group of students about measuring systems and drug calculations, the instructor determines that the teaching wa
dusya [7]
  • After teaching a group of students about drug measurement and calculation systems, the instructor determines that teaching is successful when students can identify which metric system is the most widely used system.

  • The metric system is a measurement system for something that is done in a study and calculation. An example of a metric system is the meter used to measure length, grams to measure weight, milliliters to measure volume.

  • In this case, we can take an example from the application of the metric system in the world of health. A nurse uses the metric system to calculate doses and uses the liter as the base unit for measuring fluids.

Learn more about Metric System here brainly.com/question/1764307

#SPJ1

7 0
1 year ago
Show what this program prints. Be exact and complete. Can you explain the behavior of each print statement? 1 2 3 4 5 6 7 public
KengaRu [80]

Answer:

39 + 3

42

393

Explanation:

In this line System.out.println("39 + 3"), the quotation marks are used to delimit a string, then when printed in the console the string is printed as-is.

In the next line: System.out.println(39 + 3), without the quotation marks, the 39+3 is treated as a normal addition and prints the result of the operation.

In the last line printed with the code System.out.println("39" + 3,; the symbol + is used to concatenate the string 39 with the number 3, since the string has no spaces they are printed together.

3 0
3 years ago
If an if-else statement is true, it will include which kinds of results?
FinnZ [79.3K]

Answer:

> It will run out the function under the if statement.

Explanation:

> As an if-else statement is saying if (something = something, etc) do (this this and this [let’s refer to this as 1]) Else do (this this and not this [let’s refer to this as 2]) Since it is true, it will do the original function (1).

> It is saying if this is true, then do this (1). If it is not true, then do this (2). Basically the else is there in case the if is not true, or equal to anything other than what’s intended.

> Since it is true however, it will do what the original function (1) is. So this is our correct answer. Once again, it is; “It will do the original function under the if statement”.

> I hope this answered your query, and any other questions you may have had on the subject. #LearningWithBrainly

8 0
3 years ago
java Two smallest numbers Write a program that reads a list of integers, and outputs the two smallest integers in the list, in a
SashulF [63]

Answer:

The code to this question can be defined as follows:

import java.util.*;//import package for user input

public class Main //defining a class

{

public static void main(String[] args)//defining main method  

{

   int m1,m2,num,t,i;//defining integer variable

   Scanner incx = new Scanner(System.in);//creating Scanner class object

   m1 = incx.nextInt();//input value

   m2 = incx.nextInt();//input value  

   if (m1 > m2)//use if block to check m1 greater than m2  

   {//swapping value

       t = m1;//holding m1 value in t

       m1 = m2;//defining m1 that take m2

       m2 = t;//holding m2 value  

   }

   for (i = 2; i < 6; i++)//defining for loop  

   {

       num = incx.nextInt();//input value  

       if (num < m1) //defining if block to smallest value

       {

           m2 = m1;//holding m2 value in m1

           m1 = num;//holding num value in m1

       }  

       else if (num < m2)//defining if block to smallest value  

       {

           m2 = num;//holding num value in m2

       }

   }

       System.out.println(m1 + " " + m2);//print two smallest values

   }

}

Output:

5

10

5

3

21

2

2 3

Explanation:

In the above code, five integer variable "m1, m2, num, t, and i" is declared, in which it creates the scanner class object for inputs the value and use m1 and m2 use to the input value.

In the next step, if a block is used to swap the value and pass into the for loop that use if block to find the two smallest values and hold its value into the m1 and m2 and print its value.

7 0
3 years ago
What is the major benefit Smartphones and tablet computers have had on social media?
Naddika [18.5K]

Answer:

c

Explanation:

The biggest advantage of smartphones and tablets is that they increased the mobility. This allowed users to access the social media platforms whenever they want. The users can login to their accounts even they are travelling by bus or walking around. This was not possible back in the days where people mostly use desktop computers.

8 0
3 years ago
Other questions:
  • Raeball was a lovin doll. And she spoke her mind as she stood tall. She made you special and loved. You're missed by so many. An
    10·2 answers
  • Which destination ip address is used when an ipv6 host sends a dhcpv6 solicit message to locate a dhcpv6 server?
    15·1 answer
  • Which of the following binary (base-2) numbers is LARGEST?
    14·1 answer
  • The mods have peanuts for brains (it's true, I lost like 1k points to them for no reason)
    12·1 answer
  • The term computer ________ is used to describe someone who is familiar enough with computers to understand their capabilities an
    12·1 answer
  • which of the following cells can't be recarged? A. Electrode cell B. wet cell C. primary cell D. storage cell
    13·1 answer
  • cpp g Write a for loop to print all elements in courseGrades, following each element with a space (including the last). Print fo
    15·1 answer
  • Question #5
    15·2 answers
  • Discuss the ways you can perform to prevent your computer/device and its data/contents from being stolen. Define two-facto authe
    7·1 answer
  • Web résumés allow you to include extra graphics and images that you would not include in a traditional résumé. please select the
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!