From the course: Programming Foundations: Algorithms

Unlock the full course today

Join today to access over 23,400 courses taught by industry experts.

Unordered list search

Unordered list search

- [Instructor] Now that we've learned a little bit about sorting data, let's take a look at how we can search for data within a collection. The first algorithm we're going to consider is a straight linear search for data in an unordered list. And that's a list that is not currently sorted in any way. The data is just in some random order. So let's open up the unordered start file and here I have some integer data to look for. I have my find item function and some test code. Now, there's no way for us to know where the particular item is in the list or if it's even there. So we have to search the list by each item, and we can do that with a simple loop. So I'll get rid of this placeholder pass and write for I in range, starting from zero up to the length of the item list. And then I'll just check to see if the item is equal to the data at the item list index. And if so, I will return the index. Otherwise, I'll return none…

Contents