Howdy, Stranger!

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

Categories

DATA STRUCTURE

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: 6
    > 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.