//C++ Code:-
#include<iostream>
using namespace std;
// Function to sort the array and update the freq
array.
void counting_sort(int a[],int n,int freq[])
{
for(int i=0;i<n;i++)
freq[a[i]]++;
int k=0;
for(int i=0;i<10;i++)
{
if(freq[i])
{
for(int j=0;j<freq[i];j++)
a[k++]=i;
}
}
}
int main()
{
// Define array with some value.
int a[]={2,4,8,4,4,3,2,9,2,5,2,5,2};
// Calculating size of an array.
int n=sizeof(a)/sizeof(a[0]);
// Array for counting Frequency of each
value.
int freq[10]={0};
// Calling function to sort the array.
counting_sort(a,n,freq);
//Print the Sorted array.
cout<<"The sorted array : ";
for(int i=0;i<n;i++)
cout<<a[i]<<" ";
cout<<endl;
// Print Distributed_Value and their corrosponding
Frequency.
cout<<"Distributed_Value Frequency"<<endl;
for(int i=0;i<10;i++)
{
if(freq[i])
cout<<i<<" "<<freq[i]<<endl;
}
return 0;
}

![2 33 34 35 36 37 //Print the Sorted array. cout<<The sorted array : ; for(int i=0;i<n;i++) cout<<a[i]<< ; cout<<endl; 38](http://img.homeworklib.com/questions/3e0976a0-08bf-11eb-afbb-83e4a2340ee6.png?x-oss-process=image/resize,w_560)
2. Consider the following unordered list: 2,4,8, 4, 4, 3, 2, 9, 2, 5, 2, 5,...
1. Consider the following unordered list: 20, 35, 25, 10, 40, 50, 45. Perform heap sort to sort this list in nondecreasing (ascending) order. a. Perform the bottom-up method to arrange these values into a max heap. Show the heapify operations on each relevant subtree. (10 points) b. Show the tree representation and the array representation of these numbers after every dequeue operation. Remember that dequeue does not delete a number. Dequeue will instead remove that number from the heap...
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:...
Given the unordered array: [0] [1] [2] [3] [4] [5] M K E A P C If the array were being sorted using the insertion sort, list the letters in the resulting array, in order, after the second pass. For example, the original array would be listed as: MKEAPC
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...
Question 3 Given the input list [72, 29, 18, 4, 5, 64, 37, 2, 13, 10, 23, 51, 95] Show every step of how the Selection Sort algorithm would proceed to sort this list in ascending order. Your solution goes here • You may wish to change the format of this Markdown cells into a Raw cell instead Question 4 Given the input list [72, 29, 18, 4, 5, 64, 37, 2, 13, 10, 23, 51, 95] • Show every...
Consider the following python code that will sort the list of numbers using the Bubble Sort algorithm def bubbleSort(alist): print(alist) for j in range (len(alist) - 1, 8, -1): for i in range(): if alist[i] > alist[i + 1]: temp = alist[i] alist[i] = alist[i+1] alist[i+1] = temp print(alist) alist = [52, 25, 94, 17, 25, 52] bubbleSort (alist) print(alist) Sort the following series of values into ascending order using the Bubble Sort algorithm. Write out the complete row of...
Discrete Mathematics
Unsorted and Sorted Lists For linear search there was no requirement for the list to be organized in any manner. The linear search works for lists that are "unsorted." But what if the values in the list are given in ascending order? This would be a sorted list. With a sorted list, is there a more efficient way to find the target? Unsorted Lists (4 pts) Assume there is a sorting algorithm with order of growth O(n), where...
C++ Sorting and Searching 1. Mark the following statements as true or false. a. A sequential search of a list assumes that the list elements are sorted in ascending order. b. A binary search of a list assumes that the list is sorted. 2. Consider the following list: 63 45 32 98 46 57 28 100 Using a sequential search, how many comparisons are required to determine whether the following items are in the list or not? (Recall that comparisons...
2. Consider your ID as an array of 9 elements, apply an insertion sort algorithm to sort the numbers in descending order. Show your steps. Example ID: 201710340 Array: 2 0 7 0 1 1 0 3 4
Sort the same array [3, 5, 1, 4, 8, 7,9, 2] in the ascending order by applying the Merge sort algorithm. Write down the intermediate results step by step in a tree structure. (20 points)