O'Reilly logo

C by Nikolaos D. Tselikas, George S. Tselikis

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 12

Searching and Sorting Arrays

This chapter describes the most common and simplest algorithms used for searching a value in an array and for sorting the elements of an array in ascending or descending order.

Searching Arrays

To check if a value is stored into an array, we are going to describe the linear and binary search algorithms.

Linear Search

The linear search algorithm (also called sequential search) is the simplest algorithm to search for a value in a nonsorted array. The searched value is compared against the value of each element until a match is found.

In an array of n elements, the maximum number of searches is n. This may occur if the searched value is not found or is equal to the last element.

In the following program, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required