a. b. Given the following algorithm, def Linear Search(a,x): for i in range(0, len(a)): if a[i]...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
a. b. 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? What will be the result if a = [1, 4, 2, 0] and a = 10? a. b. 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? What will be the result if a = [1, 4, 2, 0] and a = 10?
Expert Answer:
Answer rating: 100% (QA)
Lets use the provided Linear Search algorithm to find the results for the given values of a and x Case 1 a 1 2 5 3 x 2 def LinearSearcha x for i in range0 lena if ai x return i return 1 a 1 2 5 3 x 2 result LinearSearcha x printresult Output 1 Explanation The element 2 is present at index 1 in the array a Case 2 a 1 4 2 0 x 10 def LinearSearcha x for i in range0 lena if ai x return i return 1 a 1 4 2 0 x 10 result LinearSearcha x printresult Output 1 Explanation The element 10 is not present in the array a so the function returns 1 To summarize For a 1 2 5 3 and x 2 the result ... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
A scientist repeats the Millikan oil drop experiment in a different galax the electrino (el). The scientist obtains data for four drops. Calculated charge (el) 6.44 10-4 el 4.14 10-4 el 5.98 10-4 el...
-
Describe the pattern formed by the sums of the numbers along the diagonal line segments shown in Pascal's Triangle (see figure). Row 0 Row 1 Row 2 Row 3 1- Row 4 10 10
-
Using the IEEE 754 floating point format, write down the bit pattern that would represent A. Can you represent A exactly? The following table shows pairs, each consisting of a fraction and an...
-
Pooling agreements have been outlawed in all states. True/false
-
Takei Company's payroll for the week ending January 15 amounted to $367,000 for salaries and wages. None of the employees has reached the earnings limits specified for federal or state employer...
-
Early in January 2021, Hopkins Company is preparing for a meeting with its bankers to discuss a loan request. Its bookkeeper provided the following accounts and balances at December 31, 2020. Except...
-
In refrigeration cycle, heat is (a) Abstracted from the lower temperature region and discarded to the higher one (b) Absorbed from the higher temperature region and discarded to the lower one (c)...
-
A shirt manufacturer buys cloth by the 100- yard roll from a supplier. For setting up a control chart to manage the irregularities (e. g., loose threads and tears), the following data were collected...
-
(a) Find the equation of the line perpendicular to 2x-7y=11 that goes through the point (-3,-1) (b) Find the equation of the line going through the point (-3,-6) and parallel to 5y-7x=9 (c) Find the...
-
Fantastique Bikes is a company that manufactures bikes in a monopolistically competitive market. The following graph shows Fantastique?s demand curve, marginal revenue curve (MR), marginal cost curve...
-
These items are taken from the financial statements of Sheffield Corp. at December 31, 2022. Buildings Accounts receivable Prepaid insurance Cash Equipment Land Office expense Income tax expense...
-
A speculator is considering the purchase of five three-month Japanese yen call options with an exercise price of $0.0096 per yen. Each option contract is for 1,000,000 yens. The option premium is...
-
South Korea's Employment Laws Slowly Adapt to Aging Population After 40 years working as an elementary school principal, Chae Jae-min now drives a delivery truck. At 64, he has few other choices. The...
-
The coronavirus (COVID-19) pandemic has severely impacted multinational corporations (MNCs) and foreign direct investment (FDI) in developing countries, jeopardizing these firms' contributions to...
-
Menu eecda284-34f7-42f9-b7d... X + Create All tools Edit Convert Sign John Bratton works for a medium sized company trading on the Toronto Stock Exchange (TSX). In 2019, he earns an annual salary of...
-
Determine the moment in N.m about line OB of the force F. F = 595 N. N 325 mm 150 mm Fr P 350 mm y K 400 mm a. MOB = -76.3 N.m b. MOB = -124.9 N.m c. MOB = -44.6 N.m d. MOB = 76.8 N.m 275 mm X
-
Suppose you work for a company that manufactures electronics. The development analysts estimate that 3% of their flagship product will fail within 2 years of the purchase date, with a replacement...
-
Consider the discrete group G of order 8 that has the following Cayley diagram e If we have the sequence of operations: fcagec, which of the options represents the reduction of the sequence to a...
-
The velocity of an automobile starting from rest is where is measured in feet per second. Find the acceleration at (a) 5 seconds (b) 10 seconds (c) 20 seconds v(t) = 100t 2t + 15
-
In Exercise create a table of values for the function and use the result to estimate the limit. Use a graphing utility to graph the function to confirm your result. x - - 1 lim x1x6-1
-
In Exercises verify that has an inverse. Then use the function and the given real number a to find ( - )'(a). f(x) = x - 4, a = 2
-
Last year during the week of July 4th, Murrysville Regional Hospital reported that they treated 264 patients for fireworks-related injuries.
-
The number of stores a person visits on a shopping trip Name and define the four types of measurement levels used in statistics. determine whether the data are qualitative or quantitative.
-
During a recent year, the average U.S. diners spent a month on food prepared outside the home was \($144\) . What is meant by a biased sample? determine whether descriptive or inferential statistics...
Study smarter with the SolutionInn App