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
hodyreva [135]
3 years ago
13

Consider sorting n numbers stored in array A by first finding the smallest element of A and exchanging it with the element in A[

1]. Then find the second smallest element of A, and exchange it with A[2]. Continue in this manner for the first n − 1 elements of A. Write pseudocode for this algorithm, which is known as selection sort. What loop invariant does this algorithm maintain? Why does it need to run for only the first n − 1 elements, rather than for all n elements? Give the best–case and worst–case running times of selection sort in Θ–notation.
Computers and Technology
1 answer:
krek1111 [17]3 years ago
7 0

Answer:

1. create the first array A

2. create the second array A1, the same length as array A.

3. create a loop to iterate over both arrays for a number of times specific to the length of the arrays, with a condition to get and pop only the minimum value of which arrays for every loop.

4. save both items to "a" for minimum value A and "b" for minimum value A1.

5. call a function to push the "a" variable value to A1 and "b" variable value to the array A.

Explanation:

This code would interchange the values of both arrays, the best-case scenario for the code is O( n ) where n is the number of items in both arrays and worst is the best-case multiplied by the number of time to compare all the items with the minimum value.

You might be interested in
Write a python program to accept a number and check whether it is divisible by 4 or not​
Alenkasestr [34]

Answer:

number = int(input("Enter number: "))

if (number % 4):

 print("{} is not divisible by 4".format(number))

else:

 print("{} is divisible by 4".format(number))

Explanation:

If the %4 operation returns a non-zero number, there is a remainder and thus the number is not divisable by 4.

5 0
2 years ago
Assume the variable myWord references a string. Write a statement that uses a slicing
givi [52]

Answer:

"myWord[-5:]"

Explanation:

So whenever you slice a string, the syntax in python is expressed as:

string[a:b:c]

where a=start index (this is included in the sliced string)

b = end index (this is excluded from the sliced string)

c = increment

If any of these are included, they are set to default values, where a=0, b=len(string), and c=1.

The increment isn't necessary here, and it's just so you know the syntax a bit more

Anyways, I'm assuming when the question asks to display "the last 5 characters in the string" it means in order? e.g "abcdefghijk" -> "ghijk" and not "abcdefghijk" -> "kjihg"

The last piece of information to know is what a negative index represents.

For example if I have the piece of code

"

string = "hello world"

print(string[-1])

"

This will output "d", and the negative 1 represents the last letter. If you did -2, it would output the 2nd to last letter and so on.

So to print the last 5 characters, we simply use the -5 as the starting index.  

"

string = "hello world"

print(string[-5:])

"

This will print "world" or in other words, the last 5 letters. The reason for this is because the -5 in the first spot means the starting index is the 5th to last letter, and when you have the : after the -5, this is the way of telling python you're slicing the string, and not indexing 1 character. You don't need to include another value after that, because it will default to the last index of the string, or more specifically the last index + 1, since the last index is still included.

So the last thing to know, is that if the string isn't greater than 5 characters, it just prints the entire string, and no errors are raised. You can test this out your self as well. So whenever you have a string that's less than 5 characters the entire string is outputted.

3 0
1 year ago
four quantum numbers that could represent the last electron added (using the Aufbau principle) to the Argon atom. A n = 2, l =0,
marshall27 [118]

Answer:

  • n = 3
  • l  = 1
  • m_l = 1
  • m_s=+1/2

Explanation:

Argon atom has atomic number 18. Then, it has 18 protons and 18 electrons.

To determine the quantum numbers you must do the electron configuration.

Aufbau's principle is a mnemonic rule to remember the rank of the orbitals in increasing order of energy.

The rank of energy is:

1s < 2s < 2p < 3s < 3p < 4s < 3d < 4p < 5s < 4d < 5p < 6s < 4f < 5d < 6p < 7s < 5f < 6d < 7d

You must fill the orbitals in order until you have 18 electrons:

  • 1s² 2s² 2p⁶ 3s² 3p⁶   : 2 + 2 + 6 + 2 + 6 = 18 electrons.

The last electron is in the 3p orbital.

