1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Svetlanka [38]
4 years ago
7

Implement the function def findChange(lst01). This function is given lst01, a list of integers containing a sequence of 0s follo

wed by a sequence of 1s. When called, it returns the index of the first 1 in lst01. For example, if lst01 is a list containing [0, 0, 0, 0, 0, 1, 1, 1], calling findChange(lst01) will return 5. Note: Pay attention to the running time of your function. If lst01 is a list of size �, an efficient implementation would run in logarithmic time (that is Θ(���'(�))).

Computers and Technology
1 answer:
Mashcka [7]4 years ago
7 0

<u>Solution and Explanation:</u>

The following is the function which will implement the required change as asked in the question.

def findChange(lst01):

left = 0

right = len(lst)-1

while (left <= right):

   middle = (left + right)// 2

   if (lst01[middle] == 1 and (middle == 0 or lst01[middle - 1] == 0)):

     return middle

   elif (lst01[middle] == 1):

     right = middle - 1

   else:  

     left = middle + 1

return -1;

lst = [0, 0, 0, 0, 0, 1,1]  

print(findChange(lst))

Please see the attched file.

You might be interested in
All windows on the desktop have width and height (as well as numerous other attributes). However the actual contents of the wind
Cerrena [4.2K]

Answer:

The abstract class Window:

public abstract class Window

Two integer instance variables, width and height:

private int width, height;

Two accessor methods, getWidth and getHeight:

public int getWidth()

public int getHeight()

A constructor that accepts two integers and uses them to initialize the two instance variables:

public Window(int var1, int var2) {width =var1; height = var2;}

An abstract void-returning method named paint that accepts no parameters

public abstract void paint();

Explanation:

Abstract keyword is used with Windows class to make this class an abstract class which means no object can be created using this class.

Two private instance variable width and height. Private means they are not accessible outside this class.

Then getWidth and getHeight methods are used to return width and height.

The constructor takes two integer type variables var1 and var2. These two variable are used to initialize the variables width and height. Constructor has the same name as that of the class.

Method paint() is an abstract method with the return type void which has no parameters.  

So here is what the class with all its methods and instance variables looks.

public abstract class Window {

private int width, height;

public Window(int a, int b) {width = a; height = b;}

public int getWidth(){ return width; }

public int getHeight(){ return height; }

public abstract void paint();

}

6 0
3 years ago
Plagiarism occurs when writers
Law Incorporation [45]
The answer is A. <span>Use others' ideas and writing as their own </span>
7 0
4 years ago
Read 2 more answers
List 2 end to end test commands. <br><br> Will mark Brainliest!!
Delvig [45]

Answer:

ibm pll

Explanation:

4 0
3 years ago
"Look at the following code. Which line will cause a compiler error?
crimeas [40]

Answer:

i got a feeling c

Explanation:

5 0
3 years ago
What is computer-aided design/computer-aided manufacturing (CAD/CAM)? a.A cultural trend that places value on an individual's ab
masha68 [24]

Answer:

C. RFID tag Systems are used to create the digital designs and then manufacture the products

7 0
3 years ago
Other questions:
  • PYTHON CODE ONLY:
    7·1 answer
  • Sam has been asked to classify a number of different processing systems that his consultancy's client uses.
    9·1 answer
  • A DSLR camera is made up of two parts. They are
    13·2 answers
  • A production house needs an operating system that captures, saves, and generates information within specific time. Which type of
    13·2 answers
  • Instructions:Select the correct answer.
    5·1 answer
  • Beverly is creating a website for her new clothing company. Aside from including photographs, how can she use the index page to
    8·2 answers
  • Which job role requires you to create user guides for computer products and services?
    13·2 answers
  • Explain why the effect of stimulant and depressants do not necessarily counteract<br>each other​
    5·1 answer
  • What do other people think of e.t <br> in the movie E.T
    5·1 answer
  • Question 2 if you have a slow computer, what are some possible culprits that could be causing this? select all that apply
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!