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
IgorC [24]
3 years ago
4

javascript, Given an array of binary digits, 0 and 1, sort the array so that all zeros are at one end and all ones are at the ot

her. Which end does not matter. To sort the array, swap any two adjacent elements. Determine the minimum number of swaps to sort the array.
Computers and Technology
1 answer:
nexus9112 [7]3 years ago
7 0

Answer:

# Python Code:-

def minMoves(list1):

list2=[]

n=len(list1) # Length of list.

for i in range(n):

list2.append(list1[i])

 

#Counting number of swaps when 0 is left side and 1 is right side.

count1=0

for i in range(0,n-1):

for j in range(0,n-i-1):

if list1[j]>list1[j+1]:

count1+=1

list1[j],list1[j+1]=list1[j+1],list1[j]

#Counting number of swaps when 1 is left side and 0 is right side.

count2=0

for i in range(0,len(list2)-1):

for j in range(0,len(list2)-i-1):

if list2[j]<list2[j+1]:

count2+=1

list2[j],list2[j+1]=list2[j+1],list2[j]

return min(count1,count2)

def main():

num=int(input())

list1=[]

for i in range(0,num):

temp=int(input())

list1.append(temp)

min_swap= minMoves(list1)

print("Output : ",min_swap)

if _name=="main_":

main()

Output:

You might be interested in
When the system denies access to someone who is authorized it is called a - false negative?
babunello [35]
The computer declined the process for the password
5 0
4 years ago
______ have become a common and easily created form of malware that are creating using applications such as Visual Basic or VBSc
Helen [10]

Answer:

Macro Viruses

Explanation:

Macro Viruses have become a common and easily created form of malware that are creating using applications such as Visual Basic or VBScript.

7 0
3 years ago
Consider the playGame procedure below which calls on 3 other procedures: countFives, player1Move, and player2Move.
emmasim [6.3K]

Answer:

c. RETURN (count)

Explanation:

A typical return statement performs the function of terminating the execution of a function and returns control to the calling function.

Hence, there will execution resumed in the calling function at the point immediately following the call.

Another thing a return statement can do is to also return a value to the calling function.

The code RETURN (count) will

terminating the execution of a function and returns control to the calling function.

3 0
3 years ago
How do you implement instruction-level parallelism?
USPshnik [31]

A. by combining similar instructions into groups, which will then execute in parallel

5 0
3 years ago
Read 2 more answers
The first popular personal computer with a graphical user interface was the Apple Macintosh. Compaq Presario. IBM PC. NeXT works
Pavlova-9 [17]

Answer:

The answer is the Apple Macintosh

Explanation:

The Apple Macintosh PC was the first widely sold and most popular PC with a GUI. It was based on its earlier predecessor called the Apple Lisa which was later killed by the Apple Macintosh OS. Prior to the Apple Macintosh was the Xerox PARC which was the first PC to support an OS that was based on GUI. However, the Xerox was not a popular commercial product  and was intended for University research only

7 0
3 years ago
Other questions:
  • In Python, what kind of error is returned by the following code? (e.g. NameError, ValueError, IOError, etc.) def my_func(n1, n2)
    8·1 answer
  • Which three phrases describe a wireframe
    12·1 answer
  • Why process scheduling is needed in a uni-processor system?
    12·1 answer
  • Give three facts about the history of the train shongololo
    9·1 answer
  • What shortcut keys do i use to print something on my keyboard ?
    6·2 answers
  • Marsha is working on a group project and needs to start putting together a slide presentation for the group. Two of her group me
    5·1 answer
  • PLEASE HELP ASAP!!! 50 POINTS FOR TWO DIGITAL TECHNOLOGY MULTIPLE CHOICE QUESTIONS!!!
    13·1 answer
  • I have 2 questions How do i send a picture for someone to answer the hw?
    6·2 answers
  • In a dark place you have only a match , a twig , campfire logs , and oil lamp and a candle which do you literally first /
    15·1 answer
  • Write an article for publication on why every student should be computer literate​
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!