Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I was wondering how computers do this.

The most logical way I can think is that they are iterating trough all elements of the list until they find one that matches the condition :)

For example if you call function_exists(), PHP should iterate trough all defined functions until it meets the one that matches the name you're looking for.

Is this true that this is the only way? If it is, it sounds like it's not very efficient :s

share|improve this question
add comment

3 Answers

up vote 2 down vote accepted

I'm a little confused by your question but here are a couple of ways that may speed up evaluating conditions:

If the list is sorted, then a binary search could be done that is more efficient than a brute force search through the list to find an element.

There can be short-circuit evaluations though can also speed up conditional evaluation.

share|improve this answer
add comment

Do some research on data structures, especially hash tables, which are frequently used for things like symbol tables. They use a function called a hash function to decide where to store the data, which has properties that make it very quick to retrieve at the expense of using some extra memory.

share|improve this answer
add comment

What you are talking about here is Search Algorithms.

The most common of these are:

1) Sequential Searches

2) Binary Search

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.