Join Simon Allardice for an in-depth discussion in this video Searching arrays, part of Foundations of Programming: Data Structures.
- View Offline
…So, how do we find a particular item in a basic array?…If I have an array of integers, or an array of strings, or an array of…anything, and I just want to know if…a specific value exists somewhere in this array.…Well, in the simplest rudimentary arrays, like C-style arrays,…you don't have any search functionality of any kind.…You might have 1,000 elements, but they'll be no easy find or index…of function that we can call just to see if a value exists.…Now we can certainly find out, we just…might need to go through all the items ourselves.…
So if I wanted to know if the value 99 exists somewhere in a basic array of…integers, where any value could be in any…position, I might use something like this pseudo code.…Where I'll set up an initial index value and set…it to 0, and then I've got a while loop.…I could write this as a for loop or a for each or a do…loop, whatever works, as long as i is less than the length of the array.…We'll check the value at that current position, see if it's equal to 99.…If it is, we'll return true.…
Starting with simple ways of grouping data like arrays and structs, together you'll explore gradually more complex data structures, like dictionaries, sets, hash tables, queues and stacks, links and linked lists, and trees and graphs. Simon keeps the lessons grounded in the real world and answers the "why" behind many data-structuring decisions: Why use a hash table? Why is a set useful? Why avoid arrays? When you're finished with the course, you'll have a clear understanding of data structures and understand how to use them in whatever language you're programming in, today or 5 years from now.
- What is a data structure?
- Using C-style structs and arrays
- Sorting and searching arrays
- Working with singly and doubly linked lists
- Using stacks for last-in, first-out (LIFO) structures
- Using queues for first-in, first-out (FIFO) structures
- Working with hash tables
- Understanding binary search trees (BSTs)
- Learning about graphs