subject

Consider the following problem: Input: Two sorted arrays, A, B. A and B together contain n integers. Output: The union and the intersection of A and B. For example, if A and B are: {0, 0, 0, 1, 2, 3, 97, 98} {0, 1, 2, 3, 4, 4, 10, 98, 100, 100} The union of A and B should be {0, 1, 2, 3, 4, 10, 97, 98, 100}. The intersection of A and B should be {0, 1, 2, 3, 98}. There should be NO duplicates in the union and intersection. Give an in-place algorithm that solves this problem in O(n) time. (i) describe the idea behind your algorithm in English (ii) Complete the method of union() and intersection(); (iii) analyze its running time. Regarding requirement (iii): Unless otherwise specified, show the steps of your analysis and present your result using big-o. public class Problemi { public static void intersection(int[] si, int[] s2) { // complete the intersection() method to output // elements that occur in both si and s2 // feel free to change method type and parameters // Full credit will awarded to algorithms O(n) and in-place } { public static void union(int[] si, int[] s2) // complete the union() method to output // the union s1 and s2 // feel free to change method type and parameters // Full credit will awarded to algorithms O(n) and in-place } public static void main(String[] args) { // TODO Auto-generated method stub // Test your intersection() method here int[] testarray1 = {0, 0, 0, 1, 2, 3, 97, 98}; int[] testarray2 = {0, 1, 2, 3, 4, 4, 10, 98, 100, 100); System. out. println("intersection of testarray1 and testarray2: "); intersection(testarray1, testarray2); //should output 0, 1, 2, 3, 98 System. out. println("union of testarray1 and testarray2: "); union(testarrayı, testarray2); // should output 0, 1, 2, 3, 4, 10, 97, 98, 100 } }

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 18:30
Kto rozmawia z clamentain przez krótkofalówke w the walking dead która śledzi lee w 4 epizodzie
Answers: 1
question
Computers and Technology, 23.06.2019 06:30
Which option correctly describes a dbms application? a. software used to manage databases b. software used to organize files and folders c. software used to develop specialized images d. software used to create effective presentations
Answers: 1
question
Computers and Technology, 23.06.2019 09:00
Which best describes the role or restriction enzymes in the analysis of edna a. to break dna into fragments that vary in size so they can be sorted and analyzed b. to amplify small amounts of dna and generate large amounts of dna for analysis c. to purify samples of dna obtained from the environment so they can be analyzed d. to sort different sizes of dna fragments into a banding pattern that can be analyzed
Answers: 1
question
Computers and Technology, 23.06.2019 09:50
Allison and her group have completed the data entry for their spreadsheet project. they are in the process of formatting the data to make it easier to read and understand. the title is located in cell a5. the group has decided to merge cells a3: a7 to attempt to center the title over the data. after the merge, allison points out that it is not centered and looks bad. where would the title appear if allison unmerged the cells in an attempt to fix the title problem?
Answers: 2
You know the right answer?
Consider the following problem: Input: Two sorted arrays, A, B. A and B together contain n integers....
Questions
question
Biology, 16.02.2021 22:20
question
Social Studies, 16.02.2021 22:20
question
Mathematics, 16.02.2021 22:20
question
English, 16.02.2021 22:20
question
Social Studies, 16.02.2021 22:20
question
Arts, 16.02.2021 22:20
Questions on the website: 13722361