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
Liono4ka [1.6K]
3 years ago
15

In an array, we can swap the elements at any two indices in a single operation called a move. For example, if our array is a = {

17, 4, 8}, we can swap a0 = 17 and a2 = 8 to get a = {8,4,17} in a single move. We want to custom-sort an array such that all of the even elements are at the beginning of the array and all of the odd elements are at the end of the array.
Complete the function moves. The function must return the minimum of the moves it takes to sort an array of integers with all even elements at earlier indexes that any odd element.

Note: the order of the elements within even or odd doesn’t matter

Sample input 4,13,10,21,20

Sample output 1

In JavaScript

function moves(a) {

//you code here

}
Computers and Technology
1 answer:
quester [9]3 years ago
3 0

Answer:

function moves(a) {

   var left = 0;

   var right = a.length-1;

   var count = 0;

   while (left < right) {

       if(a[left] % 2 == 0) {

           left++;

           continue;

       }

       if(a[right] % 2 == 1) {

           right--;

           continue;

       }

       var temp = a[left];

       a[left] = a[right];

       a[right] = temp;

       left++;

       right--;

       count++;

   }

   return count;

}

var a = [4,13,10,21,20];

console.log('Number of moves: ' + moves(a));

console.log('Sorted array: ' + a);

Explanation:

You might be interested in
The components of hardware include:
zlopas [31]

Answer:

A

Explanation:

Monitor, CPU, Disk Drives, Printer, Keyboard/mouse

5 0
3 years ago
Read 2 more answers
When resizing images or objects in a presentation, why should a user not utilize the sizing handles in the middle of the sides
Shalnov [3]

When resizing an image or an object in a presentation, a user should not utilize the sizing handles in the middle of the sides or the bottom of the image. There's nothing wrong with resizing this way.

There's nothing wrong with resizing this way

<u>Explanation:</u>

When the sizing handles in the middle of the sides are used, the image stretches out reflecting an increase in the width maintaining There's nothing wrong with resizing this way.

On the other hand, while using the sizing handles at the bottom, the image increases in height whilst maintaining the same width again disturbing the aspect ratio.

5 0
3 years ago
Read 2 more answers
Split the worksheet into panes at cell G1.
nikdorinn [45]

Answer:

1. Select below the row where you want the split, or the column to the right of where you want the split.

2. On the View tab, in the Window group, click Split.

Explanation:

3 0
3 years ago
Perform algorithm time measurement for all three quadratic sorting algorithms for Best Case (already sorted), Average Case (rand
Kaylis [27]

Answer:

Experiment size : 50,000

==================================

Selection sort :

---------------------------------------------------------

Worst case : 0.162

Average case : 0.116

Best case : 0.080

Insertion sort :

---------------------------------------------------------

Worst case : 0.162

Average case : 0.116

Best case : 0.080

Bubble sort:

--------------------------------------------------------

Worst case : 0.211

Average case : 0.154

Best case : 0.117

Experiment size : 100,000

==================================

Selection sort :

---------------------------------------------------------

Worst case : 0.316

Average case : 0.317

Best case : 0.316

Insertion sort :

---------------------------------------------------------

Worst case : 0.316

Average case : 0.317

Best case : 0.316

Bubble sort:

--------------------------------------------------------

Worst case : 0.482

Average case: 0.487

Best case : 0.480.

Experiment size : 200,000

==================================

Selection sort :

---------------------------------------------------------

Worst case : 1.254

Average case : 1.246

Best case : 1.259

Insertion sort :

---------------------------------------------------------

Worst case : 1.254

Average case : 1.246

Best case : 1.259

Bubble sort:

--------------------------------------------------------

Worst case : 1.990

Average case : 2.009.

Best case : 1.950

Explanation:

[NB: since it is very long there is the need for me to put it it a document form. Kindly check the doc. Files. The file A is the sort Analysis.Java file and the file B is the sort.Java file].

The concept of algorithm time measurement strictly depends on the following;

=> The measurement of time, space or energy on different sizes.

=> Plotting of the measurements and characterizing them.

=> Running or implementation of the algorithm.

Programming language such as Java can be used in accessing the operating system clock and Java had two static methods.

KINDLY CHECK BELOW FOR THE ATTACHMENT.

Download doc
<span class="sg-text sg-text--link sg-text--bold sg-text--link-disabled sg-text--blue-dark"> doc </span>
<span class="sg-text sg-text--link sg-text--bold sg-text--link-disabled sg-text--blue-dark"> doc </span>
5 0
3 years ago
Next, Kim decides to include a diagram of a frog’s life cycle in her presentation. She wants to use an image that is part of a p
kap26 [50]

Answer:

B, C, D, and F are correct answers

Explanation:

On edg

8 0
4 years ago
Read 2 more answers
Other questions:
  • A(n) _____ is a fake online persona created to promote a particular point of view, often in praise of a firm, product, or indivi
    15·1 answer
  • which option will joan use to get a glimpse of how her presentation will look like when she presents it to her audience
    11·2 answers
  • Which one of the following words means most nearly the opposite of RANDOM? (remember,opposite)
    12·1 answer
  • An application server is used to communicate between a Web server and an organization's back-end systems.
    6·1 answer
  • You want to centrally back up the files users store in the Documents folder in their user profiles, but you don’t want users to
    7·1 answer
  • Answer the following
    11·1 answer
  • Which system is a type of artificial intelligence that uses a database, containing facts and rules, to provide assistance to use
    9·1 answer
  • Monica needs to work on a document where she has to highlight topics in bold and add emphasis to some words in a paragraph using
    9·1 answer
  • Electronic age,what format/equipment people use to communicate with each other?​
    7·2 answers
  • The processes of only seeing only some records frome data table is called as what​
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!