Reynald, to demonstrate linear search, steps through creating custom classes and methods. He talks through the process so the student understands the basic requirement for linear search. Once done with the core functionality, he then writes out the code to execute the demonstration and runs it while explaining the results.
- [Instructor] So the first step that we want to do…to create our linear search algorithm…is to set up an R function.…So let's create one called…linear search that returns an integer.…And it will take in two parameters.…An array of integers.…We'll call it A.…And, the value that we're searching for…which is X.…And to get rid of this red squiggly line…let's go ahead and do our last step…which is to return…answer.…
That's going to be the name of our variable.…Which we will now define…in step one.…Int answer equals…negative one.…And now we go onto step two…and do the main work…of iterating through with a for loop.…I'll just type in the word for and hit tab tab.…And a nice snippet gets invoked.…So I don't have to type everything in manually.…
So now, the only thing I need to modify is just…add the letter A and a period…to reflect the length.…Capitalization matters.…So we're going to iterate through this…for as long as I is less than the length of the array.…At which point,…we check…to see if…the array index at I…is equal to…our value…
- Working with linked lists
- Creating a stack
- Defining a queue
- Performing a binary search
- Finding target values with a linear search
Skill Level Beginner
1. Algorithms and Data Structure Overview
Reasons for this course1m 26s
2. Linked List
5. Binary Search
6. Linear Search
- 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.