Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.
Suppose you are given a set P of integers and another integer x. We wish to use a T(nlgn) algorithm to decide whether there are 2 integers in P and the product (multiplication) of these two integers equals to x. Show your algorithm. (You can use pseudo code or by illustration only)
Function equate(list m)
Var l.list, r.list;
Var int middle = length.m /2;
For(int i = 0; i < middle; i++)
For(int j = 1;j < middle; j++)
print l.list(i), l.list(j)
For(int i = middle; i < m; i++)
For(int j = middle; j < m; j++)
if(r.list(i)*r.list(j) = x)
I want to make sure if this is correct! If I have to change something please show me on my code what I have to change, and explain! Thanks!
0 · ·