1. Engineering
  2. Computer Science
  3. 1 lnear search on sorted list a write pseudocode for...

Question: 1 lnear search on sorted list a write pseudocode for...

Question details

1 Lnear Search on sorted list (a) Write pseudocode for linear search, assuming that the input list is already sorted, and also return the would-be index for the key if the key is not in the list. Note: Your algorithm should take advantage of the fact that the list is sorted, but still looks for the value by comparing the list elements one by one with the value. Problom: Linear Search in a sorted (in ascending order) 1ist Input: list A[1... n: the length of listA v: the value ve are searching A(1...n] for and A[1]<#A [2] <-...(aatn-1]<-A [n] Output: if v appears in list A[1...n], return the index of the its first appearance if v does not appear in the list, return the negation of the vould-be index of v (i.e., the index of v if v is inserted into the sorted list and the ascending order is to be maintained) for example, 1) list A-[3,4,6,9], n-4, v-7, the function shall return -4 2) list A-[3,4,6,9], n-4, v-6, the function shall return 3 Algorithm: Linear-Search (A, n, v)
Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution