Learn how to search for an item in an array using the tools given by a programming language. Understand why sorting an array with a brute-force algorithm takes linear time.
- We are able to access a specific item in an array…because we know its index.…We know where it's stored in the array.…In searching, we usually want…to return a true or false value…depending on if the value exists in the array.…Sometimes if the item is in the array,…we'll also want to know its index.…Now, the most obvious solution…for searching is to check every item,…to go through the entire data structure…and check if the item at a given index…matches the item we're looking for.…
If there's a match, we return true.…If we've gone through the entire data structure…and there is not a match, we return false.…To do this in most languages, we can use a for loop,…iterating over the data structure…and checking each item at every index…to see if it matches the item we're looking for.…Here we're using a Java example…where we go through every index and check if the element…at that index equals our specific item.…It it does, we return true.…And if we go through the whole structure without finding it,…we return false.…
We call this linear search or sequential search.…
- Data types: Booleans, numbers, strings, and more
- Multidimensional arrays
- Jagged arrays
- Search and sort arrays
- Linked lists
- Stacks and queues
- Hash functions and hash tables
- Trees and graphs
Skill Level Intermediate
Understand data structures1m 25s
1. Introduction to Data Structures
4. Stacks and Queues
5. Hash-Based Data Structures
6. Trees and Graphs
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.