Implement in C SharpCreate a new algorithm based on the algorithm, selection sort. The new algorithm should be able to sort an array like this: Input: an array that has n elements, and the values of its elements are assigned randomly, for example: Index 0 1 2 3 4 5 value 7 3 6 2 1 5 Output: an array - its first n/2 elements are sorted in ascending order and its second n/2 elements sorted in descending order. That is, after sorting, the array above will become: Index 0 1 2 3 4 5 value 5 6 7 3 2 1 As the solution of this problem, you need to submit the following answer(s): (1). Your algorithm written in pseudo code . (2). The implementation of your algorithm in C# .
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace wk5collabproject
{
class Program
{
static void Main(string[] args)
{
//int [] myArray = new int[] { 5,2,4, 7, 9, 3, 1, 6, 8 };
int [] myArray = new int[] { 5,2,3,4,5,6,7,8 };
int middle, temp , curr;
if(myArray.Length%2==0)
middle = myArray.Length/2;
else
middle = (myArray.Length+1)/2;
for(int i=0; i<myArray.Length; ++i){
if(i<middle){
curr = i;
for(int j=i+1; j<middle;++j){
if(myArray[curr] > myArray[j]){
temp = myArray[curr];
myArray[curr]=myArray[j];
myArray[j] = temp;
}
}
}
else {
curr = i;
for(int k=i+1; k<myArray.Length; ++k){
if(myArray[curr]<myArray[k]){
curr = k;
}
temp = myArray[i];
myArray[i]=myArray[curr];
myArray[curr]= temp;
}
}
}
for(int i=0;i<myArray.Length;++i){
Console.WriteLine(myArray[i] + " ");
}
}
}
}
================================================================
See Ouput
![class Program 2 3 static void Main(string[] args) Ant myArray - new int 5,2,4, 7, 9, 3, 1, 6, 8; 5,2,3,4,5,6,7,8 ; 6 int myAr](http://img.homeworklib.com/questions/522500e0-d5c5-11ea-9b42-f1495f3605d7.png?x-oss-process=image/resize,w_560)
Thanks
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Selection_Sort
{
class Program
{
static void Main(string[] args)
{
Selection_Sort selection = new Selection_Sort(10);
selection.Sort();
}
}
class Selection_Sort
{
private int[] data;
private static Random generator = new Random();
//Create an array of 10 random numbers
public Selection_Sort(int size)
{
data = new int[size];
for (int i = 0; i < size; i++)
{
data[i] = generator.Next(20, 90);
}
}
public void Sort()
{
Console.Write("\nSorted Array Elements :(Step by Step)\n\n");
display_array_elements();
int smallest;
for (int i = 0; i < data.Length - 1; i++)
{
smallest = i;
for (int index = i + 1; index < data.Length; index++)
{
if (data[index] < data[smallest])
{
smallest = index;
}
}
Swap(i, smallest);
display_array_elements();
}
}
public void Swap(int first, int second)
{
int temporary = data[first];
data[first] = data[second];
data[second] = temporary;
}
public void display_array_elements()
{
foreach (var element in data)
{
Console.Write(element + " ");
}
Console.Write("\n\n");
}
}
}
Implement in C SharpCreate a new algorithm based on the algorithm, selection sort. The new algorithm...
Question 5 (10 Points) Write a well-documented, Python program, hmwk305.py that implements the Selection-Sort algorithm. Selection-Sort segments the list into sorted and unsorted elements. The algorithm continues to remove the smallest element of the unsorted list and adds it to the sorted segment. Implement the algorithm that accepts an unsorted list and returns a sorted one - in ascending order. 5 3 8 Initial List 4 6 18 4 6 Minimum Swaps Position: Sorted List Length 1 Minimum Swaps Position:...
please help with python
Write a well-documented, Python program, hmwk305.py that implements the Selection-Sort algorithm. Selection Sort segments the list into sorted and unsorted elements. The algorithm continues to remove the smallest element of the unsorted list and adds it to the sorted segment. Implement the algorithm that accepts an unsorted list and returns a sorted one - in ascending order. 5 3 8 4 6 Initial List Minimum Swaps Position: Sorted List Length 1 Minimum Swaps Position: Sorted List...
Selection Sort is a common algorithm to sort the elements of an array. First, it scans the elements of the array to find the smallest value and places it at index 0, thus creating a sorted “subarray” of size 1 that contains the smallest value. Then it scans the remaining unsorted values for the new smallest value and places it at index 1, creating a sorted subarray of size 2 that contains the 2 smallest values. It continues in this...
Sorting Sort the following array using the quick sort algorithm: (4 Marks) a. 12 26 8 9 7 0 4 Pivot selection is defined to be the first element of each sub-list. Show the array before and after each quicksort round (when the array is partitioned after placing the pivot at its correct position). Also, clearly highlight the pivot in each partition b. Consider an unsorted array of integers of size n. Write a Java program to arrange the array...
TO DO: IMPLEMENT SELECTION SORT, BUBBLE SORT, MERGE SORT INSTRUCTIONS: GENERATE AN ARRAY arr AND FILL IT WITH 100 RANDOM INTEGERS, HAVING VALUES 0-99. PRINT THE UNSORTED ARRAY IMPLEMENT EACH SORTING ALGORITHM (DO NOT USE THE BUILT-IN LIBRARIES) FOR EACH ALGORITHM, INCLUDE PSEUDOCODE WITH NUMBERED STEPS. IN YOUR CODE, CLEARLY COMMENT WHICH STEP IS BEING PERFORMED BY THE LINE OR BLOCK OF CODE. USE A TIMER TO CHECK HOW LONG EACH ALGORITHM TAKES TO SORT THE ARRAY. THIS SHOULD BE...
Modify the sorts (selection sort, insertion sort, bubble sort, quick sort, and merge sort) by adding code to each to tally the total number of comparisons and total execution time of each algorithm. Execute the sort algorithms against the same list, recording information for the total number of comparisons and total execution time for each algorithm. Try several different lists, including at least one that is already in sorted order. ---------------------------------------------------------------------------------------------------------------- /** * Sorting demonstrates sorting and searching on an...
2. Suggest a structured plan (algorithm) for the bubble sort and selection sort, and perform running time analysis for both best and worst case. 3. Consider the age data of 12 children who are supposed to undergo for vaccination in ascending order of their age. Suggest and apply a sorting technique which can efficiently handle this data. Show all the intermediate steps clearly. Child ID 01 02 03 04 05 06 07 08 09 10 11 12 2. Age 1...
Exercise #2: Design and implement a program (name it SimpleSort) to implement and test the three sort algorithms (Bubble, Insertion, Selection) discussed in the lecture slides. Define method BubbleSort() to implement Bubble sort of an array of integers. Modify the algorithm implementation to count number of swaps it takes to sort the array. Define method InsertionSort() to implement insertion sort of an array of integers. Modify the algorithm implementation to count number of swaps it takes to sort the array. Define...
3. Modify the insertion sort algorithm discussed in class so
that it can sort strings. That is, its input will be an array, the
type of which is string. The insertion sort algorithm will sort the
elements in this array. Finally, its output will be a sorted
array.
As the solution of this problem, you need to submit the
following answer(s): (1). The implementation of your algorithm in
C# (20points).
Algorithm: At each array-position, it checks the value there against...
1. What is the minimum number of locations a binary search algorithm will have to examine when looking for a particular value in a sorted array of 200 elements? (2 points) 1 6 7 8 200 2. In general, which of the following sorting algorithms is the MOST efficient? (2 points) Bubble sort Insertion sort Heap sort Merge sort Selection sort 3. Which of the following are quadratic-sorting algorithms? (2 points) I. insertion sort II. selection sort III. merge sort...