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.

Was this answer helpful?

 Print this Article

Also Read

problem when set up dhcp server

Posted by tinhnho, 07-17-2007, 04:43 PMI follow instruction from redhat to setup my Centos acts...

MySQL database convert!

Posted by tetrahost, 11-14-2012, 03:25 AMHello all, i need a help from you. i need to convert a...

Shell Script Question

Posted by jscholes, 03-13-2010, 08:55 AMHi, I have a Windows port of the Unix/Linux uptime...

IE 6.0 and style.display

Posted by jon31, 03-23-2007, 05:14 PMHey folks, I'm working on some cool little AJAX scripts,...

wordpress jquery

Posted by Seeking Knowledge, 10-16-2012, 08:43 AMHi there, I'm facing a problem with few...