Data-structures-algorithms-linear-search-algorithm

提供:Dev Guides
移動先:案内検索

データ構造とアルゴリズムの線形検索

線形検索は非常に単純な検索アルゴリズムです。 このタイプの検索では、すべてのアイテムを1つずつ順番に検索します。 すべてのアイテムがチェックされ、一致が見つかった場合、その特定のアイテムが返されます。それ以外の場合は、データ収集が終了するまで検索が続行されます。

線形検索アニメーション

アルゴリズム

Linear Search ( Array A, Value x)

Step 1: Set i to 1
Step 2: if i > n then go to step 7
Step 3: if A[i] = x then go to step 6
Step 4: Set i to i + 1
Step 5: Go to Step 2
Step 6: Print Element x Found at index i and go to step 8
Step 7: Print element not found
Step 8: Exit

疑似コード

procedure linear_search (list, value)

   for each item in the list
      if match item == value
         return the item's location
      end if
   end for

end procedure

Cプログラミング言語での線形検索の実装については、リンク:/data_structures_algorithms/linear_search_program_in_c [click-here]をご覧ください。