Question

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 anything.
If you have debugging or testing print statements in the function, 
comment them out before doing any timing.


Testing
-------
Create a list of five random numbers. Use randint, don't hardcode.
Demonstrate your algorithm finding each of the numbers.
in the list. Then look for a number not in the list.
You may write a testing function if you wish, params and
returns up to you, or do all testing in the main program.

expected output (use different numbers than in the example)


       numbers [5, 8, 3, 11, -2]

       searching for 5
       expected index: 0
       returned index: 0
       test passed: YES

       searching for 8
       expected index: 1
       returned index: 1
       test passed: YES

       searching for 3
       expected index: 2
       returned index: 2
       test passed: YES

       searching for 11
       expected index: 3
       returned index: 3
       test passed: YES

       searching for -2
       expected index: 4
       returned index: 4
       test passed: YES

       searching for 100
       expected index: -1
       returned index: -1
       test passed: YES

       passed 6 out of 6 tests


Timing
------
Make sure you are timing the WORST CASE for sequential search.
That means look for a value you know is not in the list.

Do NOT include list creation in your timing. Do NOT include any input.
Only time sequential search. If you laptop is very fast, you might
have to time many calls to sequential search, not just one call.
To get the time for just one call, divide by the number of calls.

example:


       repetition_count = 10000

       time_start = time()

       for rep in range( repetition_count ):
           ind = sequential_search( value, my_list )

       time_end = time()
       time_all_reps = time_end - time_start
       time_one_rep = time_all_reps / repetition_count


You may create the timing table in your program so you don't have to
type it up in Word. If you do that, your table must have neat columns
that line up and 3 or 4 significant figures after leading zeros.

example:


    list     single        comparison time
    length   search time   or C estimate

      2000   0.000205      1.025e-07    
      4000   0.0004391     1.098e-07    
      6000   0.0006798     1.133e-07    
      8000   0.0008866     1.108e-07    
     10000   0.001112      1.112e-07    
0 0
Add a comment Improve this question Transcribed image text
Answer #1

# A Python program that uses Logical Not or ! on boolean

import random

def sequential_search(alist, item):

pos = 0

while pos < len(alist):

if alist[pos] == item:

return pos

else:

pos = pos+1

return -1

numbers= []

for i in range (5):

numbers.append(random.randint(0, 100))

  

print(numbers)

for i in range (5):

print(sequential_search(numbers,random.randint(0, 100)))

ganonymous/untitled input clear run share save Python 3.6.1 (default, Dec 2015, 13:05:11) [GCC 4.8.2] on linux # A Python pro

Add a comment
Know the answer?
Add Answer to:
Sequential Search Algorithm Python Programming Objectives ---------- * sequential search - design, analyze, implement, test, time...
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
  • Write and implement a recursive version of the sequential search algorithm. Test the algorithm with an...

    Write and implement a recursive version of the sequential search algorithm. Test the algorithm with an array that have ten integer values, user can enter the values or assigned the values to the array in the main method. The search key should be a value in the array or not in the array. JAVA!!!

  • The binary search algorithm from Chapter 9 is a very efficient algorithm for searching an ordered...

    The binary search algorithm from Chapter 9 is a very efficient algorithm for searching an ordered list. The algorithm (in pseudocode) is as follows: highIndex - the maximum index of the part of the list being searched lowIndex - the minimum index of the part of the list being searched target -- the item being searched for //look in the middle middleIndex = (highIndex + lowIndex) / 2 if the list element at the middleIndex is the target return the...

  • C++ Time the sequential search and the binary search methods several times each for randomly generated...

    C++ Time the sequential search and the binary search methods several times each for randomly generated values, then record the results in a table. Do not time individual searches, but groups of them. For example, time 100 searches together or 1,000 searches together. Compare the running times of these two search methods that are obtained during the experiment. Regarding the efficiency of both search methods, what conclusion can be reached from this experiment? Both the table and your conclusions should...

  • Arrays Arravs Introduction Your ninth programming assignment will consist of two C++programs. Your programs should compile...

    Arrays Arravs Introduction Your ninth programming assignment will consist of two C++programs. Your programs should compile correctly and produce the specified output. Please note that your programs should comply with the commenting and formatting rules we discussed in class. Please see the descriptive ile on eLearning for details. Program 1- Linear Search Algorithm In Computer Science, it is often very important to be able to locate a specific data item inside a list or collection of data. Algorithms that perform...

  • Parallel Arrays are two arrays, often containing elements of different datatypes that are synced with a...

    Parallel Arrays are two arrays, often containing elements of different datatypes that are synced with a common index. For this problem you are going to create a function called FindHighest that will accept two parameters: names and calls. The names list will contain the names of individuals that work on a help desk. The calls list will contain the number of calls they received in one day. Your function will return back to main the name of the person who...

  • Python pls CENGAGE MINDTAP Q Search this course Programming Exercise 11.1 x Instructions search.py + >_...

    Python pls CENGAGE MINDTAP Q Search this course Programming Exercise 11.1 x Instructions search.py + >_ Terminal + A sequential search of a sorted list can halt when the target is less than a given element in the list. 1 " 2 File: search.py 3 Project 11.1 4 5 Optimizes sequential search for sorted lists. 6 The complexity is O(n) in the worst case and 0(1) in the best case. 7 The average case is less than n / 2,...

  • In C language Write a program that includes a function search() that finds the index of...

    In C language Write a program that includes a function search() that finds the index of the first element of an input array that contains the value specified. n is the size of the array. If no element of the array contains the value, then the function should return -1. The program takes an int array, the number of elements in the array, and the value that it searches for. The main function takes input, calls the search()function, and displays...

  • Problem 1: Implement an algorithm to generate prime numbers. You will need to implement the following...

    Problem 1: Implement an algorithm to generate prime numbers. You will need to implement the following ingredients (some of them you developed for earlier assignments): 1. A method to generate random binary numbers with n-digits (hint: for the most significant digit, you have no choice, it will be 1; similarly, for the least significant digit there is no choice, it will have to be 1; for all other position, generate 0 or 1 at random) 2. A method to compute...

  • Just Q3 and Q4 Q1] Write a C function to implement the binary search algorithm over...

    Just Q3 and Q4 Q1] Write a C function to implement the binary search algorithm over an array of integer numbers and size n. The function should return the index of the search key if the search key exists and return - 1 if the search key doesn't exist. [10 Points] Q2] Write a C function to implement the selection sort algorithm, to sort an array of float values and size n. The function should sort the array in ascending...

  • I need help writing this code in C++ Proj11.cpp is provided as well as the randomdata.txt thank you in advance! Objectives: The main objectives of this project is to introduce you to recursion,...

    I need help writing this code in C++ Proj11.cpp is provided as well as the randomdata.txt thank you in advance! Objectives: The main objectives of this project is to introduce you to recursion, and test your ability to work with some STL functionalities. A review of your knowledge on working with templates, dynamic data structures, as well as manipulating dynamic memory, classes, pointers and iostream to all extents, is also included. Description: For the entirety of this project, you will...

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