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
If an object moves without rotation or angular displacement, it is called translation.
NikAS [45]

Hi!


The answer is True.


Angular displacement is defined as the angle an object travels through, in a circular path, or in other terms -rotation.

Translation is a type of geometric transformation which results in the motion of each point on an object in a particular direction by the same distance. An object moving without rotation is said to have a movement known as translation.


Hope this helps!

7 0
3 years ago
Programming challenge description: Given a string comprising just of the characters (,),{,},[,] determine if it is well-formed o
nadezda [96]

Answer:

Employing Java language,

Explanation:

//for using stack data structure

import java.util.Stack;

//class definition

public class BracketMatch {

   //function to find the string is well formed or not

   public static boolean isWellFormed(String str) {

       //variable to store the character value

       char ch;

       //check if the first character itself is the end of the brackets

       if (str.charAt(0) == ')'||str.charAt(0) =='}'||str.charAt(0) ==']')

           return false;

       //creating a stack of character type

       Stack<Character> stack = new Stack<Character>();

       //iterating through the characters in string

       for(int i=0; i < str.length(); i++) {

           //storing the current character from the string in the variable

           ch = str.charAt(i);

           if(ch == '('||ch=='{'||ch=='[')

               //if the character is starting of the brackets push it into stack

               stack.push(ch);

           else if(ch == ')')

               //if it is closing bracket and the stack is empty then the string is not well formatted

               if(stack.empty())

                   return false;

               else if(stack.peek() == '(')

                   stack.pop();

               else

                   return false;

           else if(ch == '}')

               if(stack.empty())

                   return false;

               else if(stack.peek() == '{')

                   stack.pop();

               else

                   return false;

       }

       //returning the stack content, if the string will be well formed the stack would be empty

       //after all the operations

       return stack.empty();

   }

   //main method

   public static void main(String[] args) {

       //calling function to find if the string is welll formatted or not

       System.out.println(isWellFormed("{}"));

       //calling function to find if the string is welll formatted or not

       System.out.println(isWellFormed("([)]"));

   }

}

5 0
3 years ago
Write a recursive function that takes a non-negative integer as an argument and displays the same number in reverse order (i.e.
avanturin [10]

Answer:

Following are the program in C++ language

#include<iostream> // header file

using namespace std; // namespace std

int reverse(int n1); // function prototype

int main()  // main function()

{

   int num; // Variable declaration

   cout << "Enter the number" << endl;

   cin >> num; // Read the number bu the user

  cout<<"After Reverse the digit:\n";

   int res= reverse(num); // calling function reverse

   

   cout<<res; // display  

}

int reverse(int n1) // function definition of reverse

{

   if (n1<10)  // checking the base condition

       {

           return n1;

       }

   else

       {

           cout << n1 % 10; // Printed the last digit

          return reverse(n1/10); // calling itsself

}

}

Output:

Enter the number:

76538

After Reverse the digit:

83567

Explanation:

Following are the description of the program

  • In the main function read the number by user in the "num" variable of int type.
  • Calling the reverse and pass that "num" variable into it.
  • After calling the control moves to the body of the reverse function.In this function we check the two condition

        1  base condition

   if (n1<10)  // checking the base condition

       {

           return n1;

     }

      2  General condition

  else

       {

           cout << n1 % 10; // Printed the last digit

          return reverse(n1/10); // calling itsself

       }

  • Finally return the reverse number and display them into the main function.
5 0
3 years ago
What types of roles are there as a webmaster?
Nuetrik [128]
<span> PHP, ASP, and Javascript. They handle the technical aspects </span>
6 0
3 years ago
Read 2 more answers
Into which of these files would you paste copied information to create an integrated document? A. Mailing list B. Source C. Data
viva [34]

it would be b.mailing list


5 0
3 years ago
Read 2 more answers
Other questions:
  • What is software that helps a computer operate efficiently and keeps track of data on a computer?
    14·1 answer
  • What command limits structural changes, such as adding, deleting, or moving sheets, that can be made in a workbook?
    13·1 answer
  • What are some objects in your home that demonstrate electrical energy to radiant energy to thermal energy
    10·2 answers
  • A lamp outside a front door comes on automatically when it is dark, and when someone stands on the doormat outside the front doo
    7·1 answer
  • What is technology? *
    10·1 answer
  • Cómo se llaman los robots que se utilizan para la exploración espacial, en medicina, en la industria, en la agricultura, los que
    13·1 answer
  • True or False: The major advantage of Arrays over ArrayLists in Java is the fact that while ArrayLists are fixed in size, an Arr
    15·1 answer
  • An MP3 player is an example of which of the following types of computer
    5·1 answer
  • Meta is a penetration testing engineer assigned to pen test the security firm's network. So far, she cannot tunnel through the n
    12·1 answer
  • Write l for law of enrtia,ll for law of Acceleration and lll for law of enteraction.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!