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
Stolb23 [73]
4 years ago
8

Merge together two sorted arrays of ints into a new array. * * Example1 merge: [-1 3 5 7 ] with [ 2 4 6 8] would yield [-1 2 3 4

5 6 7 8] * Example2 merge: [1 6 ] with [ 2 3 8 9] would yield [1 2 3 6 8 9]
* There is no guarantee about the size of either array. When/if you run out of elements in * either array, copy all the remaining elements from the non-empty array to the new array
* preconditions:
* both arrays, are sorted low to high
* there are no duplicate values among the two arrays
* either array may be empty
* postcondition: return an array with all elements from both arrays sorted from low to high
*
* You may not use any additional methods, sorting routines, etc
* For full credit, your solution may only go through each array one time ( so in particular - no nested loops)
*
* You will need to create a new array inside the function
* You do not have to write this recursively.
public static int[] mergeArrays( int[] a, int[] b) {

int[] answer = new int[0]; // an empty array to have something to return
return answer; // ToDo 3 . Fix this.
}


/*
* exercising functions and main.
* There are no Todo's for you in the code below.
*/
public static void mergeArrayTests() {

int a[] = new int[] {1,3,5,7,9,11};
int b[] = new int[] {2,4,6};
int[] combinedArray = mergeArrays( a,b);
StdOut.println("merging: "+ Arrays.toString(a) + " " + Arrays.toString(b));
StdOut.println(" --> " + Arrays.toString(combinedArray));

int c[] = new int[] {1,3,5,7,9,11};
int d[] = new int[] {2,4};
combinedArray = mergeArrays( c,d);
StdOut.println("merging: "+ Arrays.toString(c) + " " + Arrays.toString(d));
StdOut.println(" --> " + Arrays.toString(combinedArray));

int e[] = new int[] {1,3,5,7,9,11};
int f[] = new int[] {};
combinedArray = mergeArrays( e,f);
StdOut.println("merging: "+ Arrays.toString(e) + " " + Arrays.toString(f));
StdOut.println(" --> " + Arrays.toString(combinedArray));

int g[] = new int[] {3,11};
int h[] = new int[] {2,4,6,8,10};
combinedArray = mergeArrays( g,h);
StdOut.println("merging: "+ Arrays.toString(g) + " " + Arrays.toString(h));
StdOut.println(" --> " + Arrays.toString(combinedArray));
}

public static void main (String[] args) {

StdOut.println(" This main function calls your functions for a variety of inputs");
StdOut.println(" and simply prints the results");
StdOut.println(" It does NOT check to see if your functions return the correct values");
StdOut.println(" It is up to you to review the output and verify the results");
StdOut.println("***************************************************************");
int[] list0 = new int[] {};
int[] list1 = new int[] { 5 };
int[] list2 = new int[] { 3, 4 };
int[] list3 = new int[] { -2, 3, -4 };
int[] list4 = new int[] { -1, -2, -4, -5 };
int[] list5 = new int[] { 6, 1, 2, -3, 8 };

StdOut.format(" list: %s sum of positives: %d\n",Arrays.toString(list0), sumOfPositivesRecursive (list0));
StdOut.format(" list: %s sum of positives: %d\n",Arrays.toString(list1), sumOfPositivesRecursive (list1));
StdOut.format(" list: %s sum of positives: %d\n",Arrays.toString(list2), sumOfPositivesRecursive (list2));
StdOut.format(" list: %s sum of positives: %d\n",Arrays.toString(list3), sumOfPositivesRecursive (list3));
StdOut.format(" list: %s sum of positives: %d\n",Arrays.toString(list4), sumOfPositivesRecursive (list4));
StdOut.format(" list: %s sum of positives: %d\n",Arrays.toString(list5), sumOfPositivesRecursive (list5));
StdOut.println();

StdOut.println ("Reverse: Before: " + Arrays.toString(list1 ) );
reverseArray (list1);
StdOut.println (" After: " + Arrays.toString (list1) + "\n" );

StdOut.println ("Reverse: Before: " + Arrays.toString(list2 ) );
reverseArray (list2);
StdOut.println (" After: " + Arrays.toString (list2) + "\n");

StdOut.println ("Reverse: Before: " + Arrays.toString(list3 ) );
reverseArray (list3);
StdOut.println (" After: " + Arrays.toString (list3) + "\n");

StdOut.println ("Reverse: Before: " + Arrays.toString(list4 ) );
reverseArray (list4);
StdOut.println (" After: " + Arrays.toString (list4) + "\n");

StdOut.println ("Reverse: Before: " + Arrays.toString(list5 ) );
reverseArray (list5);
StdOut.println (" After: " + Arrays.toString (list5) + "\n");

mergeArrayTests();
StdOut.println("***************************************************************");
StdOut.println(" Output was not verified to be correct by this program. ");
StdOut.println(" It is up to you to review the output and verify the results");

}
}

Computers and Technology
1 answer:
Lelu [443]4 years ago
8 0

