Algorithms and Flowchart linear search - Ishwaranand

News

Algorithms and Flowchart linear search

Linear Search

Q) Explain the linear search with an algorithm with an example.

  • Linear search is the sequential search. it is started from elements, in this search elements are checked sequentially until the required element is found.
  • When an element is found, the search is said to be successful. But when all elements are compared and the required element is not found then the search is said to be unsuccessful.

linear search in java, linear search in data structure, linear search in c, linear search python, linear search vs binary search, linear search time complexity, linear search pseudocode, linear search definition, binary search in c, linear search vs binary search, linear search in c using recursion, interval search algorithms, sequential search java, linear search in python, binary search in data structure, linear search algorithm python, linear search flowchart, interval search algorithm, interpolation search ppt, programiz binary search, linear search program in python, interval search,
Image Source ~ Crafted With ©Ishwaranand - 2020 ~ Image by ©Ishwaranand

Algorithm :linear_search (Data[], N Item, loc)

  • This is the algorithm for linear search
  • Data[] - Array of elements,
  • item - Element to be searched,
  • N - size of an array
  • loc - location
  • i - index variable
step 1 : Start
step 2 : Set i = 1
step 3 : Set loc = 0
step 4 : Repeat steps 5 and 6 until i <= n and loc = 0
step 5 : [compare Data[i] and item]
       if data[i] == utem the
          set loc=i
          Goto step7
       end if
step 6 : set i = i + 1
step 7 : if loc == 0 then
         print "item is not found"
      Else
        print "item is found at loc"
step 8 : stop

Example Linear Search

Consider the following example, having 7array elements.
1234567
1139564328
Element to search is: 64

Pass 1
Compare Data[1] with 64
1234567
1139564328
As Data[1] != 64 go for next pass

Pass 2
Compare Data[2] with 64
1234567
1139564328
As Data[2] != 64 go for next pass
Pass 3
Compare Data[3] with 64
1234567
1139564328
As Data[3] != 64 go for next pass

Pass 4
Compare Data[4] with 64
1234567
1139564328
As Data[4] != 64 go for next pass

Pass 5
Compare Data[5] with 64
1234567
1139564328
As Data[5] == 64 is Print "Element is Found"
Result: Given element 64 is found are the 5th position.

No comments

Comment on Ishwaranand or Happy Day
Not, Add any types of links