Alorithm help

Posted by Red_wolf6, 03-07-2010, 04:41 PM
Hello, I have a Question - I couldn't solved it We have an unordered List, I want to find the phone number of john and it's position in the table names. NAME : http://i47.tinypic.com/x572he.png TELEPHONE: http://i47.tinypic.com/dysidy.png Any idea what to do?

Posted by UNIXy, 03-07-2010, 05:20 PM
There's isn't much of a sophisticated algorithm one can use against an unordered list. You just have to iterate through each of the list's elements until you find John. So for an unordered list, the algorithm is going to be O(n) no matter what. It's usually best to sort the list first (perhaps based on person's name) and then implement one of the many efficient algorithms on ordered lists. Sorting the list once makes subsequent searches much more efficient. Regards Joe / UNIXY

Posted by Mark Edwards, 03-09-2010, 12:36 AM
Honestly though if the list is only 1000 people long, no big deal. Just loop it getting name/phone number and checking if name is John. Or have two arrays and use the indexes appropriately. Both work.

Je li Vam ovaj odgovor pomogao?

 Ispiši članak

Također pročitajte

Can't upload via php script

Posted by JohnDoe_Cro, 06-28-2008, 01:58 PMHello all, I am having problems on my server... I...

EARHOST down!

Posted by davkiz, 08-29-2002, 03:54 AMWow now there's a surprise. It was bound to happen. Their...

Any PHP library to create .ico? Or just to convert a PNG to ICO?

Posted by yangyang2036, 09-21-2008, 09:17 PMSearched google with nothing relevant. Posted by...

adultvideoscript dispute

Posted by jo2jo, 03-05-2010, 08:46 PMPlease beware. quick over view, the site says Instant...

Monitoring System

Posted by prashant1979, 06-22-2008, 12:51 AMHello, I am looking for a server monitoring system...