Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a function HowM any(A, x) where A is a sorted list of integers and x is an integer number. The function should return the

Write a function HowM any(A, x) where A is a sorted list of integers and x is an integer number. The function should return the number of elements of A that are equal x. For example if A = [1, 2, 4, 4, 4, 5, 15] and x = 4 then HowM any(A, x) should return 3. The runtime of the function should be O(log n)?

My current solution is O(n)

def HowMany(A,x): count = 0 for i in range(0,len(A)): if A[i] == x : count +=1 return count HowMany([1,2,2,2,3,2,4],2)

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

Successful Keyword Searching Initiating Research On Popular Topics Using Electronic Databases

Authors: Randall MacDonald, Susan MacDonald

1st Edition

0313306761, 978-0313306761

More Books

Students also viewed these Databases questions

Question

Define promotion.

Answered: 1 week ago

Question

Write a note on transfer policy.

Answered: 1 week ago

Question

Discuss about training and development in India?

Answered: 1 week ago

Question

Explain the various techniques of training and development.

Answered: 1 week ago

Question

Employ effective vocal cues Employ effective visual cues

Answered: 1 week ago