Answer:

Explanation:

def mergeArrays(arr1, arr2):

   s1 = len(arr1) # size of array 1

   s2 = len(arr2) # size of array 2

   new_size = s1 + s2

   new_arr=[]

   for i in range(new_size):

       if len(arr1)!= 0 and len(arr2) != 0:

           if arr1[0]<=arr2[0]:

               new_arr.append(arr1[0])

               del(arr1[0])

           else:

               new_arr.append(arr2[0])

               del(arr2[0])

       elif len(arr1)==0:

           for e in arr2:

               new_arr.append(e)

           del(arr2)

           break

       else:

           for e in arr1:

               new_arr.append(e)

           del(arr1)

           break

   return new_arr

arr = mergeArrays([-1,3,5,7],[2,4,6,8])

print(arr)

arr = mergeArrays([1,6],[2,3,8,9])

print(arr)

You might be interested in
Theodor is researching computer programming. He thinks that this career has a great employment outlook, so he'd like to learn if
lakkis [162]

Answer:

The capability to program for a longtime and not burn out and to know a few coding languages as well as have the ability to learn new languages quickly.

4 0
3 years ago
Read 2 more answers
.in the array based list implementation of the ADT what is the worst case time efficiency of the getEntry method?
kenny6666 [7]

Answer:

c.O(n)

Explanation:

In the array based list implementation of the ADT the worst case time complexity of the getEntry method is O(n).In the worst case it has to travel upto n elements then it has to do the operation.In doing so  the time complexity will come out to be O(n).So we conclude that the answer to this question is O(n).

5 0
4 years ago
Your wireless network consists of multiple 802.11n access points that are configured as follows: SSID (hidden): CorpNet Security
nasty-shy [4]

Answer:

double the bandwidth assigned per channel to 40 MHz

Explanation:

The best way of doing this would be to double the bandwidth assigned per channel to 40 MHz. This will make sure that the capacity is more than sufficient. This is simply because the bandwidth of a channel represents how much information can pass through the channel at any given second, the larger the channel, the more information/data that can pass at the same time. Therefore, if 20 MHz is enough for the network, then doubling this bandwidth channel size would be more than sufficient capacity for the network to handle all of the data.

6 0
3 years ago
You suspect a component in a computer is fried. You remove any unnecessary hardware devices one by one to narrow down where the
tankabanditka [31]

The examination phase

Further Explanation:

Hardware troubleshooting in computers requires a systematic and logical approach. Taking a logical approach helps you identify the root cause much easily. Ask yourself those questions first before getting to the bottom of anything. You will find it helpful to reproduce the problem and develop a hypothesis of the problem if you ask yourself those 20 questions.

Next comes the examination phase. Having gathered everything, I will now attempt a fix based on what I think I found. In my case, I suspect that there a component in my computer that is fried. A few ways to tell if my motherboard or components attached to the motherboard are fried is to remove the side panel first and examine the circuitry before removing any unnecessary hardware devices. Obvious sings will be smell of smoke. Examine the capacitors as well. Burnt capacitors have rounded tops. This is a clear indication that they are blown.

I will now remove every single component one by one from the motherboard and test my hardware on a low-level.

Learn more about computer hardware troubleshooting

brainly.com/question/12704715

brainly.com/question/13182488

#LearnWithBrainly

8 0
3 years ago
X = 1 if (A = 1 OR B = 1) OR (A = 0 AND B = 1
Gnoma [55]

Answer:

For question a, it simplifies.  If you re-express it in boolean algebra, you get:

(a + b) + (!a + b)

= a + !a + b

= b

So you can simplify that circuit to just:

x = 1 if b = 1

(edit: or rather, x = b)

For question b, let's try it:

(!a!b)(!b + c)

= !a!b + !a!bc

= !a!b(1 + c)

= !a!b

So that one can be simplified to

a = 0 and b = 0

I have no good means of drawing them here, but hopefully the simplification helped!

4 0
3 years ago
Other questions:
  • Which type of topology describes the physical arrangement, installation, and connection of cables, computer, and other devices?
    10·2 answers
  • On computer X, a nonpipelined instruction execution would require 12 ns. A pipelined implementation uses 6 equal-length stages o
    9·1 answer
  • Which speaker port should you use when connecting a single speaker to a pc?
    6·1 answer
  • Password is an example of an authentication mechanisms that is based on " what an entity has".
    6·2 answers
  • For the following C code assume k and m are passed in x3 and x4 respectively, while result is returned in x4. Compile this code
    14·1 answer
  • The signature area in a cover letter includes the sender's first and last name, followed by his/her job title (if applicable). *
    13·1 answer
  • 7.5 Code practice Plz answer ASAP
    15·1 answer
  • Koi jinda hei kya hello​
    13·2 answers
  • Which example illustrates the idea of "collecting data"?
    8·2 answers
  • Mack signs into his laptop and gets a message saying all his files have been encrypted and will only be released if he sends mon
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!