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.

這篇文章有幫助嗎?

 列印本文

Also Read

SQL DB backup error !

Posted by htw_Mehdi, 09-14-2007, 09:28 PMhello, when i try to backup mysql database on the...

Free host sites.

Posted by abbas, 09-17-2001, 06:01 AMHi. I want to start a free host site similar to...

P2V migration

Posted by webservermatrix, 04-23-2009, 06:41 AMHi, We have 2 servers SQL, Web & SM 4.x each with...

nsv streaming

Posted by kteo, 05-08-2007, 03:50 AMhello there...i have a shoutcast server installed in my...

litespeed standard 150 connect limit, high enough?

Posted by aww, 05-04-2007, 03:12 PMHow can I tell if the 150 connection limit in 3.1 litespeed is...