The following code snippet is for C++
int selection_Sort(int A[ ], int n)
{
int I, j, small, temp;
for( i = 0; i < n-1; i++)
{
small = i;
for(j = i + 1; j < n; j++)
{
if ( A[ j ] < A[ small ]
small = j;
}
temp = A [ i ];
A[ i ] = A[small];
A[small] = temp;
}
}
Please explain in rich detail the logic behind every execution and why it does what it does according to the format that the code has! I am really trying to understand how this all works and runs! Thank you in advance!
Please upvote if you like this answer.
CODE:
#include <iostream>
using namespace std;
int selection_Sort(int A[], int n)
{
int i, j, small, temp;
for( i = 0; i < n-1; i++)
{
small = i;
for(j = i+1; j < n; j++)
{
if ( A[j] < A[small])
{
small = j;
}
}
temp = A [i];
A[i] = A[small];
A[small] = temp;
}
}
int main()
{
int arr[] = {5,6,2,3,1};
cout << "given array is : 5,6,2,3,1 \n" ;
int n = sizeof(arr)/sizeof(arr[0]);
int i;
selection_Sort(arr, n);
cout << "Sorted array is: \n";
for (i=0; i < n; i++)
cout << arr[i]
<< " ";
return 0;
}
OUTPUT:

EXPLANATION:




The following code snippet is for C++ int selection_Sort(int A[ ], int n) { int I,...
What's the conversion from C++ to assembly code x86 int findMinIndex (int integer_array[], int i, int j) { // C code to be converted to x86 assembly /* int iMin = i; // test against elements after i and before j to find the smallest for ( i ; i < j; i++) { // if this element is less, then it is the new minimum if (integer_array[i] < integer_array[iMin]) { // found new minimum; remember its index iMin...
1). What is the complexity of the following code snippet? { for (int count2 = 0; count2<n; count2++) { /*some sequence of O(1) step*/ } } select one: a. O(N^2) b. O(Log N) c. O(1) d. O(N!) 2). What is the complexity of the following code snippet? for (int count = 0; count<n; count++) { printsum(count) } select one: a. We need to know the complexity of the printsum() function. b. O(Log N) c. O(1) d. O(N) e. O(N^2) 3)....
QUESTION 9 What will be the output of following code snippet? int a[3] = {1, 2, 3}; int *p = a; int **r = &p; printf("%p %p", *r, a); A. Different memory addresses printed B. 1 2 C. Same memory address printed twice D. 1 1 2 points QUESTION 10 What will be the output of following code snippet? int arr[4] = {1, 2, 3, 4}; int *p; p = arr + 3; *p = 5; printf("%d\n", arr[3]); A....
Consider the following code snippet: int myVariable; int *myPointer; myPointer = &myVariable; Submit the following: Write a C++ statement that would display the value stored in myVariable using myPointer. Write a C++ statement that would display the memory address of myVariable using myPointer. I am in programming II with C++
The following code is a Java code for insertion sort. I would like this code to be modified by not allowing more than 10 numbers of integer elements (if the user enters 11 or a higher number, an error should appear) and also finding the range of the elements after sorting. /* * Java Program to Implement Insertion Sort */ import java.util.Scanner; /* Class InsertionSort */ public class InsertionSortTwo { /* Insertion Sort function */ public static void sort( int...
Consider the following C++ code segment: for (int i = 0; i <n; ++i) { for (int j = 0; j <m; ++j) if (i != j) cout << "0"; else cout << "1"; } } Which of the options below gives the correct output if the value of nis 2and the value of mis 3? 1. 100010 2. 011101 3. 100100 4. 010001
I am trying to write the following code using pointers and traversal by pointers instead of indexing (in C++). The following code is correct: void shift(int arr[], int n) { int temp = arr[n - 1]; int temp1; for (int i = 0; i < n; i++) { temp1 = arr[i]; arr[i] = temp; temp = temp1; } } This is my ATTEMPT at writing it with pointers (and traversal by pointers!) but I know it is wrong. I believe...
Consider the following code C++ like program: int i, j, arr[5]; //arr is an array starting at index 0 void exchange(int x, int y) { int temp:= x; x:= y; y:= temp; } main(){ for (j = 0; j < 5; j++) arr[j]:= j; i:= 1; exchange(i, arr[i+1]); output(i, arr[2]); //print i and arr[2] } What is the output of the code if both parameters in function swapping are passed by: a- value? b- reference? c- value-result?
(a)How many times does the code snippet given below display "Hello"? int x = 1; while (x != 15) { System.out.println ("Hello"); x++; } (b)What is the output of the following code fragment? int i = 1; int sum = 0; while (i <= 5) { sum = sum + i; i++; } System.out.println("The value of sum is " + sum); Quie 2 What is the output of the following snipped code? public class Test {...
c++ help Write a program that obtains the execution times for the following three code segments with the different n. code 1: for(int i = 0; i <= n; i++) { x = i; } code 2: for (int i = 0; i <= n; i++) { for (int j = 0; j <= n; j++) { x = i + j; } } code 3: for (int i = 0; i <= n; i++) { for (int j =...