1. Engineering
  2. Computer Science
  3. 2 a write pseudocode for linear search assuming that the...

Question: 2 a write pseudocode for linear search assuming that the...

Question details

2) 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. 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. Problem: Linear Search in a sorted (in ascending order) list Input: list A.] n: the length of list A y: the value we are searching A[1...n] for and A[ FA[2]<= <-A[n-1 ]<=A[n] Example, 1) list A-13,4,6,9], n-4, v-7, return -4 2) list A-[3,4,6,9], n-4, v-6, return 3 Algorithm: Linear-Search (A, n, v) (b) For your pseudocode, give a problem instance for which the algorithm performs n operations (where n is the length of the list), and returns -n comparison

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution