c++ program: I need to sort arrays using an insertion sort and a merge sort (I already have). I
need to use these sorting methods to sort input arrays in the form of randomly generated numbers
in the size of 20, 100 and 200. So I need 3 randomily generated arrays and sorted and outputed
by both sorting method. I currently have it as given arrays and need help changing them to
randomily generated arrays
Here is my code so far:
#include
using namespace std;
void InsertionSort(int arr[],int size){
int temp,j;
for(int i=0; i=0){
arr[j+1] = arr[j];
j--;
}
arr[j+1] = temp;
}
}
//Merges two sub-arrays. First sub-array is arr[l..m],second is arr[m+1..r]
void merge(int arr[], int l, int m, int r){
int i, j, k;
int n1 = m - l + 1;
int n2 = r - m;
//Create temp arrays
int L[n1], R[n2];
//Copy data to temp arrays L[] and R[]
for (i = 0; i < n1; i++)
L[i] = arr[l + i];
for (j = 0; j < n2; j++)
R[j] = arr[m + 1+ j];
/* Merge arrays back into arr[l..r]*/
i = 0;
j = 0;
k = l;
while (i < n1 && j < n2){
if (L[i] <= R[j]){
arr[k] = L[i];
i++;
}
else{
arr[k] = R[j];
j++;
}
k++;
}
//Copy the remaining elements of L[], if there are any
while (i < n1){
arr[k] = L[i];
i++;
k++;
}
//Copy the remaining elements of R[], if there are any
while (j < n2){
arr[k] = R[j];
j++;
k++;
}
}
//l is left index and r is right index of the sub-array of array to be sorted
void MergeSort(int arr[], int l, int r){
if (l < r){
// Same as (l+r)/2, but avoids overflow for large l and h
int m = l+(r-l)/2;
// Sort first and second halves
MergeSort(arr, l, m);
MergeSort(arr, m+1, r);
merge(arr, l, m, r);
}
}
void printArray(int arr[], int size){//Function to print array
int i;
for (i=0; i < size; i++)
cout << arr[i] <<\" \";
cout << endl;
}
int main(){
int size = 20;
int array1[] = {17,33,88,54,96,82,12,36,69,74,79,66,32,11,1,98,76,55,3,4};
int array2[] = {20,1,19,2,18,3,17,4,16,5,15,6,14,7,13,8,12,9,11,10};
int array3[] = {220,209,198,187,176,165,154,143,132,121,110,99,88,77,66,55,44,33,22,11};
int array4[] = {15,35,85,100,40,90,70,65,25,5,10,30,55,75,80,95,20,45,50,60};
int array5[] = {100,99,98,97,96,95,94,93,92,91,90,89,88,87,86,85,84,83,82,81};
//Output for array1
cout << \"Original array 1: \ \";
printArray(array1, size);
InsertionSort(array1, size);
cout << \"Array 1 sorted by INSERTION SORT: \ \";
printArray(array1, size);
cout << \"\ \";
//Output for array2
cout << \"Original array 2: \ \";
printArray(array2, size);
MergeSort(array2,0,size);
cout << \"Array 2 sorted by MERGE SORT: \ \";
printArray(array2, size);
cout << \"\ \";
//Output for array3
cout << \"Original array 3: \ \";
printArray(array3, size);
InsertionSort(array3, size);
cout << \"Array 3 sorted by INSERTION SORT: \ \";
printArray(array3, size);
cout << \"\ \";
//Output for array4
cout << \"Original array 4: \ \";
printArray(array4, size);
MergeSort(array4,0,size);
cout << \"Array 4 sorted by MERGE SORT: \ \";
printArray(array4, size);
cout << \"\ \";
//Output for array5
cout << \"Original array 5: \ \";
printArray(arr.
#include iostream using namespace std; void InsertionSort(int .pdfbrijmote
#include
using namespace std;
void InsertionSort(int arr[],int size){
int temp,j;
for(int i=0; i=0){
arr[j+1] = arr[j];
j--;
}
arr[j+1] = temp;
}
}
// Merges two subarrays of arr[].
// First subarray is arr[l..m]
// Second subarray is arr[m+1..r]
void merge(int arr[], int l, int m, int r)
{
int i, j, k;
int n1 = m - l + 1;
int n2 = r - m;
/* create temp arrays */
int L[n1], R[n2];
/* Copy data to temp arrays L[] and R[] */
for (i = 0; i < n1; i++)
L[i] = arr[l + i];
for (j = 0; j < n2; j++)
R[j] = arr[m + 1+ j];
/* Merge arrays back into arr[l..r]*/
i = 0; // first subarray index
j = 0; // second subarray index
k = l; // merged subarray index
while (i < n1 && j < n2)
{
if (L[i] <= R[j])
{
arr[k] = L[i];
i++;
}
else
{
arr[k] = R[j];
j++;
}
k++;
}
/* Copy the remaining elements of L[], if there
are any */
while (i < n1)
{
arr[k] = L[i];
i++;
k++;
}
/* Copy the remaining elements of R[], if there
are any */
while (j < n2)
{
arr[k] = R[j];
j++;
k++;
}
}
/* l is for left index and r is right index of the
sub-array of arr to be sorted */
void mergeSort(int arr[], int l, int r)
{
if (l < r)
{
// Same as (l+r)/2, but avoids overflow for
// large l and h
int m = l+(r-l)/2;
// Sort first and second halves
mergeSort(arr, l, m);
mergeSort(arr, m+1, r);
merge(arr, l, m, r);
}
}
void printArray(int arr[], int size){//Function to print array
int i;
for (i=0; i < size; i++)
cout << arr[i] <<\" \";
cout << endl;
}
int main(){
int size = 20;
int array1[] = {17,33,88,54,96,82,12,36,69,74,79,66,32,11,1,98,76,55,3,4};
int array2[] = {20,1,19,2,18,3,17,4,16,5,15,6,14,7,13,8,12,9,11,10};
int array3[] = {220,209,198,187,176,165,154,143,132,121,110,99,88,77,66,55,44,33,22,11};
int array4[] = {25,27,23,2,7,99,96,1996,85,3,24,11,17,4,1,0,8,9,98,45};
int array5[] = {15,35,85,100,40,90,70,65,25,5,10,30,55,75,80,95,20,45,50,60};
//Output for array1
cout << \"Original array 1: \ \";
printArray(array1, size);
InsertionSort(array1, size);
cout << \"Array 1 sorted by insertion sort: \ \";
printArray(array1, size);
//CALL THE MERGE SORT HERE
//PRINT THE MERGE SORT HERE
cout << \"\ \";
//Output for array2
cout << \"Original array 2: \ \";
printArray(array2, size);
mergeSort(array2,0,size);
cout << \"Array 2 sorted by Merge sort: \ \";
printArray(array2, size);
cout << \"\ \";
//Output for array3
cout << \"Original array 3: \ \";
printArray(array3, size);
InsertionSort(array3, size);
cout << \"Array 3 sorted by insertion sort: \ \";
printArray(array3, size);
cout << \"\ \";
//Output for array4
cout << \"Original array 4: \ \";
printArray(array4, size);
mergeSort(array4,0,size);
cout << \"Array 4 sorted by Merge sort: \ \";
printArray(array4, size);
cout << \"\ \";
//Output for array5
cout << \"Original array 5: \ \";
printArray(array5, size);
InsertionSort(array5, size);
cout << \"Array 5 sorted by insertion sort: \ \";
printArray(array5, size);
cout << \"\ \";
return 0;
}
/* sample output
Note: As sorting an already sorted array does not result good. I have changed the array2,a.
Please I want a detailed complete answers for each part.Then make.pdfsiennatimbok52331
Please I want a detailed complete answers for each part.Then make sure you provide clear
picture(s) of soultions that I can read. Try making all numbers and letters clrearly readable easy
to recognize. You also can type it which I prefer so I can copy all later, paste them in Microsoft
Word to enlarge & edit if needed. Thanks for all :) 1. Sort the record 9, 34,17,6, 15, 3:8 by using
the following sorting techniques, respectively, 1) QuickSort with a good call for the first pivot
value 2) MergeSort 3) HeapSort (including the details for building 1st Heap, and all 6 heaps) 4)
Binsort (Choose Bins as: 0-9; 10-19, 20-29, 30-39) 5) Radix sort The details of each sorting step
should be ncluded The details of each sorting step should be included
Solution
QuickSort:
QuickSort is a Divide and Conquer algorithm. It picks an element as pivot and partitions the
given array around the picked pivot. There are many different versions of quickSort that pick
pivot in different ways.
The key process in quickSort is partition(). Target of partitions is, given an array and an element
x of array as pivot, put x at its correct position in sorted array and put all smaller elements
(smaller than x) before x, and put all greater elements (greater than x) after x. All this should be
done in linear time
elements:
9 34 17 6 15 38
9 34 17 6 15 38
9 34 17 6 15 38
9 34 17 6 15 38
9 34 17 6 15 38
9 34 17 6 15 38
9 6 17 34 15 38
swapping 15 and 34
15 is choosing pivot
compare with i-1 value
Program
def quickSort(alist):
quickSortHelper(alist,0,len(alist)-1)
def quickSortHelper(alist,first,last):
if first= pivotvalue and rightmark >= leftmark:
rightmark = rightmark -1
if rightmark < leftmark:
done = True
else:
temp = alist[leftmark]
alist[leftmark] = alist[rightmark]
alist[rightmark] = temp
temp = alist[first]
alist[first] = alist[rightmark]
alist[rightmark] = temp
return rightmark
alist = [9,34,17,6,15,8]
quickSort(alist)
print(alist)
Mergesort:
MergeSort is a Divide and Conquer algorithm. It divides input array in two halves, calls itself for
the two halves and then merges the two sorted halves. The merge() function is used for merging
two halves. The merge(arr, l, m, r) is key process that assumes that arr[l..m] and arr[m+1..r] are
sorted and merges the two sorted sub-arrays into one. See following C implementation for
details.
9 34 17 6 15 38
divide two parts
9 34 17 6 15 38
divide separate parts
9 34 17 6 15 38
compare two elements in each section
9 34 17 6 15 38
compare section to section
9 17 34 6 15 38
compare two section
6 9 15 17 34 38
Merges two subarrays of arr[].
# First subarray is arr[l..m]
# Second subarray is arr[m+1..r]
def merge(arr, l, m, r):
n1 = m - l + 1
n2 = r- m
# create temp arrays
L = [0] * (n1)
R = [0] * (n2)
# Copy data to temp arrays L[] and R[]
for i in range(0 , n1):
L[i] = arr[l + i]
for j in range(0 , n2):
R[j] = arr[m + 1 + j]
# Merge the temp arrays back into arr[l..r]
i = 0 # Initial index of first subarray
j = 0 # Initial index of second.
#include iostream using namespace std; void InsertionSort(int .pdfbrijmote
#include
using namespace std;
void InsertionSort(int arr[],int size){
int temp,j;
for(int i=0; i=0){
arr[j+1] = arr[j];
j--;
}
arr[j+1] = temp;
}
}
// Merges two subarrays of arr[].
// First subarray is arr[l..m]
// Second subarray is arr[m+1..r]
void merge(int arr[], int l, int m, int r)
{
int i, j, k;
int n1 = m - l + 1;
int n2 = r - m;
/* create temp arrays */
int L[n1], R[n2];
/* Copy data to temp arrays L[] and R[] */
for (i = 0; i < n1; i++)
L[i] = arr[l + i];
for (j = 0; j < n2; j++)
R[j] = arr[m + 1+ j];
/* Merge arrays back into arr[l..r]*/
i = 0; // first subarray index
j = 0; // second subarray index
k = l; // merged subarray index
while (i < n1 && j < n2)
{
if (L[i] <= R[j])
{
arr[k] = L[i];
i++;
}
else
{
arr[k] = R[j];
j++;
}
k++;
}
/* Copy the remaining elements of L[], if there
are any */
while (i < n1)
{
arr[k] = L[i];
i++;
k++;
}
/* Copy the remaining elements of R[], if there
are any */
while (j < n2)
{
arr[k] = R[j];
j++;
k++;
}
}
/* l is for left index and r is right index of the
sub-array of arr to be sorted */
void mergeSort(int arr[], int l, int r)
{
if (l < r)
{
// Same as (l+r)/2, but avoids overflow for
// large l and h
int m = l+(r-l)/2;
// Sort first and second halves
mergeSort(arr, l, m);
mergeSort(arr, m+1, r);
merge(arr, l, m, r);
}
}
void printArray(int arr[], int size){//Function to print array
int i;
for (i=0; i < size; i++)
cout << arr[i] <<\" \";
cout << endl;
}
int main(){
int size = 20;
int array1[] = {17,33,88,54,96,82,12,36,69,74,79,66,32,11,1,98,76,55,3,4};
int array2[] = {20,1,19,2,18,3,17,4,16,5,15,6,14,7,13,8,12,9,11,10};
int array3[] = {220,209,198,187,176,165,154,143,132,121,110,99,88,77,66,55,44,33,22,11};
int array4[] = {25,27,23,2,7,99,96,1996,85,3,24,11,17,4,1,0,8,9,98,45};
int array5[] = {15,35,85,100,40,90,70,65,25,5,10,30,55,75,80,95,20,45,50,60};
//Output for array1
cout << \"Original array 1: \ \";
printArray(array1, size);
InsertionSort(array1, size);
cout << \"Array 1 sorted by insertion sort: \ \";
printArray(array1, size);
//CALL THE MERGE SORT HERE
//PRINT THE MERGE SORT HERE
cout << \"\ \";
//Output for array2
cout << \"Original array 2: \ \";
printArray(array2, size);
mergeSort(array2,0,size);
cout << \"Array 2 sorted by Merge sort: \ \";
printArray(array2, size);
cout << \"\ \";
//Output for array3
cout << \"Original array 3: \ \";
printArray(array3, size);
InsertionSort(array3, size);
cout << \"Array 3 sorted by insertion sort: \ \";
printArray(array3, size);
cout << \"\ \";
//Output for array4
cout << \"Original array 4: \ \";
printArray(array4, size);
mergeSort(array4,0,size);
cout << \"Array 4 sorted by Merge sort: \ \";
printArray(array4, size);
cout << \"\ \";
//Output for array5
cout << \"Original array 5: \ \";
printArray(array5, size);
InsertionSort(array5, size);
cout << \"Array 5 sorted by insertion sort: \ \";
printArray(array5, size);
cout << \"\ \";
return 0;
}
/* sample output
Note: As sorting an already sorted array does not result good. I have changed the array2,a.
Please I want a detailed complete answers for each part.Then make.pdfsiennatimbok52331
Please I want a detailed complete answers for each part.Then make sure you provide clear
picture(s) of soultions that I can read. Try making all numbers and letters clrearly readable easy
to recognize. You also can type it which I prefer so I can copy all later, paste them in Microsoft
Word to enlarge & edit if needed. Thanks for all :) 1. Sort the record 9, 34,17,6, 15, 3:8 by using
the following sorting techniques, respectively, 1) QuickSort with a good call for the first pivot
value 2) MergeSort 3) HeapSort (including the details for building 1st Heap, and all 6 heaps) 4)
Binsort (Choose Bins as: 0-9; 10-19, 20-29, 30-39) 5) Radix sort The details of each sorting step
should be ncluded The details of each sorting step should be included
Solution
QuickSort:
QuickSort is a Divide and Conquer algorithm. It picks an element as pivot and partitions the
given array around the picked pivot. There are many different versions of quickSort that pick
pivot in different ways.
The key process in quickSort is partition(). Target of partitions is, given an array and an element
x of array as pivot, put x at its correct position in sorted array and put all smaller elements
(smaller than x) before x, and put all greater elements (greater than x) after x. All this should be
done in linear time
elements:
9 34 17 6 15 38
9 34 17 6 15 38
9 34 17 6 15 38
9 34 17 6 15 38
9 34 17 6 15 38
9 34 17 6 15 38
9 6 17 34 15 38
swapping 15 and 34
15 is choosing pivot
compare with i-1 value
Program
def quickSort(alist):
quickSortHelper(alist,0,len(alist)-1)
def quickSortHelper(alist,first,last):
if first= pivotvalue and rightmark >= leftmark:
rightmark = rightmark -1
if rightmark < leftmark:
done = True
else:
temp = alist[leftmark]
alist[leftmark] = alist[rightmark]
alist[rightmark] = temp
temp = alist[first]
alist[first] = alist[rightmark]
alist[rightmark] = temp
return rightmark
alist = [9,34,17,6,15,8]
quickSort(alist)
print(alist)
Mergesort:
MergeSort is a Divide and Conquer algorithm. It divides input array in two halves, calls itself for
the two halves and then merges the two sorted halves. The merge() function is used for merging
two halves. The merge(arr, l, m, r) is key process that assumes that arr[l..m] and arr[m+1..r] are
sorted and merges the two sorted sub-arrays into one. See following C implementation for
details.
9 34 17 6 15 38
divide two parts
9 34 17 6 15 38
divide separate parts
9 34 17 6 15 38
compare two elements in each section
9 34 17 6 15 38
compare section to section
9 17 34 6 15 38
compare two section
6 9 15 17 34 38
Merges two subarrays of arr[].
# First subarray is arr[l..m]
# Second subarray is arr[m+1..r]
def merge(arr, l, m, r):
n1 = m - l + 1
n2 = r- m
# create temp arrays
L = [0] * (n1)
R = [0] * (n2)
# Copy data to temp arrays L[] and R[]
for i in range(0 , n1):
L[i] = arr[l + i]
for j in range(0 , n2):
R[j] = arr[m + 1 + j]
# Merge the temp arrays back into arr[l..r]
i = 0 # Initial index of first subarray
j = 0 # Initial index of second.
computer dataA computer is a machine that can be programmed to carry out sequences of arithmetic or logical operations (computation) automatically. Modern digital electronic computers can perform generic sets of operations known as programs. These programs enable computers to perform a wide range of tasks. A computer system is a nominally complete computer that includes the hardware, operating system (main software), and peripheral equipment needed and used for full operation. This term may also refer to a group of computers that are linked and function together, such as a computer network or computer cluster.
A broad range of industrial and consumer products use computers as control systems. Simple special-purpose devices like microwave ovens and remote controls are included, as are factory devices like industrial robots and computer-aided design, as well as general-purpose devices like personal computers and mobile devices like smartphones. Computers power the Internet, which links billions of other computers and users.
Early computers were meant to be used only for calculations. Simple manual instruments like the abacus have aided people in doing calculations since ancient times. Early in the Industrial Revolution, some mechanical devices were built to automate long, tedious tasks, such as guiding patterns for looms. More sophisticated electrical machines did specialized analog calculations in the early 20th century. The first digital electronic calculating machines were developed during World War II. The first semiconductor transistors in the late 1940s were followed by the silicon-based MOSFET (MOS transistor) and monolithic integrated circuit chip technologies in the late 1950s, leading to the microprocessor and the microcomputer revolution in the 1970s. The speed, power and versatility of computers have been increasing dramatically ever since then, with transistor counts increasing at a rapid pace (as predicted by Moore's law), leading to the Digital Revolution during the late 20th to early 21st centuries.
Write a program that obtains the execution time of selection sort, bu.pdfarri2009av
Write a java program called Question39 that does the following: Gets input for temperature
Utilizing a branching statement: If temperature is 76-100, call method outputHot passing the
temperature input as an argument. If temperature is 0-39, call method outputCold passing the
temperature input as an argument. If temperature is 40 to 75, call method outputJustRight
passing the temperature input as an argument. If temperature is outside these ranges, output
“Temperature outside range” to the screen. Be precise, import modules, include comments,
prologue, etc. as needed.
Solution
Question39.java
import java.util.Scanner;
public class Question39 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println(\"Enter temperature: \");
int temp = scan.nextInt();
if(temp >=76 && temp <=100){
outputHot(temp);
}
else if(temp >=0 && temp <=39){
outputCold(temp);
}
else if(temp >=40 && temp <=75){
outputJustRight(temp);
}
else{
System.out.println(\"Temperature outside range\");
}
}
public static void outputHot(int temp){
System.out.println(\"Temperature \"+temp+\" Hot \");
}
public static void outputCold(int temp){
System.out.println(\"Temperature \"+temp+\" Cold \");
}
public static void outputJustRight(int temp){
System.out.println(\"Temperature \"+temp+\" Just Right \");
}
}
Output:
Enter temperature:
45
Temperature 45 Just Right.
Merge Sort implementation in C++ The implementation for Mergesort gi.pdfmdameer02
Merge Sort implementation in C++ The implementation for Mergesort given in Section 7.4 takes
an array as input and soils that array. At the beginning of Section 7.4 there is a simple
pseudocode implementation for sorting a linked list using Mergesort. Implement both a linked
list-based version of Mergesort and the array-based version of Mergesort. and compare and
analyze their running times.
Solution
/* Merger sort array-based version */
/* C program for Merge Sort */
#include
#include
// Merges two subarrays of arr[].
// First subarray is arr[l..m]
// Second subarray is arr[m+1..r]
void merge(int arr[], int l, int m, int r)
{
int i, j, k;
int n1 = m - l + 1;
int n2 = r - m;
/* create temp arrays */
int L[n1], R[n2];
/* Copy data to temp arrays L[] and R[] */
for (i = 0; i < n1; i++)
L[i] = arr[l + i];
for (j = 0; j < n2; j++)
R[j] = arr[m + 1+ j];
/* Merge the temp arrays back into arr[l..r]*/
i = 0; // Initial index of first subarray
j = 0; // Initial index of second subarray
k = l; // Initial index of merged subarray
while (i < n1 && j < n2)
{
if (L[i] <= R[j])
{
arr[k] = L[i];
i++;
}
else
{
arr[k] = R[j];
j++;
}
k++;
}
/* Copy the remaining elements of L[], if there
are any */
while (i < n1)
{
arr[k] = L[i];
i++;
k++;
}
/* Copy the remaining elements of R[], if there
are any */
while (j < n2)
{
arr[k] = R[j];
j++;
k++;
}
}
/* l is for left index and r is right index of the
sub-array of arr to be sorted */
void mergeSort(int arr[], int l, int r)
{
if (l < r)
{
// Same as (l+r)/2, but avoids overflow for
// large l and h
int m = l+(r-l)/2;
// Sort first and second halves
mergeSort(arr, l, m);
mergeSort(arr, m+1, r);
merge(arr, l, m, r);
}
}
/* UTILITY FUNCTIONS */
/* Function to print an array */
void printArray(int A[], int size)
{
int i;
for (i=0; i < size; i++)
printf(\"%d \", A[i]);
printf(\"\ \");
}
/* Driver program to test above functions */
int main()
{
int arr[] = {12, 11, 13, 5, 6, 7};
int arr_size = sizeof(arr)/sizeof(arr[0]);
printf(\"Given array is \ \");
printArray(arr, arr_size);
mergeSort(arr, 0, arr_size - 1);
printf(\"\ Sorted array is \ \");
printArray(arr, arr_size);
return 0;
}
--------------------------------------------------------------------------------------------------------------------
/* merge sort link-list version
#include
#include
/* Link list node */
struct node
{
int data;
struct node* next;
};
/* function prototypes */
struct node* SortedMerge(struct node* a, struct node* b);
void FrontBackSplit(struct node* source,
struct node** frontRef, struct node** backRef);
/* sorts the linked list by changing next pointers (not data) */
void MergeSort(struct node** headRef)
{
struct node* head = *headRef;
struct node* a;
struct node* b;
/* Base case -- length 0 or 1 */
if ((head == NULL) || (head->next == NULL))
{
return;
}
/* Split head into \'a\' and \'b\' sublists */
FrontBackSplit(head, &a, &b);
/* Recursively sort the sublists */
MergeSort(&a);
MergeSort(&b);
/* answer = merge the two sorted lists together */
*.
An Introduction to Part of C++ STL for OI. Introduced the common use of STL algorithms and containers, especially those are helpful to OI.
Also with some examples.
COURSE TITLE: SOFTWARE DEVELOPMENT VI
COURSE CODE: VIT 351
TOPICS COVERED:
ARRAYS
TYPES OF ARRAYS
MULTIDIMENSIONAL ARRAYS
CHARACTER HANDLING IN C
STRING HANDLING IN C
QUIZ SET 2
The language is C. Thanks. Write a function that computes the intege.pdfforwardcom41
The language is C. Thanks. Write a function that computes the integer mean of an array of
integers. For example, the integer mean of - 1, 4, 2 is (- 1 + 4 + 2)/3 = 5/3 = 1, where/denotes
integer division. The function should implement the following specification;/* Computes the
integer mean of an array and stores it * where mn references. Returns -J for erroneous input *
(len
Solution
// C code
#include
int mean(int *a, int len, int *mn)
{
if(len <= 0)
return -1;
*mn = 0;
int i = 0;
for (i = 0; i < len; ++i)
{
*mn = *mn + *(a+i);
}
*mn = *mn/len;
return 0;
}
int main()
{
int size;
printf(\"Enter size of array: \");
scanf(\"%d\",&size);
int i;
int array[size];
for (i = 0; i < size; ++i)
{
printf(\"Enter array element at index %d: \",(i+1));
scanf(\"%d\",&array[i]);
}
int mn;
int result = mean(array, size, &mn);
if(result == 0)
printf(\"Mean: %d\ \", mn);
else
printf(\"Erroneous input\ \");
return 0;
}
/*
output:
Enter size of array: 3
Enter array element at index 1: -1
Enter array element at index 2: 4
Enter array element at index 3: 2
Mean: 1
*/.
C++ Searching & Sorting5. Sort the following list using the select.pdfRahul04August
C++ Searching & Sorting
5. Sort the following list using the selection sort algorithm. Show the list after each iteration of
the outerforloop.
36, 55, 17, 35, 63, 85, 12, 48, 3, 66
6. Consider the following list: 5, 18, 21, 10, 55, 20
The first three keys are in order. To move 10 to its proper position using the insertion sort as
described in this chapter, exactly how many key comparisons are executed?
7. Consider the following list: 7, 28, 31, 40, 5, 20
The first four keys are in order. To move 5 to its proper position using the insertion sort as
described in this chapter, exactly how many key comparisons are executed?
8. Consider the following list: 28, 18, 21, 10, 25, 30, 12, 71, 32, 58, 15
This list is to be sorted using the insertion sort algorithm. Show the resulting list after six
passes of the sorting phase – that is, after six iterations of the for loop.
9. Perform the insertion sort algorithm using the following list of keys: 18, 8, 11, 9, 15, 20, 32,
61, 22, 48, 75, 83, 35, 3
Show the list after each iteration. Exactly how many key comparisons are executed to sort this
list using insertion sort?
10. a. The performance of bubble sort can be improved if we stop the sorting process as soon as
we find that in an iteration, no swapping of elements takes place. Write a function that
implements bubble sort algorithm using this fact.
b. Using the algorithm that you designed in part (a), find the number of iterations that are needed
to sort the list: 65, 14, 52, 43, 75, 25, 80, 90, 95.
11. Suppose that L is a sorted list of 4096 elements. What is the maximum number of
comparisons made by binary search to determine whether an item is in L?
12. Suppose that the elements of a list are in descending order, and they need to be put in
ascending order. Write a C++ function that takes as input an array of items in descending order
and the number of elements in the array. The function must not incorporate any sorting
algorithms, that is, no item comparisons should take place.
Solution
# include
# include
# include
#include
#include
#include
#include
// Function related to sorting in class sorting
class sorting
{
int array[50],array1[50],final[100],i,n,m,j;
public:
// Function to read an array
void read();
// Function to read arrays for merge sort
void read_mer();
// Function to display an array
void display();
// Function to perform bubble sort
void bub_sort();
// Function to perform selection sort
void Sel_sort();
// Function to perform insertion sort
void Ins_sort();
// Function to perform quick sort
void Qui_sort();
// Function to perform heap sort
void Heap_sort();
// Function to build a heap
void heap(int array[], int n);
// Function to interchange the value of root node with a
// child node in heap sort
void below_heap(int array[], int first, int last);
// Function to perform merges sort
void Mer_sort();
// Function to perform shell sort
void Shell_sort();
// Function to split the array into two halves during quick sort
void partition(int arra.
Imagine a spherical balloon filled wild helium- the balloon itself is.pdfdhavalbl38
Imagine a spherical balloon filled wild helium- the balloon itself is magically crafted to expand
and contract freely without exerting any restorative force Some weights (with negligible volume)
are hung from the balloon such that the total mass of helium + balloon + weights is m Assume
the balloon is surrounded by with constant density p_0 and constant pressure P_0, independent
of altitude.
Solution
Gas equation PV = nRT
As the pressure P is constant
P dV/dt = nR dT/dt
dV/dt =nR/P dT/dt
initial condition P0V0 = nRT0
dV/dt = (V0/T0) dT/dt
upward thrust on the ballon
F = Vg – mg
Differentiate with t , we have
dF/dt = gdV/dt
initial the balloon is at rest hence
V0 g – mg = 0 hence m = V0
mda/dt = gdV/dt
= g*(V0/T0)* dT/dt
da/dt = g/T0 * dT/dt
we can express rate of change of acceleration in terms of g, which has units of acceleration
da/dt = (1/T0)dT/dt
integrating it
a(t) = T(t)/T0
given T(t) = T0(2 - 1/t+1)
a(t) = 2 – 1/t+1
dv(t)/dt = 2 – 1/t+1
v(t) = 2t – ln(t+1).
If a substance has a pH of 4, is it acidic or basic. What type of io.pdfdhavalbl38
If a substance has a pH of 4, is it acidic or basic. What type of ion is it going to give off when
dissolved in water?
Solution
If a substance has a pH of 4, it is acidic in nature.
An acid donates hydrogen ions. So,when this acid is dissolved in water (H2O), the balance
between hydrogen ions and hydroxide ions is shifted. There will be more hydrogen ions rather
than hydroxide ions in the solution. This kind of solution is called acidic solution.
H2O -----------------> H+ + OH-
Note:
If,
pH < 7 = Acidic in nature
pH = 7 = Neutral solutions
pH > 7 = Basic / Alkaline in nature.
More Related Content
Similar to c++ program I need to sort arrays using an insertion sort and a mer.pdf
computer dataA computer is a machine that can be programmed to carry out sequences of arithmetic or logical operations (computation) automatically. Modern digital electronic computers can perform generic sets of operations known as programs. These programs enable computers to perform a wide range of tasks. A computer system is a nominally complete computer that includes the hardware, operating system (main software), and peripheral equipment needed and used for full operation. This term may also refer to a group of computers that are linked and function together, such as a computer network or computer cluster.
A broad range of industrial and consumer products use computers as control systems. Simple special-purpose devices like microwave ovens and remote controls are included, as are factory devices like industrial robots and computer-aided design, as well as general-purpose devices like personal computers and mobile devices like smartphones. Computers power the Internet, which links billions of other computers and users.
Early computers were meant to be used only for calculations. Simple manual instruments like the abacus have aided people in doing calculations since ancient times. Early in the Industrial Revolution, some mechanical devices were built to automate long, tedious tasks, such as guiding patterns for looms. More sophisticated electrical machines did specialized analog calculations in the early 20th century. The first digital electronic calculating machines were developed during World War II. The first semiconductor transistors in the late 1940s were followed by the silicon-based MOSFET (MOS transistor) and monolithic integrated circuit chip technologies in the late 1950s, leading to the microprocessor and the microcomputer revolution in the 1970s. The speed, power and versatility of computers have been increasing dramatically ever since then, with transistor counts increasing at a rapid pace (as predicted by Moore's law), leading to the Digital Revolution during the late 20th to early 21st centuries.
Write a program that obtains the execution time of selection sort, bu.pdfarri2009av
Write a java program called Question39 that does the following: Gets input for temperature
Utilizing a branching statement: If temperature is 76-100, call method outputHot passing the
temperature input as an argument. If temperature is 0-39, call method outputCold passing the
temperature input as an argument. If temperature is 40 to 75, call method outputJustRight
passing the temperature input as an argument. If temperature is outside these ranges, output
“Temperature outside range” to the screen. Be precise, import modules, include comments,
prologue, etc. as needed.
Solution
Question39.java
import java.util.Scanner;
public class Question39 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println(\"Enter temperature: \");
int temp = scan.nextInt();
if(temp >=76 && temp <=100){
outputHot(temp);
}
else if(temp >=0 && temp <=39){
outputCold(temp);
}
else if(temp >=40 && temp <=75){
outputJustRight(temp);
}
else{
System.out.println(\"Temperature outside range\");
}
}
public static void outputHot(int temp){
System.out.println(\"Temperature \"+temp+\" Hot \");
}
public static void outputCold(int temp){
System.out.println(\"Temperature \"+temp+\" Cold \");
}
public static void outputJustRight(int temp){
System.out.println(\"Temperature \"+temp+\" Just Right \");
}
}
Output:
Enter temperature:
45
Temperature 45 Just Right.
Merge Sort implementation in C++ The implementation for Mergesort gi.pdfmdameer02
Merge Sort implementation in C++ The implementation for Mergesort given in Section 7.4 takes
an array as input and soils that array. At the beginning of Section 7.4 there is a simple
pseudocode implementation for sorting a linked list using Mergesort. Implement both a linked
list-based version of Mergesort and the array-based version of Mergesort. and compare and
analyze their running times.
Solution
/* Merger sort array-based version */
/* C program for Merge Sort */
#include
#include
// Merges two subarrays of arr[].
// First subarray is arr[l..m]
// Second subarray is arr[m+1..r]
void merge(int arr[], int l, int m, int r)
{
int i, j, k;
int n1 = m - l + 1;
int n2 = r - m;
/* create temp arrays */
int L[n1], R[n2];
/* Copy data to temp arrays L[] and R[] */
for (i = 0; i < n1; i++)
L[i] = arr[l + i];
for (j = 0; j < n2; j++)
R[j] = arr[m + 1+ j];
/* Merge the temp arrays back into arr[l..r]*/
i = 0; // Initial index of first subarray
j = 0; // Initial index of second subarray
k = l; // Initial index of merged subarray
while (i < n1 && j < n2)
{
if (L[i] <= R[j])
{
arr[k] = L[i];
i++;
}
else
{
arr[k] = R[j];
j++;
}
k++;
}
/* Copy the remaining elements of L[], if there
are any */
while (i < n1)
{
arr[k] = L[i];
i++;
k++;
}
/* Copy the remaining elements of R[], if there
are any */
while (j < n2)
{
arr[k] = R[j];
j++;
k++;
}
}
/* l is for left index and r is right index of the
sub-array of arr to be sorted */
void mergeSort(int arr[], int l, int r)
{
if (l < r)
{
// Same as (l+r)/2, but avoids overflow for
// large l and h
int m = l+(r-l)/2;
// Sort first and second halves
mergeSort(arr, l, m);
mergeSort(arr, m+1, r);
merge(arr, l, m, r);
}
}
/* UTILITY FUNCTIONS */
/* Function to print an array */
void printArray(int A[], int size)
{
int i;
for (i=0; i < size; i++)
printf(\"%d \", A[i]);
printf(\"\ \");
}
/* Driver program to test above functions */
int main()
{
int arr[] = {12, 11, 13, 5, 6, 7};
int arr_size = sizeof(arr)/sizeof(arr[0]);
printf(\"Given array is \ \");
printArray(arr, arr_size);
mergeSort(arr, 0, arr_size - 1);
printf(\"\ Sorted array is \ \");
printArray(arr, arr_size);
return 0;
}
--------------------------------------------------------------------------------------------------------------------
/* merge sort link-list version
#include
#include
/* Link list node */
struct node
{
int data;
struct node* next;
};
/* function prototypes */
struct node* SortedMerge(struct node* a, struct node* b);
void FrontBackSplit(struct node* source,
struct node** frontRef, struct node** backRef);
/* sorts the linked list by changing next pointers (not data) */
void MergeSort(struct node** headRef)
{
struct node* head = *headRef;
struct node* a;
struct node* b;
/* Base case -- length 0 or 1 */
if ((head == NULL) || (head->next == NULL))
{
return;
}
/* Split head into \'a\' and \'b\' sublists */
FrontBackSplit(head, &a, &b);
/* Recursively sort the sublists */
MergeSort(&a);
MergeSort(&b);
/* answer = merge the two sorted lists together */
*.
An Introduction to Part of C++ STL for OI. Introduced the common use of STL algorithms and containers, especially those are helpful to OI.
Also with some examples.
COURSE TITLE: SOFTWARE DEVELOPMENT VI
COURSE CODE: VIT 351
TOPICS COVERED:
ARRAYS
TYPES OF ARRAYS
MULTIDIMENSIONAL ARRAYS
CHARACTER HANDLING IN C
STRING HANDLING IN C
QUIZ SET 2
The language is C. Thanks. Write a function that computes the intege.pdfforwardcom41
The language is C. Thanks. Write a function that computes the integer mean of an array of
integers. For example, the integer mean of - 1, 4, 2 is (- 1 + 4 + 2)/3 = 5/3 = 1, where/denotes
integer division. The function should implement the following specification;/* Computes the
integer mean of an array and stores it * where mn references. Returns -J for erroneous input *
(len
Solution
// C code
#include
int mean(int *a, int len, int *mn)
{
if(len <= 0)
return -1;
*mn = 0;
int i = 0;
for (i = 0; i < len; ++i)
{
*mn = *mn + *(a+i);
}
*mn = *mn/len;
return 0;
}
int main()
{
int size;
printf(\"Enter size of array: \");
scanf(\"%d\",&size);
int i;
int array[size];
for (i = 0; i < size; ++i)
{
printf(\"Enter array element at index %d: \",(i+1));
scanf(\"%d\",&array[i]);
}
int mn;
int result = mean(array, size, &mn);
if(result == 0)
printf(\"Mean: %d\ \", mn);
else
printf(\"Erroneous input\ \");
return 0;
}
/*
output:
Enter size of array: 3
Enter array element at index 1: -1
Enter array element at index 2: 4
Enter array element at index 3: 2
Mean: 1
*/.
C++ Searching & Sorting5. Sort the following list using the select.pdfRahul04August
C++ Searching & Sorting
5. Sort the following list using the selection sort algorithm. Show the list after each iteration of
the outerforloop.
36, 55, 17, 35, 63, 85, 12, 48, 3, 66
6. Consider the following list: 5, 18, 21, 10, 55, 20
The first three keys are in order. To move 10 to its proper position using the insertion sort as
described in this chapter, exactly how many key comparisons are executed?
7. Consider the following list: 7, 28, 31, 40, 5, 20
The first four keys are in order. To move 5 to its proper position using the insertion sort as
described in this chapter, exactly how many key comparisons are executed?
8. Consider the following list: 28, 18, 21, 10, 25, 30, 12, 71, 32, 58, 15
This list is to be sorted using the insertion sort algorithm. Show the resulting list after six
passes of the sorting phase – that is, after six iterations of the for loop.
9. Perform the insertion sort algorithm using the following list of keys: 18, 8, 11, 9, 15, 20, 32,
61, 22, 48, 75, 83, 35, 3
Show the list after each iteration. Exactly how many key comparisons are executed to sort this
list using insertion sort?
10. a. The performance of bubble sort can be improved if we stop the sorting process as soon as
we find that in an iteration, no swapping of elements takes place. Write a function that
implements bubble sort algorithm using this fact.
b. Using the algorithm that you designed in part (a), find the number of iterations that are needed
to sort the list: 65, 14, 52, 43, 75, 25, 80, 90, 95.
11. Suppose that L is a sorted list of 4096 elements. What is the maximum number of
comparisons made by binary search to determine whether an item is in L?
12. Suppose that the elements of a list are in descending order, and they need to be put in
ascending order. Write a C++ function that takes as input an array of items in descending order
and the number of elements in the array. The function must not incorporate any sorting
algorithms, that is, no item comparisons should take place.
Solution
# include
# include
# include
#include
#include
#include
#include
// Function related to sorting in class sorting
class sorting
{
int array[50],array1[50],final[100],i,n,m,j;
public:
// Function to read an array
void read();
// Function to read arrays for merge sort
void read_mer();
// Function to display an array
void display();
// Function to perform bubble sort
void bub_sort();
// Function to perform selection sort
void Sel_sort();
// Function to perform insertion sort
void Ins_sort();
// Function to perform quick sort
void Qui_sort();
// Function to perform heap sort
void Heap_sort();
// Function to build a heap
void heap(int array[], int n);
// Function to interchange the value of root node with a
// child node in heap sort
void below_heap(int array[], int first, int last);
// Function to perform merges sort
void Mer_sort();
// Function to perform shell sort
void Shell_sort();
// Function to split the array into two halves during quick sort
void partition(int arra.
Similar to c++ program I need to sort arrays using an insertion sort and a mer.pdf (20)
Imagine a spherical balloon filled wild helium- the balloon itself is.pdfdhavalbl38
Imagine a spherical balloon filled wild helium- the balloon itself is magically crafted to expand
and contract freely without exerting any restorative force Some weights (with negligible volume)
are hung from the balloon such that the total mass of helium + balloon + weights is m Assume
the balloon is surrounded by with constant density p_0 and constant pressure P_0, independent
of altitude.
Solution
Gas equation PV = nRT
As the pressure P is constant
P dV/dt = nR dT/dt
dV/dt =nR/P dT/dt
initial condition P0V0 = nRT0
dV/dt = (V0/T0) dT/dt
upward thrust on the ballon
F = Vg – mg
Differentiate with t , we have
dF/dt = gdV/dt
initial the balloon is at rest hence
V0 g – mg = 0 hence m = V0
mda/dt = gdV/dt
= g*(V0/T0)* dT/dt
da/dt = g/T0 * dT/dt
we can express rate of change of acceleration in terms of g, which has units of acceleration
da/dt = (1/T0)dT/dt
integrating it
a(t) = T(t)/T0
given T(t) = T0(2 - 1/t+1)
a(t) = 2 – 1/t+1
dv(t)/dt = 2 – 1/t+1
v(t) = 2t – ln(t+1).
If a substance has a pH of 4, is it acidic or basic. What type of io.pdfdhavalbl38
If a substance has a pH of 4, is it acidic or basic. What type of ion is it going to give off when
dissolved in water?
Solution
If a substance has a pH of 4, it is acidic in nature.
An acid donates hydrogen ions. So,when this acid is dissolved in water (H2O), the balance
between hydrogen ions and hydroxide ions is shifted. There will be more hydrogen ions rather
than hydroxide ions in the solution. This kind of solution is called acidic solution.
H2O -----------------> H+ + OH-
Note:
If,
pH < 7 = Acidic in nature
pH = 7 = Neutral solutions
pH > 7 = Basic / Alkaline in nature.
Help with answering these questions for my Human Health Class Biolog.pdfdhavalbl38
Help with answering these questions for my Human Health Class Biology 2020
INGREDIENTS: COOKED FETTUCCINI PASTA (WATER, SEMOLINA [DURUM
WHEAT, NIACIN, IRON, FERROUS SULFATE, THIAMINE MONONITRATE,
RIBOFLAVIN, FOLIC ACID], EGG WHITES), GARLIC BREAD (BLEACHED ENRICHED
FLOUR [MALTED BARLEY FLOUR, NIACIN, REDUCED IRON, THIAMINE
MONONITRATE, RIBOFLAVIN, FOLATE], WATER, VEGETABLE OIL [SOYBEAN
AND/OR COTTONSEED OIL], YEAST, SALT, HIGH FRUCTOSE CORN SYRUP,
ENRICHED WHEAT FLOUR [FLOUR, NIACIN, REDUCED IRON, THIAMINE
MONONITRATE, RIBOFLAVIN, FOLIC ACID], DATEM, VEGETABLE SHORTENING
[PARTIALLY HYDROGENATED SOYBEAN OIL, TBHQ ADDED TO PRESERVE
FRESHNESS], CONTAINS LESS THAN 2% OF THE FOLLOWING: ASCORBIC ACID, L-
CYSTEINE HYDROCHLORIDE, AZODICAR-BONAMIDE, ENZYMES, CALCIUM
PEROXIDE, CALCIUM PROPIONATE, ENZYME, TOPPINGS [LIQUID AND PARTIALLY
HYDROGENATED SOYBEAN OIL, WATER, SALT, LECITHIN, MONOGLYCERIDES,
SODIUM BENZOATE {PRESERVATIVE}, CITRIC ACID, NATURAL FLAVOR,
ARTIFICIAL FLAVOR, BETA CAROTENE, VITAMIN A PALMITATE, CALCIUM
DISODIUM EDTA {TO PROTECT FLAVOR}, PARSLEY FLAKES]), WATER, CARROTS,
BROCCOLI, HEAVY WHIPPING CREAM, SOYBEAN OIL, CREAM CHEESE
(PASTEURIZED MILK AND CREAM, CHEESE CULTURES, SALT, CAROB BEAN GUM),
ROMANO (FROM COW’S MILK) AND PARMESAN CHEESE (PART-SKIM MILK,
CHEESE CULTURES, SALT, ENZYMES, CELLULOSE POWDER [PREVENTS CAKING]),
HALF AND HALF (MILK, CREAM), CONTAINS 2% OR LESS OF: GARLIC SHERRY
WINE, STABILIZER (MODIFIED FOOD STARCH, SODIUM PHOSPHATE, MONO- AND
DIGLYCERIDES, DEHYDRATED GARLIC, XANTHAN AND GUAR GUMS, SALT,
PAPRIKA), SUGAR, SALT, BUTTER (CREAM, SALT), FLAVORINGS, BUTTER FLAVOR
(PARTIALLY HYDROGENATED SOYBEAN OIL, FLAVOR [BUTTER OIL, ENZYME
MODIFIED BUTTERFAT, WHEY POWDER, NONFAT DRY MILK POWDER, SOY
LECITHIN {EMULSIFIER}]), POLYGLYCEROL ESTERS OF FATTY ACIDS, SPICE,
PAPRIKA, BETA CAROTENE.
Nutrition Facts
Serving Size 1 Meal (397g)
Amount Per Serving
Calories 770
Calories from Fat 420
% Daily Value*
Total Fat 46g
?%
Saturated Fat 16g
?%
Trans Fat 0.5g
Cholesterol 30mg
?%
Sodium 129mg
?%
Total Carbohydrate 69g
?%
Dietary Fiber 11g
?%
Sugars 9g
Protein 19g
Vitamin A 80%
•
Vitamin C 0%
Calcium 35%
•
Iron 6%
* Percent Daily Values are based on a 2,000 calorie diet. Your Daily Values may be higher or
lower depending on your calorie needs.
Calories
2,000
2,500
Total Fat
Less than
65g
80g
Sat Fat
Less than
20g
25g
Cholesterol
Less than
300mg
300mg
Sodium
Less than
2400mg
2400mg
Total Carbohydrate
300g
375g
Dietary Fiber
25g
30g
Referring to the label above:
1. a. Is this product a good source of fiber?
b. Calculate the percentage of the Daily Value for fiber for a 2,500-calorie diet that is
contributed by this product.
c. Calculate the percentage of the DRI for a 2,500-calorie diet that is contributed by this
product.
2. Is this a nutrient-dense product? Why or why not?
3. What percentage of the Daily Value for total carbohydrate (for 2,000 calories) comes from
this product?
Label Analysis—Lipids (from chapter 5)
Instructions: Use t.
For each task, submit your source java code file.(1) Objective Im.pdfdhavalbl38
For each task, submit your source java code file.
(1) Objective: Implement Link List
Write a class that maintains the scores for a game application. Implement the addition and
removal function to update the database. The gamescore.txt contains player’ name and score data
record fields separated by comma. For Removal function, uses the name field to select record to
remove the game score record.
Download – List.java, LList.java, Dlink.java, GameEntry.java, gamescore.txt
(a)Read gamescore.txt to initialize the Linked list in sorted order. (1 point)
(b)Provide Remove and Add function for user to update the sorted linked list. (1 point)
(2)Add a reverse function to the LList.java class to reverse the order of the linked list. (2 points).
---------------------------------------------------------------------------------------------------------------------
-----------------------------------------
//gamescore.txt
Mike,1105
Rob,750
Paul,720
Anna,660
Rose,590
Jack,510
--------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------
//DLink.java
/** Source code example for \"A Practical Introduction to Data
Structures and Algorithm Analysis, 3rd Edition (Java)\"
by Clifford A. Shaffer
Copyright 2008-2011 by Clifford A. Shaffer
*/
/** Doubly linked list node */
class DLink {
private E element; // Value for this node
private DLink next; // Pointer to next node in list
private DLink prev; // Pointer to previous node
/** Constructors */
DLink(E it, DLink p, DLink n)
{ element = it; prev = p; next = n; }
DLink(DLink p, DLink n) { prev = p; next = n; }
/** Get and set methods for the data members */
DLink next() { return next; }
DLink setNext(DLink nextval)
{ return next = nextval; }
DLink prev() { return prev; }
DLink setPrev(DLink prevval)
{ return prev = prevval; }
E element() { return element; }
E setElement(E it) { return element = it; }
}
--------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------
//GameEntry.java
public class GameEntry {
protected String name;
protected int score;
public GameEntry(String n, int s) {
name = n;
score = s;
}
public String getName() {return name;}
public int getScore() {return score;}
public String toString() {
return \"(\"+name+\",\"+score+\")\";
}
}
--------------------------------------------------------------------------------------------------------------------
----------------------------------
//List.java
/** Source code example for \"A Practical Introduction to Data
Structures and Algorithm Analysis, 3rd Edition (Java)\"
by Clifford A. Shaffer
Copyright 2008-2011 by Clifford A. Shaffer
*/
/** List ADT */
public interface List {
/** Remove all contents from the list, so it is once again
empty. Client is responsible for reclaiming storage
used by the list elements. */
p.
Emperor penguins live on a diet of fish and crustaceans obtained fro.pdfdhavalbl38
Emperor penguins live on a diet of fish and crustaceans obtained from cold Antarctic seawaters.
However, during their breeding cycle, they migrate to inland breeding grounds nearly 100 km
away from their source of food. As a result, male emperor penguins do not eat for the two
months that they protect and incubate the single egg laid by their mate. During this time, each of
the tens of thousands of male penguins can lose up to 50% of its body mass (by dry weight).
Where does the majority of this penguin mass go?A. The mass is converted to energy and used
up.B. The mass is converted to urine and feces and eliminated from the body.C. The mass is
converted to ATP molecules.D. The mass is released as CO2 and H2O.
Solution
DURING THIS PERIOD THE MASS WOULD BE USED UP IN FORM OF ENERGY
REQUIRED DURING SUCH PERIOD. OPTION A. The mass is converted to energy and used
up. is answer.
Even before the Ownership Society programs of Presidents Clinton.pdfdhavalbl38
Even before the \\Ownership Society\" programs of Presidents Clinton and Bush, the federal
government was heavily involved in the housing market. In a study just prior to the foreclosure
crisis starting in 2008, the Urban Institute started about 80% of the estimated $200 billion
of federal housing subsidies consisted of tax breaks. Samples indicated that federal housing
benefits average $8,268 for those with incomes $200,000 and $500,000 and only $365 for those
with incomes of $40,000 to $50,000. The respective standard deviations were $2,100 and $150.
They were obtained from sample sizes of 150.
1. the statistical test obtained is 45.9741 and p value is 0.0000. Test whether the benefits
to the high income group are at least $7,500 more than the benefits to the low income
group using = 0:05. Make sure to state the null and the alternative hypotheses. Assume
bene ts are normally distributed for both income groups.
Solution.
Do the following picSolutionHere is the solution for the .pdfdhavalbl38
Do the following pic:
Solution
Here is the solution for the first 2 problems in the pic:
#include
using namespace std;
template
class Dec
{
public:
//hasDuplicate function that returns true if the private data member has an item that appears
twice or more in the list.
bool hasDuplicate();
//eraseAll function to remove all items which are equal to the item specified in the function
parameter.
void eraseAll(ElementType element);
//isLessThan function to determine if another Dec object is greater than the Dec object itself.
//If the summation of all items from the Dec object itself is less than the summation of all
//items from another Dec object, return true, otherwise, return false.
bool isLessThan(Dec other);
//push_second function to add an item after the first item if there are more than one items.
void push_second(ElementType element);
private:
vector dec;
};
template
bool Dec::hasDuplicate()
{
for(vector::iterator ot = dec.begin(); ot != dec.end(); ot++)
for(vector::iterator it = dec.begin() + ot + 1; it != dec.end(); it++)
if(*it == *ot)
return true;
return false;
}
template
bool Dec::isLessThan(Dec other)
{
int sum1 = 0, sum2 = 0;
for(vector::iterator it = dec.begin(); it != dec.end(); it++)
sum1 += *it;
for(vector::iterator it = other.dec.begin(); it != other.dec.end(); it++)
sum2 += *it;
return sum1 < sum2;
}.
Can one mRNA be translated into more than one protein sequence Can .pdfdhavalbl38
Can one mRNA be translated into more than one protein sequence? Can more than one type of
mRNA be transcribed in a single cell?
Solution
The prokaryotic mRNAs are called as polycistronic since a single mRNA codes for more than
one protein, whareas the eukaryotic mRNA is monocistronic, because it codes for single
polypeptide.hence the given statement true for prokaryotes. Second statement is also absolutely
true. Because in a cell meny genes are in the process of transcription or translation or both at the
same time in the same cell.hence one cell has more than one type of mRNA..
why is there an uneven distribution of photosystem 1 and 2 on the th.pdfdhavalbl38
why is there an uneven distribution of photosystem 1 and 2 on the thylakoid membrane?
Solution
Photosynthesis is carried out by the cyanobacteria, plants involved the absorption of light and the
conversion of its energy into chemical energy. The photosynthetic apparatus is made up of 4
multiprotein complexes, which are asymmetrically embedded in the thyalkoid memberane. It is
the high structural and functional coordination between these 4 complexes, which enables the
efficient coupling of photosynthetic electron transfer and photophosphorylation.
The 4 complexes - Photosystem II (PSII), cytochrome b6f complex, PS I and the proton-ATP
synthase, are unevenly distributed between the 2 regions of the thylakoids. The PS II complex is
situated in the appressed grana-lamella region, the PS I and the ATP synthase complex are
located in the non-appressed stroma-lamella region.
Light driven electron transfer is intiated with the oxidation of water mole. by the PS II complex
and the reduction of quinones associated with the PS II complex. The electrons are then
transferred across the memberane to plastocyanin via the Cyt b6f complex. Plastocyanin is a
copper protein facing the lumen of the thylakoids, is the secondary electron donor of the PS I
complex. In the PS I the electron are translocated across the memberane to ferredoxin which
further transfers them to NADP+. The membrane potental and proton gradient resulting from this
photochemical electron transport provide the motive force required for the formation of ATP by
the ATP synthase.
The transport of electron against the electrical potential and the formation of ATP and NADPH
are made possible due to the unique ability of the thylakoids to absorb light energy. The 2
pigment complexes (PS II and PS I) are responsible for harvesting the light and performing the
charge separation across the thylakoid memberanes.
Photosytem II (PS II):
1. PS II is located at the inner surface the grana thyalkoid memberane
2. The photocentre is P680
3. Pigments absorb shorter wavelengths of light (<680nm)
4. Participates only in non cyclic photophosphorylation
5. It is associated with photolysis of water
6. Main functions are ATP synthesis and hydrolysis of water
Photosystem I (PS I)
1. PS I is located at the outer surface the grana thylakoid memberane
2. The photocentre is P700
3. Pigments absorb longer wavelength of light (>680nm)
4. Participates in cyclic and non-cyclic photophosphorylation
5. It is not associated with photolysis of water
6. Main function is ATP synthesis
This is the purpose the two photosystems (PS) are unevely distributed in thyalkoid memberane..
Which of the following are examples of cell signaling Choose all tha.pdfdhavalbl38
Which of the following are examples of cell signaling? Choose all that apply. As a response to
increasing densities, bacteria coordinate behaviors and form biofilms. Insulin hormone produced
by the pancreas triggers the intake of glucose by liver cells. Carbon dioxide diffuses across the
cell membrane into the blood plasma. Chlorophyll absorbs and transfers light energy during
photosynthesis. A neuron releases neurotransmitters into a synapse, triggering a target nerve
cell.
Solution
Cell signaling
Cell signaling is the communication between the cells through which they coordinate
certain activities.
What is the purpose of testing a program with different dataSol.pdfdhavalbl38
What is the purpose of testing a program with different data?
Solution
The purpose of testing a program functions according to the expectation. The overall goal of
testing is to find a bug that might effect the functioning of the program. There are various types
of testing and each serve their own purpose. Different data is used for each type of testing. We
have to check the whether internal module is functioning properly, how the program responds to
invalid data, test how changing one module will effect the whole system etc.. There are many
automated tools which can be used for comprehensive testing..
what are the factors contributing to the rise in global media Will .pdfdhavalbl38
what are the factors contributing to the rise in global media? Will global media eventually
replace national media?
Solution
Q1) Media is the mass communication system of letting people informed through broadcasting,
publishing, and the internet. It enriches public awareness and knowledge, which is very
important in today’s fast moving world.
Global media gives the news of whole world, suppose a person sitting in India can get the
happenings in the US.
Factors are as below:
Point 1) The urge of national media: There are so many small national media in various
countries. They want to get international news as well but can’t get because of their small
infrastructure. Therefore, they are now becoming tied up with big international media agencies in
order to get regular updating. This is the reason of rising trend of global media.
Point 2) Globalization of economy: Most of the countries have free-trade environment now.
They need cheaper rate of factors of production (land, labor, capital, and organization); the
global media is a great source of information of it.
Point 3) Technological development: The development of internet gives the platform of rising of
global media. A person sitting on computer can get to know the whole world.
Q2) To some extent it is true. Since national media getting tied up with big global firms, the
chance of being acquired may be high in future. The small national media could be acquired by
those global media..
WACC of Alibaba company WACC of Alibaba companySolutionTh.pdfdhavalbl38
WACC of Alibaba company
WACC of Alibaba company
Solution
The Weighted Average Cost of Capital Alibaba company as of the latest quarter report is
18.28%. Alibaba company generates more return on investment than the cost of capital. WACC
is the rate that a company is expected to pay its stockholders and other lenders of money..
Two particles A and B of equal mass have velocities as shown in the f.pdfdhavalbl38
Two particles A and B of equal mass have velocities as shown in the figure to the right. If the
particles collide, circle the situation(s) shown 111 the figures below that represent possible
velocities for the particles after impact. The velocities in all figures are shown to scale. [0.5 mark
for each correct answer]
Solution
Since thy have equal masses they will exchange velocities both for horizontal and vertical
component.
horizontal is head on collision so they will have horizontal velocity in opposite direction..
The forecast equation for mean wind in a turbulent flow is U_it + .pdfdhavalbl38
The forecast equation for mean wind in a turbulent flow is: U_i/t + U_j U_i/x_j = delta_i3 g +
f_c epsilon_ij3 U_j - 1/p P/x_i + v ^2 U_i/x^2_j u\'_i u\'_j/x_j Name each term, and give its
physical interpretation.
Solution
solution
A is storage of mean momentum
B is advection of mean momentum by the mean wind
C is gravity to act in the vertical direction only
D is the Coriolis effect due to the earth’s rotation
E is the mean pressure gradient forces
F is the effect of viscous stress on the mean motions
G is the effect of Reynolds stress on the mean motions (also called the divergence of turbulent
momentum flux).
The image below is of a charged moving in a uniform magnetic field. I.pdfdhavalbl38
The image below is of a charged moving in a uniform magnetic field. Is the particle positively
or negatively charged?
Solution
According to Fleming left hand rule,
When the thumb,first finger,middle finger are streatched perpendicular to each other and the first
finger represents the magnetic field direction ,middle finger represents the direction of motion of
positive charged particle then the thumb represents force on charged particle.
In figure , magnetic field into the paper and the particle deflect right.So, the charged particle is
negative nature.
The concept of a sampling distributionA-Is essential for drawing c.pdfdhavalbl38
The concept of a sampling distribution
A-Is essential for drawing conclusions about a population from the results of a sample.
B- Is related to the use of probability theory in inferential statistics.
C-Helps us use statistics to estimate the corresponding true values in the population.
D-All of the above.
Solution
The concept of a sampling distribution
D-All of the above..
The diets common to some cultures emphasize meat. Meat, milk, and br.pdfdhavalbl38
The diets common to some cultures emphasize meat. Meat, milk, and bread, but few fruits and
vegetables, might be a typical meal for populations in northern latitudes and in desert areas, for
example. What ecological factors seem relevant in explaining this human habit?
Solution
Various studies have shown that populations living in northern latitude and desert areas have
dietary patterns higher in animal fat such as meat and dairy products compared to those living in
southern latitudes who thrive majorly on fruits and vegetables. This may be because land in
northern and desert areas had been less fertile to grow seasonal vegeies, due to extremes of
environment and limited rainfalls. People living in these areas over generations have been mostly
hunter-gatherers. Such societies had depended for their economic survival primarily on hunting,
gathering (wild vegetable and fruits and small land fauna), and fishing. Thus they might have
developed the food habit of increased meat and milk consumption (as they are largely dependent
on herd of cattle/animals) along with staple diet of breads, over the generations.
On the other hand, southern populations residing on more fertile pieces of land relish a
vegetarian diet consisting of fresh fruits and vegetables. They are richer in biodiversity due to
moderate climates and rainfall distribution throughtout the year. These populations are typically
farmers, food growers over several generations and have developed food habits of vegetarian
diets..
aed by genes at two loci R. rand P. p). A walnut comb is at one Tocus.pdfdhavalbl38
aed by genes at two loci R. rand P. p). A walnut comb is at one Tocus and at least one dominant
inant gene A pi R P A rose comb is produced when at least and two recessive genes are present
at the the first locus at pea comb is produced when two recessive genes are least one dominant
gene is at are present at the first and the second locas sNuces 2 for comb shape of the parents in
the fol walnut, 1 single, and 1 pea offspring. ngle comb ing cross: Rose 3/. The mutation (bard es
is inherited as a maternal effect recessive allele. What is the expected ratio of preho termale and
a bad bed male? in offspring cross between bcd normal: mutant 1 3 mutant normal c 3 mutant 1
normal 32 Could the characteristic followed in the pedigree be caused by an autosomal dominant
disease? not?
Solution
32............is pedigree explaining about autosomal dominant disease/.
t t Deg g olthe year.) 4.9 An engineering construction firm is .pdfdhavalbl38
t t Deg g olthe year.) 4.9 An engineering construction firm is chartered to provide consulting
services, design, and a limited range of construction services. Its designs have developed into
registered patents Some designs are licensed by subcontractors, the firm not choosing to use
them itself; it does re- ceive income from that business arrangement. These accounts and their
balance are summa- rized below or a family-owned firm titled \"Eastwood s are in units of
$1000, but ignore r each account title, first identify if it is an asset, liability, net worth, income,
expense, Find the income statement and balance sheet f Engineering Services,\" Second Quarter.
(Hints: These value that. Fo or tax. Each account will have a spot in either the income or
balance-sheet statement.)
Solution
Income Statement Revenue in $ in $ Fees Recived 73 Sales of design 7 Equipment
Lease 6 Royality on Patent 40 Interest On owned Securities 126 Less Salary
Expense 28 Utilities Paid 5 Taxes 12 Office Rent 1 Travel 4 Interest On owned
Securities 2 Supplies Expense 9 61 Net Income after tax 65 Balance sheet
Liability Amount in $ Asset Amount in $ Opening bal of retained earning 27 Equipment Book
Value 58 Profit as per income statement 65 Receivable from project 55 Capital Stock 25
Account Payable 30 Patent Asset 11 Bond Owned 12 Cash in Hand 3.
Francesca Gottschalk - How can education support child empowerment.pptxEduSkills OECD
Francesca Gottschalk from the OECD’s Centre for Educational Research and Innovation presents at the Ask an Expert Webinar: How can education support child empowerment?
Honest Reviews of Tim Han LMA Course Program.pptxtimhan337
Personal development courses are widely available today, with each one promising life-changing outcomes. Tim Han’s Life Mastery Achievers (LMA) Course has drawn a lot of interest. In addition to offering my frank assessment of Success Insider’s LMA Course, this piece examines the course’s effects via a variety of Tim Han LMA course reviews and Success Insider comments.
2024.06.01 Introducing a competency framework for languag learning materials ...Sandy Millin
http://sandymillin.wordpress.com/iateflwebinar2024
Published classroom materials form the basis of syllabuses, drive teacher professional development, and have a potentially huge influence on learners, teachers and education systems. All teachers also create their own materials, whether a few sentences on a blackboard, a highly-structured fully-realised online course, or anything in between. Despite this, the knowledge and skills needed to create effective language learning materials are rarely part of teacher training, and are mostly learnt by trial and error.
Knowledge and skills frameworks, generally called competency frameworks, for ELT teachers, trainers and managers have existed for a few years now. However, until I created one for my MA dissertation, there wasn’t one drawing together what we need to know and do to be able to effectively produce language learning materials.
This webinar will introduce you to my framework, highlighting the key competencies I identified from my research. It will also show how anybody involved in language teaching (any language, not just English!), teacher training, managing schools or developing language learning materials can benefit from using the framework.
Model Attribute Check Company Auto PropertyCeline George
In Odoo, the multi-company feature allows you to manage multiple companies within a single Odoo database instance. Each company can have its own configurations while still sharing common resources such as products, customers, and suppliers.
Introduction to AI for Nonprofits with Tapp NetworkTechSoup
Dive into the world of AI! Experts Jon Hill and Tareq Monaur will guide you through AI's role in enhancing nonprofit websites and basic marketing strategies, making it easy to understand and apply.
c++ program I need to sort arrays using an insertion sort and a mer.pdf
1. c++ program: I need to sort arrays using an insertion sort and a merge sort (I already have). I
need to use these sorting methods to sort input arrays in the form of randomly generated numbers
in the size of 20, 100 and 200. So I need 3 randomily generated arrays and sorted and outputed
by both sorting method. I currently have it as given arrays and need help changing them to
randomily generated arrays
Here is my code so far:
#include
using namespace std;
void InsertionSort(int arr[],int size){
int temp,j;
for(int i=0; i=0){
arr[j+1] = arr[j];
j--;
}
arr[j+1] = temp;
}
}
//Merges two sub-arrays. First sub-array is arr[l..m],second is arr[m+1..r]
void merge(int arr[], int l, int m, int r){
int i, j, k;
int n1 = m - l + 1;
int n2 = r - m;
//Create temp arrays
int L[n1], R[n2];
//Copy data to temp arrays L[] and R[]
for (i = 0; i < n1; i++)
L[i] = arr[l + i];
for (j = 0; j < n2; j++)
R[j] = arr[m + 1+ j];
/* Merge arrays back into arr[l..r]*/
i = 0;
j = 0;
k = l;
2. while (i < n1 && j < n2){
if (L[i] <= R[j]){
arr[k] = L[i];
i++;
}
else{
arr[k] = R[j];
j++;
}
k++;
}
//Copy the remaining elements of L[], if there are any
while (i < n1){
arr[k] = L[i];
i++;
k++;
}
//Copy the remaining elements of R[], if there are any
while (j < n2){
arr[k] = R[j];
j++;
k++;
}
}
//l is left index and r is right index of the sub-array of array to be sorted
void MergeSort(int arr[], int l, int r){
if (l < r){
// Same as (l+r)/2, but avoids overflow for large l and h
int m = l+(r-l)/2;
// Sort first and second halves
MergeSort(arr, l, m);
MergeSort(arr, m+1, r);
merge(arr, l, m, r);
}
}
3. void printArray(int arr[], int size){//Function to print array
int i;
for (i=0; i < size; i++)
cout << arr[i] <<" ";
cout << endl;
}
int main(){
int size = 20;
int array1[] = {17,33,88,54,96,82,12,36,69,74,79,66,32,11,1,98,76,55,3,4};
int array2[] = {20,1,19,2,18,3,17,4,16,5,15,6,14,7,13,8,12,9,11,10};
int array3[] = {220,209,198,187,176,165,154,143,132,121,110,99,88,77,66,55,44,33,22,11};
int array4[] = {15,35,85,100,40,90,70,65,25,5,10,30,55,75,80,95,20,45,50,60};
int array5[] = {100,99,98,97,96,95,94,93,92,91,90,89,88,87,86,85,84,83,82,81};
//Output for array1
cout << "Original array 1: ";
printArray(array1, size);
InsertionSort(array1, size);
cout << "Array 1 sorted by INSERTION SORT: ";
printArray(array1, size);
cout << " ";
//Output for array2
cout << "Original array 2: ";
printArray(array2, size);
MergeSort(array2,0,size);
cout << "Array 2 sorted by MERGE SORT: ";
printArray(array2, size);
cout << " ";
//Output for array3
cout << "Original array 3: ";
printArray(array3, size);
InsertionSort(array3, size);
cout << "Array 3 sorted by INSERTION SORT: ";
printArray(array3, size);
4. cout << " ";
//Output for array4
cout << "Original array 4: ";
printArray(array4, size);
MergeSort(array4,0,size);
cout << "Array 4 sorted by MERGE SORT: ";
printArray(array4, size);
cout << " ";
//Output for array5
cout << "Original array 5: ";
printArray(array5, size);
InsertionSort(array5, size);
cout << "Array 5 sorted by INSERTION SORT: ";
printArray(array5, size);
return 0;
}
Solution
#include
using namespace std;
void InsertionSort(int arr[],int size){
int temp,j;
for(int i=0; i=0){
arr[j+1] = arr[j];
j--;
}
arr[j+1] = temp;
}
}
//Merges two sub-arrays. First sub-array is arr[l..m],second is arr[m+1..r]
void merge(int arr[], int l, int m, int r){
int i, j, k;
5. int n1 = m - l + 1;
int n2 = r - m;
//Create temp arrays
int L[n1], R[n2];
//Copy data to temp arrays L[] and R[]
for (i = 0; i < n1; i++)
L[i] = arr[l + i];
for (j = 0; j < n2; j++)
R[j] = arr[m + 1+ j];
/* Merge arrays back into arr[l..r]*/
i = 0;
j = 0;
k = l;
while (i < n1 && j < n2){
if (L[i] <= R[j]){
arr[k] = L[i];
i++;
}
else{
arr[k] = R[j];
j++;
}
k++;
}
//Copy the remaining elements of L[], if there are any
while (i < n1){
arr[k] = L[i];
i++;
k++;
}
//Copy the remaining elements of R[], if there are any
while (j < n2){
arr[k] = R[j];
j++;
6. k++;
}
}
//l is left index and r is right index of the sub-array of array to be sorted
void MergeSort(int arr[], int l, int r){
if (l < r){
// Same as (l+r)/2, but avoids overflow for large l and h
int m = l+(r-l)/2;
// Sort first and second halves
MergeSort(arr, l, m);
MergeSort(arr, m+1, r);
merge(arr, l, m, r);
}
}
void printArray(int arr[], int size){//Function to print array
int i;
for (i=0; i < size; i++)
cout << arr[i] <<" ";
cout << endl;
}
int main(){
int size = 20;
int array1[] = {17,33,88,54,96,82,12,36,69,74,79,66,32,11,1,98,76,55,3,4};
int array2[] = {20,1,19,2,18,3,17,4,16,5,15,6,14,7,13,8,12,9,11,10};
int array3[] = {220,209,198,187,176,165,154,143,132,121,110,99,88,77,66,55,44,33,22,11};
int array4[] = {15,35,85,100,40,90,70,65,25,5,10,30,55,75,80,95,20,45,50,60};
int array5[] = {100,99,98,97,96,95,94,93,92,91,90,89,88,87,86,85,84,83,82,81};
int i;
int a[20];
for(i=0;i<20;i++)
a[i]=rand();
printArray(a,20);