Our Blog

Dive into the latest trends, tutorials and insights in computer science. From AI advancements to coding best practices, our blog brings you a wealth of knowledge for tech enthusiasts and developers alike. Stay ahead of the curve with in-depth articles on programming, software development, cybersecurity and more!

Linear Search

This is a simple algorithm used to find a value in a list of 

  1. Identify a search term.
  2. Look at the first item in the list.
  3. Compare the item with the search term.
  4. Is the current item the same as the search term? If so, the item has been found. If not, move to the next item.
  5. Repeat from step two until the last item in the list has been reached.
  6. If the end of the list has been reached and the search term has not been found, then the search term is not in the list and the algorithm can stop.


    In 

    find <-- 1
    found <-- False
    length <-- length(list)
    counter <-- 0
    
    WHILE found = False AND counter <= length
         IF list[counter] = find THEN
              found <-- True
              OUTPUT 'Found at position', counter
            ELSE
              counter <-- counter + 1
            ENDIF
    ENDWHILE
    IF found = False THEN
       OUTPUT 'Item not found'
    ENDIF

Categories
Archive