Given two integer arrays, A and B of length n each, write an efficient algotihm to find an integer that occurs the same number of times in both A and B.
extra:
solve this recurrence: T(1) = 1; T(n) = T(n/4) + n
Hi, I have answered Q1.
Please repost others in separate post.
Given two integer arrays, A and B of length n each, write an efficient algotihm to find an integer that occurs the same number of times in both A and B.
Algorithm:
Step 1:
prepare HashMap of elements of A
mapA = createHashMap
for i=1 to n do:
if A[i] is in mapA then do:
increase count
of A[i]
else:
add A[i] in mapA
with count 1
Step2:
prepare HashMap of elements of B
mapB = createHashMap
for i=1 to n do:
if B[i] is in mapB then do:
increase count
of B[i]
else:
add B[i] in mapB
with count 1
Step 3:
traverse any one of the array , A or B
Lets traverse A
for i =1 to n do:
if count of A[i] is in mapA and
mapB is same then:
return A[i]
Time complexity: O(N)
Space complexity: O(N)
Given two integer arrays, A and B of length n each, write an efficient algotihm to...
write a code to multiply two integer arrays (each with N numbers). Monitor the time to run that code with the following N: 50, 100, 200, and 400 ================= You can write in either C or in Java, Provide correct solution to get upvote, Thanks
Write a program that reads two integer arrays each of size 10 then find and print the inner product of the arrays. Inner product can be performed by multiplying each element of one vector by the corresponding element in the second vector that has the same index, and summing all the products. For example: A[5]= {1,2,3,4,5} B[5]= {2,0,3,1,5} Inner product = 40
Given two arrays A and B of n integers both of which are sorted in ascending order. Write an algorithm to check whether or not A and B have an element in common. Find the worst case number of array element comparisons done by this algorithm as a function of n and its Big-O complexity
Language C Code Write a program that takes two integer arrays (A and B) and sums them together (element wise). A third array to accept the result should be passed in as the output argument. Assume the arrays are all the same size. The argument N is the size of the arrays. Your code should provide a function with the following signature: void array Addition (int A[], int B[], int N, int output[]) { } Your code must also provide...
Use C programming Swap two arrays using pointers Given two integer arrays, swap the two arrays using pointers. Input: 4 1 2 3 4 5 4 5 6 7 8 where: First line represents the number of elements in the first array. Second line represents the elements in the first array. Third line represents the number of elements in the second array. Fourth line represents the elements in the second array. Output: 4 5 6 7...
Given two vectors of length n that are represented with one-dimensional arrays, write a code fragment that computes the Euclidean distance between them (the square root of the sums of the squares of the differences between corresponding elements).. Implement using while loops
Java arrays Create method named repeatedN that takes two integer parameters named range and n and returns an integer array Method should return an integer array that has numbers 0 - range repeated in order n times If range is less than or equal to 0; return an array that has 0 repeated n times Create a second method named printArray that takes an integer array as a parameter. The method should print out every element on the same line...
Write a class called RandomIntegerArrayCreator that: upon its object instantiation: will generate a random integer arraySize from the set {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, create a random integer array of size arraySize (15 OR LESS) with elements from the the set {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10} (integers can appear multiple times in this array, has two accessor methods: public int getArraySize() that will...
in c++ Write a program which can add two float vectors (arrays) of any length ?. The length ? of the two vectors being added should be the same. The user will enter the length ?. Use the length to control how many times you loop. The result is also a vector.
4A. Write a CUDA host program that reads a character type matrix A and integer type matrix B of size mxn. It produces an output string STR such that, every character of A is repeated n times (where n is the integer value in matrix B which is having the same index as that of the character taken in A). Solve this using 1D Block. Example: 1 2 4 3 e X a M Output String STR: pCCaaaaPPPeeXXXXaaaMM 4B. Write...