Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Fundamentals for Self-Taught Programmers

You're reading from   Fundamentals for Self-Taught Programmers Embark on your software engineering journey without exhaustive courses and bulky tutorials

Arrow left icon
Product type Paperback
Published in Apr 2023
Publisher Packt
ISBN-13 9781801812115
Length 254 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Jasmine Greenaway Jasmine Greenaway
Author Profile Icon Jasmine Greenaway
Jasmine Greenaway
Arrow right icon
View More author details
Toc

Table of Contents (20) Chapters Close

Preface 1. Part 1: Software Engineering Basics
2. Chapter 1: Defining Software Engineering FREE CHAPTER 3. Chapter 2: The Software Engineering Life Cycle 4. Chapter 3: Roles in Software Engineering 5. Part 2: Introduction to Programming
6. Chapter 4: Programming Languages and Introduction to C# 7. Chapter 5: Writing Your First C# Program 8. Chapter 6: Data Types in C# 9. Chapter 7: Flow Control in C# 10. Chapter 8: Introduction to Data Structures, Algorithms, and Pseudocode 11. Chapter 9: Applying Algorithms in C# 12. Chapter 10: Object-Oriented Programming 13. Part 3: Software Engineering – the Profession
14. Chapter 11: Stories from Prominent Job Roles in Software Development 15. Chapter 12: Coding Best Practices 16. Chapter 13: Tips and Tricks to Kickstart Your Software Engineering Career 17. Assessments 18. Index 19. Other Books You May Enjoy

Introduction to the linear search algorithm

The linear search algorithm is a basic search within a data structure that begins by visiting the data at the beginning and visits each value until it’s found or reaches the end of the array, where the value does not exist. In the Introduction to the array data structure section, we did a linear search to find a picture in the example array. We’ll experiment with it more by using the same array of integers used in the selection sort algorithm. First, let’s write the algorithm in pseudocode:

  1. Store the value being searched for.
  2. Start at index 0.
  3. WHILE the value is not found and is not at end of the array.
    1. IF the value is equal to the value being searched for.
    1. Return the index
    2. ELSE
    1. Increase the index by 1 and move on to the next value.

    C. IF at end of the array.

    1. Print value not found.

In the following example, we will be searching for the integer 48, so the algorithm will visit the value at index 0:

...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image