Question

Python plsCENGAGE MINDTAP Q Search this course Programming Exercise 11.1 x Instructions search.py + >_ Terminal + A sequential search o

0 0
Add a comment Improve this question Transcribed image text
Answer #1

def sequentialSearch(target, lyst):
    position = 0
    while position < len(lyst):
        if target == lyst[position]:
            return position
        if target < lyst[position]:
            return -1
        position += 1

    return -1

def main():
    print(sequentialSearch(3,[0,1,2,3,4]))
    print(sequentialSearch(3,[0,1,2]))
    print(sequentialSearch(3,[0,4,5,6]))

if __name__ == "__main__":
    main()
      

#Best case = O(1)
#Average case = O(n)
#Worst case = O(n)

Add a comment
Know the answer?
Add Answer to:
Python pls CENGAGE MINDTAP Q Search this course Programming Exercise 11.1 x Instructions search.py + >_...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • . CENGAGE MINDTAP Q Search this course OX Programming Exercise 2-3 0 Instructions InchesToCentimeters... Σ. Terminal...

    . CENGAGE MINDTAP Q Search this course OX Programming Exercise 2-3 0 Instructions InchesToCentimeters... Σ. Terminal + 3 inches is 7.62 centimet ers Convert the InchesToCentimeters program to an interactive application named InchesToCentimetersInteractive. 600 vau AWN 1 using static System.Console; 2 class InchesToCentimeters Interactive 3 { static void Main() 5 { 6 const double CENTIMETERS_PER_INCH = 2.54; double inches = 3; Line("{0} inches is {1} centimeters", inches, inches * CENTIMETERS_PER_INCH); Instead of assigning a value to the inches variable, accept...

  • Language = c++ Write a program to find the number of comparisons using the binary search...

    Language = c++ Write a program to find the number of comparisons using the binary search and sequential search algorithms as follows: o Suppose list is an array of 1000 elements. o Use a random number generator to fill the list. o Use the function insertOrd to initially insert all the elements in the list. o You may use the following function to fill the list: void fill(orderedArrayListType& list) {       int seed = 47; int multiplier = 2743;                                ...

  • Sequential Search Algorithm Python Programming Objectives ---------- * sequential search - design, analyze, implement, test, time...

    Sequential Search Algorithm Python Programming Objectives ---------- * sequential search - design, analyze, implement, test, time * continue practicing previously learned skills: algorithm analysis, graphing with theoretical prediction curves Implementation -------------- Write a function named sequential_search. It must have two parameters, a list to search and a value to search for. It must return either the index of the value within the list or -1 if the value is not found in the list. Your search function should NOT print...

  • Consider the following Python function: def find_max (L): max = 0 for x in L: if...

    Consider the following Python function: def find_max (L): max = 0 for x in L: if x > max: max = x return max Suppose list L has n elements. In asymptotic notation, determine the best case running time as function of n In asymptotic notation, determine the worst case running time as function of n Now, assume L is sorted. Give an algorithm that takes asymptotically less time than the above algorithm, but performs the same function. Prove that...

  • C programming (you don't need to write program) Problem 1 [Linear Search with Early Stop] Below...

    C programming (you don't need to write program) Problem 1 [Linear Search with Early Stop] Below you will find a linear search function with early stop. A linear search is just a naive search - you go through each of the elements of a list one by one. Early stop works only on sorted list. Early stop means, instead of going through whole list, we will stop when your number to search can no longer be possibly found in the...

  • Q Search this course CENGAGE MINDTAP X ECO201 Homework (Ch 13) 5. Costs in the short...

    Q Search this course CENGAGE MINDTAP X ECO201 Homework (Ch 13) 5. Costs in the short run versus in the long run Ike's Bikes is a major manufacturer of bicycles. Currently, the company produces bikes using only one factory. However, it is considering expanding production to two or even three factories. The following table shows the company's short-run average total cost (SRATC) each month for various levels of production if it uses one, two, or three factories. (Note: Q equals...

  • Assume a hash table is implemented using chaining with buckets implemented using sorted linked lists. What's...

    Assume a hash table is implemented using chaining with buckets implemented using sorted linked lists. What's the worst-case time complexity of inserting a data item? (n is the size of data) Oin None of these Oina) O(nLogin) O 0(1) D Question 22 2 pts Assume a hash table is implemented using chaining with buckets implemented using binary search trees. What's the average-case time complexity of searching for a data item? Assume the size of data, n, is not much larger...

  • Programming Exercise 11.6 Х + | Instructions fib.py >_ Terminal + iit B 1 def fib(n):...

    Programming Exercise 11.6 Х + | Instructions fib.py >_ Terminal + iit B 1 def fib(n): 2 "*"Returns the nth Fibonacci number. " 3 if n < 3: lil 4 return 1 Modify the recursive Fibonacci function to employ the memoization technique discussed in this chapter. The function creates a dictionary and then defines a nested recursive helper function named memoizedFib You will need to create a dictionary to cache the sum of the fib function. The base case of...

  • CENGAGE MINDTAP Search this course Assignment 04 - Analysis of Financial Statements 0 X 3. Asset...

    CENGAGE MINDTAP Search this course Assignment 04 - Analysis of Financial Statements 0 X 3. Asset management ratios A Aa E Asset management ratios are used to measure how effectively a firm manages its assets, by relating the amount a firm has invested in a particular type of asset (or group of assets) to the amount of revenues the asset is generating. Examples of asset management ratios include the average collection period (also called the days sales outstanding ratio), the...

  • I'm trying to sort a list of students from a text file in python(3.7) with three separate sorting functions (Bubble, selection, insert) I'm not sure to why as its not working I'm going to...

    I'm trying to sort a list of students from a text file in python(3.7) with three separate sorting functions (Bubble, selection, insert) I'm not sure to why as its not working I'm going to guess its because I'm not using the swap function I built. Every time I run it though I get an error that says the following Traceback (most recent call last): File "C:/Users/tkoto/Desktop/SearchAndSortLab.py", line 146, in <module> main() File "C:/Users/tkoto/Desktop/SearchAndSortLab.py", line 122, in main studentArray.gpaSort() File "C:/Users/tkoto/Desktop/SearchAndSortLab.py",...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT