Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For each of the following functions code, calculate T(n), the running time it takes to solve a problem of size n, and find the corresponding

  1. For each of the following functions code, calculate T(n), the running time it takes to solve a problem of size n, and find the corresponding Big-O notation:
  1. Sequential search

def sequentialSearch(alist, item):

pos = 0

found = False

while pos < len(alist) and not found:

if alist[pos] == item:

found = True

else:

pos = pos+1

return found

  1. Bubble sort

def bubbleSort(alist):

for passnum in range(len(alist)-1,0,-1):

for i in range(passnum):

if alist[i]>alist[i+1]:

temp = alist[i]

alist[i] = alist[i+1]

alist[i+1] = temp

  1. Binary search

def binarySearch (alist, item):

first=0

last=len(alist)-1

found=False

While first<=last and not found

midpoint=(first+last)/2

If alist[midpoint]==item:

found=True

else:

if item

last=midpoint-1

else:

first=midpoint+1

return found

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

Focus On Geodatabases In ArcGIS Pro

Authors: David W. Allen

1st Edition

1589484452, 978-1589484450

More Books

Students also viewed these Databases questions

Question

The amount of work I am asked to do is reasonable.

Answered: 1 week ago

Question

The company encourages a balance between work and personal life.

Answered: 1 week ago