## Algorithms

Moderators: None (Apply to moderate this forum)
Number of threads: 402
Number of posts: 786

This Forum Only

Re: DATA STRUCTURE Posted by Arkadi on 20 Mar 2012 at 4:26 AM
> 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.
```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;
}
```

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

Thread Tree
bakinde DATA STRUCTURE on 23 Jan 2012 at 5:49 AM
Arkadi Re: DATA STRUCTURE on 20 Mar 2012 at 4:26 AM

## Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.