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.

Var dette svaret til hjelp?

 Print

Les også disse

Seeking a new host

Posted by Bloory, 08-03-2002, 12:57 PMI'm looking for a host with a maximum cost of around £35...

user avahi

Posted by sherwood, 04-22-2009, 11:59 AMHi, I seem to be getting emails from LFD about the...

yum broken

Posted by chielsen, 12-18-2007, 02:20 PMI have waisted all not trying to get subversion working...

Object Oriented Programming in PHP

Posted by That Guy, 03-19-2007, 11:03 PMWhy? I want to make a login script, but I'm not sure if I...

SVN web interface

Posted by fqaisrani, 02-21-2011, 10:17 AMI want to install SVN server on my VPS along with a web...