Question
Given n distinct integers, we want to know how many triples ( x , y , z ), where x y z , sum to
Given n distinct integers, we want to know how many triples (x, y, z), where x y z, sum to exactly zero. Note that the order of the triple does not matter, i.e., (x, y, z) is considered to be the same as (z, y, x).Example: There are 4 triples that sum to zero in the array:
[3 4 2 1 4 0 1]
i.e., the triples (3, 4, 1), (3, 2, 1), (4, 4, 0), (1, 0, 1).
Consider the following pseudocode, which, given an input of n distinct integers, counts the number of triples that sum exactly to zero:
3-Sum-to-0(A[1n]) 01 count = 0 02 for i = 1 to n 03 for j = i + 1 to n 04 for k = j + 1 to n 05 if A[i] + A[j] + A[k] == 0 06 count = count + 1 07 return count
1. Let T(n) be the number of times the array A is accessed (for values A[i], A[j],A[k]) as a function of input size n. Express T(n) as a summation (actually three nested summations). Find T(n), i.e., simplify the summation. Show all your work.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started