Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.
    • You may choose any stopping criteria for the users to indicate they are done entering numbers. For example, one way would be: when the user enters a number that is less than the previous number.
  • 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

OCA Oracle Database SQL Exam Guide Exam 1Z0-071

Authors: Steve O'Hearn

1st Edition

1259585492, 978-1259585494

More Books

Students also viewed these Databases questions

Question

Identify possible reasons for ineffective performance.

Answered: 1 week ago

Question

Describe the components of a needs assessment.

Answered: 1 week ago

Question

Describe the benefits of employee orientation.

Answered: 1 week ago