i = 1; j = n; while(i != j) { if(A[i] + A[j] == M) break; else if(A[i] + A[j] < M) i++; else j--; }
our works become simpler when we read the word its in increasing order...keep on adding the 2 consecutive numbers
case 1:the sum is less than given element then continue
case 2:the sum is greater than given element then terminate and return -1
case 3:the sum is equal to given element then terminate and return the position of i and j
can u explain ur logic once again ,its really hard for me to understand.
what is the meaning of this line:
First use hash table, to has first half no of this array.
i=1; j=n; if((a[1]+a[2]>M) OR (A[n]+a[n-1]<M)) print Element not found else { while(a[i]+a[j]!=M) { if(a[i]+[J]<M) i++; else j--; } print i ,j }