a. Given the following algorithm, def Linear Search(a, x): for i in range(0, len(a)): if a[i] == x: return i return -1 What will be the result if a = [1,2,5,3] and x = = 2? b. What will be the result if a = [1,4,2,0] and x = 10?

Elements Of Modern Algebra
8th Edition
ISBN:9781285463230
Author:Gilbert, Linda, Jimmie
Publisher:Gilbert, Linda, Jimmie
Chapter8: Polynomials
Section8.2: Divisibility And Greatest Common Divisor
Problem 31E
icon
Related questions
Question
a.
Given the following algorithm,
def Linear Search(a, x):
for i in range(0, len(a)):
if a[i] == x:
return i
return -1
What will be the result if a = [1,2,5,3] and x = = 2?
b.
What will be the result if a = [1,4,2,0] and x = 10?
Transcribed Image Text:a. Given the following algorithm, def Linear Search(a, x): for i in range(0, len(a)): if a[i] == x: return i return -1 What will be the result if a = [1,2,5,3] and x = = 2? b. What will be the result if a = [1,4,2,0] and x = 10?
Expert Solution
steps

Step by step

Solved in 1 steps

Blurred answer
Recommended textbooks for you
Elements Of Modern Algebra
Elements Of Modern Algebra
Algebra
ISBN:
9781285463230
Author:
Gilbert, Linda, Jimmie
Publisher:
Cengage Learning,
Linear Algebra: A Modern Introduction
Linear Algebra: A Modern Introduction
Algebra
ISBN:
9781285463247
Author:
David Poole
Publisher:
Cengage Learning