Question: Write a program (a3.py) that has 3 function definitions: magic-sequential(), magic-binary(), and main(). You will write the code for the above functions. Both magic functions

Write a program (a3.py) that has 3 function definitions: magic-sequential(), magic-binary(), and main().

  • You will write the code for the above functions.
  • Both magic functions (magic-sequential() and magic-binary()) will look for a magic index in a given sorted list of distinct integers.
    • A magic index in a list myList[0 ... n-1] is defined to be an index i such that myList[i] = i .
    • Both functions receive the list as a parameter and return an integer: either the magic index, if one exists, or -1 if a magic index does not exist in the list. If more than one magic index exist, return the first one found.
  • The function magic-sequential() must use sequential search to traverse the list.
  • The function magic-binary() must use binary search to find the magic index.
    • You should not use any built-in python function or method to perform the search - you must write the logic for the search algorithm.
      • It's okay to use len(), print(), input(), int(), range(), append().
  • The function main() must prompt the user to enter unique integers, in ascending order. Add these numbers to a list and then call both count functions passing the same list as a parameter. Print the results from both function calls.
  • At the bottom of a3.py (after the three function definitions), call main() to execute the code.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!