Question: We have discussed Target-SUM with sorted array problem, 2-SUM problem and 3-SUM problem in the lecture (lecture 2), and give different algorithms for these problem.
We have discussed Target-SUM with sorted array problem, 2-SUM problem and 3-SUM problem in the lecture (lecture 2), and give different algorithms for these problem. Answer the following questions related to these problems. 1. 4-SUM problem: Given the algorithms for 3-SUM using two pointers (reduce to TargetSum), brieflydescribe a algorithm for the 4-SUM problem, where we want to find the tuples of 4 numbers in an distinct integer array that sums to 0, and give its running time in O(). Now we are going to solve a problem thats a slight variant of the 4-SUM describe above in part 1. Now, instead of one array, we are given four arrays, and we want to find out the total number of tuple of 4 numbers, each come from one array, that sum to 0. More formally, given four integer arrays A, B, C, and D, each has n integers, our goal is to find the number of tuples (i, j, k, l) such that: 0 i, j, k, l < n A[i] + B[j] + C[k] + D[l] = 0
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
