Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
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.

DATA STRUCTURE

bakindebakinde Posts: 2Member
PLS HELP ME SOLVE THIS QUESTION.................ITS VERY URGENT FOR ME..



1. An array contains 25 positive integers. Write a module which
(a) Finds all pairs of elements whose sum is 25.
(b) Find the number EVNUM of elements of A which are even, and the number ODNUM of elements of A which are odd.


Comments

  • ArkadiArkadi Posts: 6Member
    > Finds all pairs of elements whose sum is 25
    You can try to sort them first:
    1. Sort the list - you can do it in O(n log n)
    2.
    [code]
    j = n - 1;
    for (i = 0; i < n - 1; i++)
    {
    for (; j > i; j--)
    if (data[i] + data[j] == 25)
    report(i, j);
    else if (data[i] + data[j] < 25)
    break;
    if (data[i] + data[i+1] > 25)
    break;
    }
    [/code]
    > Find the number EVNUM of elements of A which are even, and the number ODNUM of elements of A which are odd
    It's a linear task. Can't think of optimization unless some low level involved.

Sign In or Register to comment.