The quantum numbers associated with the 3p orbitals are:

  • n = 3

  • l = 1 (orbitals s correspond to l = 0, orbitals p correspond to l  = 1, orbitals d, correspond to l  = 2 , and orbitals f correspond to  l = 3)

  • m_l can be -1, 0, or 1 (from - l  to + l )

  • the fourth quantum number, the spin can be +1/2 or -1/2

Thus, the six possibilities for the last six electrons are:

  • (3, 1, -1 +1/2)
  • (3, 1, -1, -1/2)
  • (3, 1, 0, +1/2)
  • (3, 1, 0, -1/2)
  • (3, 1, 1, +1/2)
  • (3, 1, 1, -1/2)

Hence, the correct choice is:

  • n = 3
  • l  = 1
  • m_l = 1
  • m_s=+1/2
5 0
3 years ago
Write a program in Java programming language that given two clock times prints out the absolute number of minutes between them
Triss [41]

Answer:

// Java Program to Find the difference

// between Two Time Periods

// Importing the Date Class from the util package

import java.util.*;

// Importing the SimpleDateFormat

// Class from the text package

import java.text.*;

public class GFG {

public static void main(String[] args) throws Exception

{

 // Dates to be parsed

 String time1 = "18:00:00";

 String time2 = "7:30:50";

 // Creating a SimpleDateFormat object

 // to parse time in the format HH:MM:SS

 SimpleDateFormat simpleDateFormat

  = new SimpleDateFormat("HH:mm:ss");

 // Parsing the Time Period

 Date date1 = simpleDateFormat.parse(time1);

 Date date2 = simpleDateFormat.parse(time2);

 // Calculating the difference in milliseconds

 long differenceInMilliSeconds

  = Math.abs(date2.getTime() - date1.getTime());

 // Calculating the difference in Hours

 long differenceInHours

  = (differenceInMilliSeconds / (60 * 60 * 1000))

  % 24;

 // Calculating the difference in Minutes

 long differenceInMinutes

  = (differenceInMilliSeconds / (60 * 1000)) % 60;

 // Calculating the difference in Seconds

 long differenceInSeconds

  = (differenceInMilliSeconds / 1000) % 60;

 // Printing the answer

 System.out.println(

  "Difference is " + differenceInHours + " hours "

  + differenceInMinutes + " minutes "

  + differenceInSeconds + " Seconds. ");

}

}

7 0
2 years ago
A router receives a packet and determines the outbound link for the packet. When the packet arrives, 2/3 of one other packet is
vlada-n [284]

Answer:

Queuing Delay is 0.08 seconds

Explanation:

The answer follows a formula that is relatively easy to use and is detailed below.

Queuing Delay = [(L - x) + (nL)] / R

where,

L is packet length given as 3,000 bytes

x is the currently transmitted packet given as 2/3 * 3,000 = 2,000

n is the number of packets waiting in the Que given as 5

R is the rate of transmission given as 4 Mbps (4 * 10^6 Bps)

We can simply plug in the above information in the equation for computing Queuing Delay.

Lets take the numerator first which would be [(3000 - 2000) + (5 * 3000)]

The numerator would be 16000 bytes. These are being transmitted at 4Mbps. So, 16000*4*5 = 320,000 "bits"

Queuing Delay= 320,000/4000000

Queuing Delay = 0.08 seconds.

As we can see, the formula is quite intuitive to use. You are simply taking the number of packets to be transmitting, incorporating the partially transmitted packet, multiplying by the number of packets and the rate of transmission and then dividing the product by the rate of transmission to compute what the delay in the Que is.

6 0
3 years ago
Other questions:
  • Do we have to use intersection?
    6·1 answer
  • _____ is when network managers deal with network breakdowns and immediate problems instead of performing tasks according to a we
    9·1 answer
  • When numbers are changed in cells that are involved in formula is the formulas are automatically
    14·1 answer
  • In gaming, "rendering" refers to:
    12·2 answers
  • The parameter passing mechanisn used in C is
    5·2 answers
  • How to be fluent in computer
    10·2 answers
  • 3. Radheshree has to complete her assignment and submit it on the next day. While typing
    9·1 answer
  • Name the first mechanical computer​
    11·1 answer
  • How do i stop my computer from automatically connecting to a wireless network
    5·1 answer
  • An agile team has which two characteristics? (choose two. ).
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!