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.
Write a java program to randomly generate the following sets of data.pdfarshin9
Write a java program to randomly generate the following sets of data:
1.) 10 numbers
2.) 1,000 numbers
3.) 100,000 numbers
4.) 1,000,000 numbers
5.) 10,000,000 numbers
Your program must sort the above sets of numbers using the following algorithms:
1.) Insertion Sort
2.) Merge Sort
3.) Quick Sort
4.) Heap Sort
Print out the time each algorithm takes to sort the above numbers
Solution
import java.util.Random;
public class Sort {
private int[] array;
private int size ;
public Sort(int n){
array = new int[n];
size = n;
Random rand = new Random();
for (int i = 0 ; i < n ; i++ ) {
array[i] = rand.nextInt(100000) ;
}
}
public void print(){
for (int i = 0; i < size ; i++ ) {
System.out.print(array[i] + \" \");
}
System.out.println(\"\");
}
void insertion_sort()
{
for (int i=1; i=0 && array[j] > key)
{
array[j+1] = array[j];
j = j-1;
}
array[j+1] = key;
}
}
void merge(int arr[], int l, int m, int r)
{
// Find sizes of two subarrays to be merged
int n1 = m - l + 1;
int n2 = r - m;
/* Create temp arrays */
int L[] = new int [n1];
int R[] = new int [n2];
/*Copy data to temp arrays*/
for (int i=0; i Array to be sorted,
low --> Starting index,
high --> Ending index */
void quick_sort(int low, int high)
{
if (low < high)
{
/* pi is partitioning index, arr[pi] is
now at right place */
int pi = partition(array, low, high);
// Recursively sort elements before
// partition and after partition
quick_sort(low, pi-1);
quick_sort(pi+1, high);
}
}
public void heap_sort()
{
int n = array.length;
// Build heap (rearrange array)
for (int i = n / 2 - 1; i >= 0; i--)
heapify(array, n, i);
// One by one extract an element from heap
for (int i=n-1; i>=0; i--)
{
// Move current root to end
int temp = array[0];
array[0] = array[i];
array[i] = temp;
// call max heapify on the reduced heap
heapify(array, i, 0);
}
}
// To heapify a subtree rooted with node i which is
// an index in arr[]. n is size of heap
void heapify(int arr[], int n, int i)
{
int largest = i; // Initialize largest as root
int l = 2*i + 1; // left = 2*i + 1
int r = 2*i + 2; // right = 2*i + 2
// If left child is larger than root
if (l < n && arr[l] > arr[largest])
largest = l;
// If right child is larger than largest so far
if (r < n && arr[r] > arr[largest])
largest = r;
// If largest is not root
if (largest != i)
{
int swap = arr[i];
arr[i] = arr[largest];
arr[largest] = swap;
// Recursively heapify the affected sub-tree
heapify(arr, n, largest);
}
}
public static void main(String[] args) {
Sort sort1 = new Sort(10);
long start = System.currentTimeMillis();
sort1.insertion_sort();
long time = System.currentTimeMillis() - start;
//sort1.print();
System.out.println(\"insertion_sort for 10 numbers take \" + time + \" ms \");
sort1 = new Sort(10);
start = System.currentTimeMillis();
sort1.merge_sort(0,9);
time = System.currentTimeMillis() - start;
//sort1.print();
System.out.println(\"merge_sort for 10 numbers take \" + time + \" ms \");
sort1 = new Sort(10);
start = System.currentTimeMillis();
sort1.quick_sor.
I have written the code but cannot complete the assignment please help.pdfshreeaadithyaacellso
I have written the code but cannot complete the assignment please help me to complete.
Please don't just copy other s answers as your own.
// Insertion sort
/*
#include <ctime>
#include <iostream>
using namespace std;
void insertionSort(int arr[], int n) {
int i, key, j;
for (i = 1; i < n; i++) {
key = arr[i];
j = i - 1;
// Move elements of arr[0..i-1], that are greater than key, to one position ahead of their current
position
while (j >= 0 && arr[j] > key) {
arr[j + 1] = arr[j];
j = j - 1;
}
arr[j + 1] = key;
}
}
int main() {
int n;
cout << "Enter the size of the array: ";
cin >> n;
int arr[n];
cout << "Enter the elements of the array: ";
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
int num = sizeof(arr) / sizeof(arr[0]);
clock_t start, end;
double timetaken;
start = clock();
insertionSort(arr, num);
end = clock();
cout << "Sorted array: \n";
for (int i = 0; i < n; i++)
cout << arr[i] << " ";
cout << endl;
timetaken = ((double) (end - start)) / CLOCKS_PER_SEC;
cout << "Time taken : " << fixed << timetaken << "s" << endl;
return 0;
}
*/
// Shell Sort
/*
#include <ctime>
#include <iostream>
using namespace std;
int shellSort(int arr[], int n) {
for (int gap = n/2; gap > 0; gap /= 2) {
for (int i = gap; i < n; i += 1) {
int temp = arr[i];
int j;
for (j = i; j >= gap && arr[j - gap] > temp; j -= gap)
arr[j] = arr[j - gap];
arr[j] = temp;
}
}
return 0;
}
void printArray(int arr[], int n) {
for (int i=0; i<n; i++)
cout << arr[i] << " ";
}
int main() {
int n;
cout << "Enter the size of the array: ";
cin >> n;
int arr[n];
cout << "Enter the elements of the array: ";
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
int num = sizeof(arr) / sizeof(arr[0]);
clock_t start, end;
double timetaken;
start = clock();
shellSort(arr, num);
end = clock();
cout << "\nArray after sorting: \n";
printArray(arr, n);
cout << endl;
timetaken = (double)(end - start) / CLOCKS_PER_SEC;
cout << "Time taken : " << fixed << timetaken << "s" << endl;
return 0;
}
*/
// MergeSort
/*
#include <ctime>
#include <iostream>
using namespace std;
void merge(int arr[], int l, int m, int r) {
int i, j, k;
int n1 = m - l + 1;
int n2 = r - m;
int L[n1], R[n2];
for (i = 0; i < n1; i++)
L[i] = arr[l + i];
for (j = 0; j < n2; j++)
R[j] = arr[m + 1 + j];
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++;
}
while (i < n1) {
arr[k] = L[i];
i++;
k++;
}
while (j < n2) {
arr[k] = R[j];
j++;
k++;
}
}
void mergeSort(int arr[], int l, int r) {
if (l < r) {
int m = l + (r - l) / 2;
mergeSort(arr, l, m);
mergeSort(arr, m + 1, r);
merge(arr, l, m, r);
}
}
int main() {
int n;
cout << "Enter the size of the array: ";
cin >> n;
int arr[n];
cout << "Enter the elements of the array: ";
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
int arr_size = sizeof(arr) / sizeof(arr[0]);
clock_t start;
clock_t end;
double timetaken;
start = clock();
mergeSort(arr, 0, arr_size - 1);
end = clock();
timetaken = (double)(end - start) / CLOCKS_PER_SEC;
.
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.
1sequences and sampling. Suppose we went to sample the x-axis from X.pdfrushabhshah600
1sequences and sampling. Suppose we went to sample the x-axis from Xmin to Xmax using a
step size of step
A)Draw a picture of what is going on.
B) Write a expression for n the total number of samples involved (in terms of Xmin, Xmax and
step)
C) Write out the sequence of x-samples
D) Write a direct and general expression for xi that captures the sequence
E) Write a recursive expression for the sequence
F) Write a program to compute and store the x-samples over the range -5x5 using a step size of
0.1 do everything in main ()
2 . We talked about the following string functions that are available in C (as long as you include
string.h):
int strlen(char str[])
void strcpy(char str1[], char str2[])
void strcat(char str1[], str2[])
Write your own versions of these functions; for example: int paul_strlen(int char str[]). Hint: for
your version of the strlen function, start at the first character in the array and keep counting until
you find the ‘\\0’ character (use a while loop for this). Note: Use your version of the strlen
function in the strcpy and strcat functions.
9. We want to insert a number into an array.
(a) Formulate the problem mathematically with two sequences: x and y. (b) Write a function of
the form:
insertNumIntoArray(int n, int array[], int num, int index)
The function inserts num into the array at the specified index. The rest of the array then follows.
For example, if num = 9 and index = 3 and array = [7 2 8 8 3 1 2] then the function will produce:
array = [7 2 8 9 8 3 1 2]
Note: assume that array is properly dimensioned to have at least 1 extra space for storage.
10. Repeat #2 by for the delete operation; that is, we want to delete a single element (at a
specified index) from an array; for example, suppose index = 3 and array = [50 70 10 90 60 20],
then the result will be
array: [50 70 10 60 20]
11. Repeat #2 by for an insert operation where we are inserting several values into the array. The
function should be of the form:
int insertArrayIntoArray(int n, int inArray[],
int nInsert, int insertArray[], int outArray[], int index)
The dimension of outArray is returned (explicitly). For example:
inArrayarray: [7 2 8 6 3 9]
insertArray: [50 60 70]
index: 2
outArray: [7 2 50 60 70 8 6 3 9]
Assume that outArray is large enough to hold all n + nInsert values.
Solution
#include
//Simulates strlen() library function
int paul_strlen(char str[])
{
int l;
for(l = 0; str[l] != \'\\0\'; l++) ;
return l;
}
//Simulates strcpy() library function
void paul_strcpy(char str1[], char str2[])
{
int c;
for(c = 0; str1[c] != \'\\0\'; c++)
str2[c] = str1[c];
str2[c] = \'\\0\';
printf(\"\ Original String: %s\", str1);
printf(\"\ Copied String: %s\", str2);
}
//Simulates strcat() library function
void paul_strcat(char str1[], char str2[])
{
int i, j;
for(i = 0; str1[i] != \'\\0\'; i++) ;
for (j = 0; str2[j] != \'\\0\'; i++, j++)
{
str1[i] = str2[j];
}
str1[i] = \'\\0\';
printf(\"\ Concatenated String: %s\", str1);
}
int main()
{
char data1[20], data2[20];
pri.
Problem 1 Show the comparison of runtime of linear search and binar.pdfebrahimbadushata00
Problem 1: Show the comparison of runtime of linear search and binary search using line chart
and table. Execute both algorithms 6 times on same data(use random integer generators), where
input data size are: 50000, 100000, 150000, 200000, 250000, and 300000. Please report worst
case runtimes so that the search item is not found in the input data.
Problem 2: Show the comparison of runtime of bubble sort and merge sort using line chart and
table. Execute both algorithms 6 times on same data(use random integer generators), where data
size are: 50000, 100000, 150000, 200000, 250000, and 300000. In each execution, sort the data
in ascending order.
Solution
Search & sort comparison for differnt sort & search algorithms.
Problem1: Java Code:
import java.util.Random;
public class SearchComparison {
public static void main(String[] args) {
//Compare linear & binary search for
//random data 6 times & print its execution time
System.out.println(\"--------------------------------\");
//50000
searchComparison(50000);
System.out.println(\"--------------------------------\");
//100000
searchComparison(100000);
System.out.println(\"--------------------------------\");
//150000
searchComparison(150000);
System.out.println(\"--------------------------------\");
//200000
searchComparison(200000);
System.out.println(\"--------------------------------\");
//250000
searchComparison(250000);
System.out.println(\"--------------------------------\");
//and 300000
searchComparison(300000);
System.out.println(\"--------------------------------\");
}
/**
* searchComparison
* @param size
*/
public static void searchComparison(int size){
System.out.println(\"Input size:\"+size);
//Generate random numbers list for given size
Random randomGenerator = new Random();
int list[]=new int[size];
for (int index = 0; index < size; ++index){
list[index]=randomGenerator.nextInt(size);
}
//For worst case key must be last number list[size-1]
long startTime=System.nanoTime();
linearSearch(list, list[size-1]);
long endTime=System.nanoTime();
long totalTime=(endTime-startTime); //time in nanoseconds
System.out.println(\"Linear search: input size=\"+size+\" - time=\"+totalTime);
startTime=System.nanoTime();
binarySearch(list, list[size-1]);
endTime=System.nanoTime();
totalTime=(endTime-startTime); //time in milliseconds
System.out.println(\"Binary search: input size=\"+size+\" - time=\"+totalTime);
}
/**
* Linearly search key in list[]. If key is present then return the index,
* otherwise return -1
*
* @param list
* @param key
* @return
*/
public static int linearSearch(int list[], int key) {
for (int index = 0; index < list.length; index++) {
if (list[index] == key)
return index;
}
return -1;
}
/**
* BinarySearch search key in list[]. If key is present then return the
* index, otherwise return -1
*
* @param list
* @param key
* @return
*/
public static int binarySearch(int list[], int key) {
int lo = 0;
int hi = list.length - 1;
while (lo <= hi) {
// Key is in list[lo..hi] or not present..
Write a program (any language) to randomly generate the following se.pdfarchanaemporium
Write a program (any language) to randomly generate the following sets of data: 1) 10 numbers
2) 1,000 numbers 3) 100,000 numbers 4) 1,000,000 numbers 5) 10,000,000 numbers Your
program must sort the above sets of numbers using the following algorithms: a) Insertion Sort b)
Merge Sort c) Quick Sort d) Heap Sort Print out the time each algorithm takes to sort the above
numbers
Solution
import java.io.*;
publicclass randomNo{
publicstaticvoid main(String[] args) throws NumberFormatException, IOException {
int n1,n2,ch;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int count = 0;
do
{
System.out.println(\"\ \");
System.out.println(\"Menu:\");
System.out.println(\"1.Insertion Sort\");
System.out.println(\"2.Heap Sort.\");
System.out.println(\"3.Quick SOrt\");
System.out.println(\"4.Merge SOrt\");
System.out.println(\"5.Exit\");
System.out.println(\"Enter your choice: \");
ch=Integer.parseInt(br.readLine());
switch(ch)
{
case 1:
System.out.println(\"Enter range to generate random numbers--Enter n1 & n2::\");
n1=Integer.parseInt(br.readLine());
n2=Integer.parseInt(br.readLine());
int[] arr=newint[n2];
for (int i = 0; i < 10 ; i++)
{
int Random = (n1) + (int)(Math.random()* ((n2-n1)+1));
arr[i]=Random;
System.out.println(Random);
count++;
}
insertionSort(arr,count);
break;
case 2:
System.out.println(\"Enter range to generate random numbers--Enter n1 & n2::\");
n1=Integer.parseInt(br.readLine());
n2=Integer.parseInt(br.readLine());
int[] arr1=newint[20];
for (int i = 0; i < 10 ; i++)
{
int Random = (n1) + (int)(Math.random()* ((n2-n1)+1));
arr1[i]=Random;
System.out.println(Random);
count++;
}
System.out.println(\"\ Before Sorting\");
for(int i=0; i1; i--) {
HeapSort(arr1, i - 1);
}
System.out.println(\"\ Ascending Order\");
for(int i=0; i=0; i--) {
System.out.print(\" \" + arr1[i]);
}
break;
case 3:
System.out.println(\"Enter range to generate random numbers--Enter n1 & n2::\");
n1=Integer.parseInt(br.readLine());
n2=Integer.parseInt(br.readLine());
int[] arr3=newint[20];
for (int i = 0; i < 10 ; i++)
{
int Random = (n1) + (int)(Math.random()* ((n2-n1)+1));
arr3[i]=Random;
System.out.println(Random);
count++;
}
QuickSort(arr3, 0, count-1);
System.out.println(\"\ \ After Sorting\");
System.out.println(\"\ Ascending Order\");
for(int i=0; i=0; i--) {
System.out.print(\" \" + arr3[i]);
}
break;
case 4:
System.out.println(\"Enter range to generate random numbers--Enter n1 & n2::\");
n1=Integer.parseInt(br.readLine());
n2=Integer.parseInt(br.readLine());
int[] arr2=newint[20];
for (int i = 0; i < 10 ; i++)
{
int Random = (n1) + (int)(Math.random()* ((n2-n1)+1));
arr2[i]=Random;
System.out.println(Random);
count++;
}
System.out.println(\"\ Before Sorting\");
for(int i=0; i=0; i--) {
System.out.print(\" \" + arr2[i]);
}
break;
case 5:
System.out.println(\"Invalid\");
default:
break;
}
}while(ch!=5);
}
//Insertion Sort
publicstaticvoid insertionSort(int arr[],int n){
System.out.println(\"\ Before Sorting :\");
for(int i=0; i 0) && .
Write a java program to randomly generate the following sets of data.pdfarshin9
Write a java program to randomly generate the following sets of data:
1.) 10 numbers
2.) 1,000 numbers
3.) 100,000 numbers
4.) 1,000,000 numbers
5.) 10,000,000 numbers
Your program must sort the above sets of numbers using the following algorithms:
1.) Insertion Sort
2.) Merge Sort
3.) Quick Sort
4.) Heap Sort
Print out the time each algorithm takes to sort the above numbers
Solution
import java.util.Random;
public class Sort {
private int[] array;
private int size ;
public Sort(int n){
array = new int[n];
size = n;
Random rand = new Random();
for (int i = 0 ; i < n ; i++ ) {
array[i] = rand.nextInt(100000) ;
}
}
public void print(){
for (int i = 0; i < size ; i++ ) {
System.out.print(array[i] + \" \");
}
System.out.println(\"\");
}
void insertion_sort()
{
for (int i=1; i=0 && array[j] > key)
{
array[j+1] = array[j];
j = j-1;
}
array[j+1] = key;
}
}
void merge(int arr[], int l, int m, int r)
{
// Find sizes of two subarrays to be merged
int n1 = m - l + 1;
int n2 = r - m;
/* Create temp arrays */
int L[] = new int [n1];
int R[] = new int [n2];
/*Copy data to temp arrays*/
for (int i=0; i Array to be sorted,
low --> Starting index,
high --> Ending index */
void quick_sort(int low, int high)
{
if (low < high)
{
/* pi is partitioning index, arr[pi] is
now at right place */
int pi = partition(array, low, high);
// Recursively sort elements before
// partition and after partition
quick_sort(low, pi-1);
quick_sort(pi+1, high);
}
}
public void heap_sort()
{
int n = array.length;
// Build heap (rearrange array)
for (int i = n / 2 - 1; i >= 0; i--)
heapify(array, n, i);
// One by one extract an element from heap
for (int i=n-1; i>=0; i--)
{
// Move current root to end
int temp = array[0];
array[0] = array[i];
array[i] = temp;
// call max heapify on the reduced heap
heapify(array, i, 0);
}
}
// To heapify a subtree rooted with node i which is
// an index in arr[]. n is size of heap
void heapify(int arr[], int n, int i)
{
int largest = i; // Initialize largest as root
int l = 2*i + 1; // left = 2*i + 1
int r = 2*i + 2; // right = 2*i + 2
// If left child is larger than root
if (l < n && arr[l] > arr[largest])
largest = l;
// If right child is larger than largest so far
if (r < n && arr[r] > arr[largest])
largest = r;
// If largest is not root
if (largest != i)
{
int swap = arr[i];
arr[i] = arr[largest];
arr[largest] = swap;
// Recursively heapify the affected sub-tree
heapify(arr, n, largest);
}
}
public static void main(String[] args) {
Sort sort1 = new Sort(10);
long start = System.currentTimeMillis();
sort1.insertion_sort();
long time = System.currentTimeMillis() - start;
//sort1.print();
System.out.println(\"insertion_sort for 10 numbers take \" + time + \" ms \");
sort1 = new Sort(10);
start = System.currentTimeMillis();
sort1.merge_sort(0,9);
time = System.currentTimeMillis() - start;
//sort1.print();
System.out.println(\"merge_sort for 10 numbers take \" + time + \" ms \");
sort1 = new Sort(10);
start = System.currentTimeMillis();
sort1.quick_sor.
I have written the code but cannot complete the assignment please help.pdfshreeaadithyaacellso
I have written the code but cannot complete the assignment please help me to complete.
Please don't just copy other s answers as your own.
// Insertion sort
/*
#include <ctime>
#include <iostream>
using namespace std;
void insertionSort(int arr[], int n) {
int i, key, j;
for (i = 1; i < n; i++) {
key = arr[i];
j = i - 1;
// Move elements of arr[0..i-1], that are greater than key, to one position ahead of their current
position
while (j >= 0 && arr[j] > key) {
arr[j + 1] = arr[j];
j = j - 1;
}
arr[j + 1] = key;
}
}
int main() {
int n;
cout << "Enter the size of the array: ";
cin >> n;
int arr[n];
cout << "Enter the elements of the array: ";
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
int num = sizeof(arr) / sizeof(arr[0]);
clock_t start, end;
double timetaken;
start = clock();
insertionSort(arr, num);
end = clock();
cout << "Sorted array: \n";
for (int i = 0; i < n; i++)
cout << arr[i] << " ";
cout << endl;
timetaken = ((double) (end - start)) / CLOCKS_PER_SEC;
cout << "Time taken : " << fixed << timetaken << "s" << endl;
return 0;
}
*/
// Shell Sort
/*
#include <ctime>
#include <iostream>
using namespace std;
int shellSort(int arr[], int n) {
for (int gap = n/2; gap > 0; gap /= 2) {
for (int i = gap; i < n; i += 1) {
int temp = arr[i];
int j;
for (j = i; j >= gap && arr[j - gap] > temp; j -= gap)
arr[j] = arr[j - gap];
arr[j] = temp;
}
}
return 0;
}
void printArray(int arr[], int n) {
for (int i=0; i<n; i++)
cout << arr[i] << " ";
}
int main() {
int n;
cout << "Enter the size of the array: ";
cin >> n;
int arr[n];
cout << "Enter the elements of the array: ";
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
int num = sizeof(arr) / sizeof(arr[0]);
clock_t start, end;
double timetaken;
start = clock();
shellSort(arr, num);
end = clock();
cout << "\nArray after sorting: \n";
printArray(arr, n);
cout << endl;
timetaken = (double)(end - start) / CLOCKS_PER_SEC;
cout << "Time taken : " << fixed << timetaken << "s" << endl;
return 0;
}
*/
// MergeSort
/*
#include <ctime>
#include <iostream>
using namespace std;
void merge(int arr[], int l, int m, int r) {
int i, j, k;
int n1 = m - l + 1;
int n2 = r - m;
int L[n1], R[n2];
for (i = 0; i < n1; i++)
L[i] = arr[l + i];
for (j = 0; j < n2; j++)
R[j] = arr[m + 1 + j];
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++;
}
while (i < n1) {
arr[k] = L[i];
i++;
k++;
}
while (j < n2) {
arr[k] = R[j];
j++;
k++;
}
}
void mergeSort(int arr[], int l, int r) {
if (l < r) {
int m = l + (r - l) / 2;
mergeSort(arr, l, m);
mergeSort(arr, m + 1, r);
merge(arr, l, m, r);
}
}
int main() {
int n;
cout << "Enter the size of the array: ";
cin >> n;
int arr[n];
cout << "Enter the elements of the array: ";
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
int arr_size = sizeof(arr) / sizeof(arr[0]);
clock_t start;
clock_t end;
double timetaken;
start = clock();
mergeSort(arr, 0, arr_size - 1);
end = clock();
timetaken = (double)(end - start) / CLOCKS_PER_SEC;
.
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.
1sequences and sampling. Suppose we went to sample the x-axis from X.pdfrushabhshah600
1sequences and sampling. Suppose we went to sample the x-axis from Xmin to Xmax using a
step size of step
A)Draw a picture of what is going on.
B) Write a expression for n the total number of samples involved (in terms of Xmin, Xmax and
step)
C) Write out the sequence of x-samples
D) Write a direct and general expression for xi that captures the sequence
E) Write a recursive expression for the sequence
F) Write a program to compute and store the x-samples over the range -5x5 using a step size of
0.1 do everything in main ()
2 . We talked about the following string functions that are available in C (as long as you include
string.h):
int strlen(char str[])
void strcpy(char str1[], char str2[])
void strcat(char str1[], str2[])
Write your own versions of these functions; for example: int paul_strlen(int char str[]). Hint: for
your version of the strlen function, start at the first character in the array and keep counting until
you find the ‘\\0’ character (use a while loop for this). Note: Use your version of the strlen
function in the strcpy and strcat functions.
9. We want to insert a number into an array.
(a) Formulate the problem mathematically with two sequences: x and y. (b) Write a function of
the form:
insertNumIntoArray(int n, int array[], int num, int index)
The function inserts num into the array at the specified index. The rest of the array then follows.
For example, if num = 9 and index = 3 and array = [7 2 8 8 3 1 2] then the function will produce:
array = [7 2 8 9 8 3 1 2]
Note: assume that array is properly dimensioned to have at least 1 extra space for storage.
10. Repeat #2 by for the delete operation; that is, we want to delete a single element (at a
specified index) from an array; for example, suppose index = 3 and array = [50 70 10 90 60 20],
then the result will be
array: [50 70 10 60 20]
11. Repeat #2 by for an insert operation where we are inserting several values into the array. The
function should be of the form:
int insertArrayIntoArray(int n, int inArray[],
int nInsert, int insertArray[], int outArray[], int index)
The dimension of outArray is returned (explicitly). For example:
inArrayarray: [7 2 8 6 3 9]
insertArray: [50 60 70]
index: 2
outArray: [7 2 50 60 70 8 6 3 9]
Assume that outArray is large enough to hold all n + nInsert values.
Solution
#include
//Simulates strlen() library function
int paul_strlen(char str[])
{
int l;
for(l = 0; str[l] != \'\\0\'; l++) ;
return l;
}
//Simulates strcpy() library function
void paul_strcpy(char str1[], char str2[])
{
int c;
for(c = 0; str1[c] != \'\\0\'; c++)
str2[c] = str1[c];
str2[c] = \'\\0\';
printf(\"\ Original String: %s\", str1);
printf(\"\ Copied String: %s\", str2);
}
//Simulates strcat() library function
void paul_strcat(char str1[], char str2[])
{
int i, j;
for(i = 0; str1[i] != \'\\0\'; i++) ;
for (j = 0; str2[j] != \'\\0\'; i++, j++)
{
str1[i] = str2[j];
}
str1[i] = \'\\0\';
printf(\"\ Concatenated String: %s\", str1);
}
int main()
{
char data1[20], data2[20];
pri.
Problem 1 Show the comparison of runtime of linear search and binar.pdfebrahimbadushata00
Problem 1: Show the comparison of runtime of linear search and binary search using line chart
and table. Execute both algorithms 6 times on same data(use random integer generators), where
input data size are: 50000, 100000, 150000, 200000, 250000, and 300000. Please report worst
case runtimes so that the search item is not found in the input data.
Problem 2: Show the comparison of runtime of bubble sort and merge sort using line chart and
table. Execute both algorithms 6 times on same data(use random integer generators), where data
size are: 50000, 100000, 150000, 200000, 250000, and 300000. In each execution, sort the data
in ascending order.
Solution
Search & sort comparison for differnt sort & search algorithms.
Problem1: Java Code:
import java.util.Random;
public class SearchComparison {
public static void main(String[] args) {
//Compare linear & binary search for
//random data 6 times & print its execution time
System.out.println(\"--------------------------------\");
//50000
searchComparison(50000);
System.out.println(\"--------------------------------\");
//100000
searchComparison(100000);
System.out.println(\"--------------------------------\");
//150000
searchComparison(150000);
System.out.println(\"--------------------------------\");
//200000
searchComparison(200000);
System.out.println(\"--------------------------------\");
//250000
searchComparison(250000);
System.out.println(\"--------------------------------\");
//and 300000
searchComparison(300000);
System.out.println(\"--------------------------------\");
}
/**
* searchComparison
* @param size
*/
public static void searchComparison(int size){
System.out.println(\"Input size:\"+size);
//Generate random numbers list for given size
Random randomGenerator = new Random();
int list[]=new int[size];
for (int index = 0; index < size; ++index){
list[index]=randomGenerator.nextInt(size);
}
//For worst case key must be last number list[size-1]
long startTime=System.nanoTime();
linearSearch(list, list[size-1]);
long endTime=System.nanoTime();
long totalTime=(endTime-startTime); //time in nanoseconds
System.out.println(\"Linear search: input size=\"+size+\" - time=\"+totalTime);
startTime=System.nanoTime();
binarySearch(list, list[size-1]);
endTime=System.nanoTime();
totalTime=(endTime-startTime); //time in milliseconds
System.out.println(\"Binary search: input size=\"+size+\" - time=\"+totalTime);
}
/**
* Linearly search key in list[]. If key is present then return the index,
* otherwise return -1
*
* @param list
* @param key
* @return
*/
public static int linearSearch(int list[], int key) {
for (int index = 0; index < list.length; index++) {
if (list[index] == key)
return index;
}
return -1;
}
/**
* BinarySearch search key in list[]. If key is present then return the
* index, otherwise return -1
*
* @param list
* @param key
* @return
*/
public static int binarySearch(int list[], int key) {
int lo = 0;
int hi = list.length - 1;
while (lo <= hi) {
// Key is in list[lo..hi] or not present..
Write a program (any language) to randomly generate the following se.pdfarchanaemporium
Write a program (any language) to randomly generate the following sets of data: 1) 10 numbers
2) 1,000 numbers 3) 100,000 numbers 4) 1,000,000 numbers 5) 10,000,000 numbers Your
program must sort the above sets of numbers using the following algorithms: a) Insertion Sort b)
Merge Sort c) Quick Sort d) Heap Sort Print out the time each algorithm takes to sort the above
numbers
Solution
import java.io.*;
publicclass randomNo{
publicstaticvoid main(String[] args) throws NumberFormatException, IOException {
int n1,n2,ch;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int count = 0;
do
{
System.out.println(\"\ \");
System.out.println(\"Menu:\");
System.out.println(\"1.Insertion Sort\");
System.out.println(\"2.Heap Sort.\");
System.out.println(\"3.Quick SOrt\");
System.out.println(\"4.Merge SOrt\");
System.out.println(\"5.Exit\");
System.out.println(\"Enter your choice: \");
ch=Integer.parseInt(br.readLine());
switch(ch)
{
case 1:
System.out.println(\"Enter range to generate random numbers--Enter n1 & n2::\");
n1=Integer.parseInt(br.readLine());
n2=Integer.parseInt(br.readLine());
int[] arr=newint[n2];
for (int i = 0; i < 10 ; i++)
{
int Random = (n1) + (int)(Math.random()* ((n2-n1)+1));
arr[i]=Random;
System.out.println(Random);
count++;
}
insertionSort(arr,count);
break;
case 2:
System.out.println(\"Enter range to generate random numbers--Enter n1 & n2::\");
n1=Integer.parseInt(br.readLine());
n2=Integer.parseInt(br.readLine());
int[] arr1=newint[20];
for (int i = 0; i < 10 ; i++)
{
int Random = (n1) + (int)(Math.random()* ((n2-n1)+1));
arr1[i]=Random;
System.out.println(Random);
count++;
}
System.out.println(\"\ Before Sorting\");
for(int i=0; i1; i--) {
HeapSort(arr1, i - 1);
}
System.out.println(\"\ Ascending Order\");
for(int i=0; i=0; i--) {
System.out.print(\" \" + arr1[i]);
}
break;
case 3:
System.out.println(\"Enter range to generate random numbers--Enter n1 & n2::\");
n1=Integer.parseInt(br.readLine());
n2=Integer.parseInt(br.readLine());
int[] arr3=newint[20];
for (int i = 0; i < 10 ; i++)
{
int Random = (n1) + (int)(Math.random()* ((n2-n1)+1));
arr3[i]=Random;
System.out.println(Random);
count++;
}
QuickSort(arr3, 0, count-1);
System.out.println(\"\ \ After Sorting\");
System.out.println(\"\ Ascending Order\");
for(int i=0; i=0; i--) {
System.out.print(\" \" + arr3[i]);
}
break;
case 4:
System.out.println(\"Enter range to generate random numbers--Enter n1 & n2::\");
n1=Integer.parseInt(br.readLine());
n2=Integer.parseInt(br.readLine());
int[] arr2=newint[20];
for (int i = 0; i < 10 ; i++)
{
int Random = (n1) + (int)(Math.random()* ((n2-n1)+1));
arr2[i]=Random;
System.out.println(Random);
count++;
}
System.out.println(\"\ Before Sorting\");
for(int i=0; i=0; i--) {
System.out.print(\" \" + arr2[i]);
}
break;
case 5:
System.out.println(\"Invalid\");
default:
break;
}
}while(ch!=5);
}
//Insertion Sort
publicstaticvoid insertionSort(int arr[],int n){
System.out.println(\"\ Before Sorting :\");
for(int i=0; i 0) && .
Operator overloading is a technique by which operators used in a programming language are implemented in user-defined types with customized logic that is based on the types of arguments passed.
Hi, Please find my codeimport java.util.Random;public class Pro.pdfanujsharmaanuj14
Hi, Please find my code:
import java.util.Random;
public class ProcessArray {
private int rows; //The attribute for number of rows in matrix
private int columns; //The attribute for number of columns in matrix
private int[][] firstArray; //The attribute for the first array
private int[][] secondArray; //The attribute for the second array
public int[][] getFirstArray() { return firstArray;}
public int[][] getSecondArray() { return secondArray;}
public ProcessArray(int rows, int columns){ //Constructor of object ProcessArray
this.rows = rows;
this.columns = columns;
int[][] array = new int[rows][columns];
initializeArray(array);
randomlyFillArray();
computeArrayValues();
printArray(secondArray);
}
public void initializeArray(int[][] array){ //Initializes first and second arrays and sets each value
to 0
firstArray = new int[rows][columns];
secondArray = new int[rows][columns];
}
public void randomlyFillArray(){ //Fills first array with random numbers
for(int i = 0; i < firstArray.length;i++){
for(int j = 0; j < firstArray[0].length;j++){
Random r = new Random();
int num = r.nextInt(16);
firstArray[i][j] = num;
}
}
}
public void computeArrayValues(){
int col = firstArray[0].length;
int row = firstArray.length;
for(int i = 0; i < row; i++){
for(int j = 0; j< col; j++){
secondArray[i][j] = 0;
if((i - 1) >=0){
secondArray[i][j] += firstArray[i-1][j];
if((j+1) < col)
secondArray[i][j] += firstArray[i-1][j+1];
if(j > 0)
secondArray[i][j] += firstArray[i-1][j-1];
}
if((j+1) < col)
secondArray[i][j] += firstArray[i][j+1];
if(j > 0)
secondArray[i][j] += firstArray[i][j-1];
if((i+1) < row){
secondArray[i][j] += firstArray[i+1][j];
if((j+1) < col)
secondArray[i][j] += firstArray[i+1][j+1];
if(j > 0)
secondArray[i][j] += firstArray[i+1][j-1];
}
}
}
}
public void printArray(int[][] Array){
System.out.println(\"\ Initial Array Filled With Random Numbers: \ \");
for(int a = 0; a < firstArray.length; a++){
for(int b = 0; b < firstArray[0].length; b++){
if(b == 0)
System.out.printf(\"%d \", firstArray[a][b]);
else
System.out.printf(\"%d \", firstArray[a][b]);
}System.out.println();
}System.out.println();
System.out.println(\"Computed Array: \ \");
for(int a = 0; a < secondArray.length; a++){
for(int b = 0; b < secondArray[0].length; b++){
if(b == 0)
System.out.printf(\"%d \", secondArray[a][b]);
else
System.out.printf(\"%d \", secondArray[a][b]);
}
System.out.println();
}System.out.println();
}
public static void main(String[] args) {
ProcessArray pr = new ProcessArray(3, 4);
}
}
/*
Sample Output:
Initial Array Filled With Random Numbers:
7 3 6 12
10 2 11 10
12 14 1 7
Computed Array:
15 36 38 27
38 64 55 37
26 36 44 22
*/
Solution
Hi, Please find my code:
import java.util.Random;
public class ProcessArray {
private int rows; //The attribute for number of rows in matrix
private int columns; //The attribute for number of columns in matrix
private int[][] firstArray; //The attribute for the first array
private int[][] secondArray; //The attribute for the second arr.
Merge Sort java with a few details, please include comments if possi.pdffeelinggifts
Merge Sort java with a few details, please include comments if possible Generate an array with
100 random integers between 0 and 1000 Print the original array to the screen Use your merge
sort algorithm to sort the array from lowest to highest Print the sorted array to the screen
Solution
/* Class name MergeSortRandomNumber.java */
import java.util.Random;
public class MergeSortRandomNumber{
private int[] array;
private int[] tempMergArr;
private int length;
public static void main(String[] args) {
int inputArr[] =new int[10];// Storing array elements default 10 we can modify depends on
requirement
Random r = new Random();//Create Object for Random Predefined class
System.out.println(\"Random Numbers\");//Printing Random Numbers
for(int i=0;i<10;i++)
{
int Low = 0;//Start from 0
int High = 100;//Up to 100
int Result = r.nextInt(High-Low) + Low;
System.out.print(Result);//Prining on the console random numbers
System.out.print(\" \");
inputArr[i]=Result;
}
System.out.println(\"\");
System.out.println(\"Input Array\");//Printing input array on the console start
for(int i=0;i<10;i++)
{
System.out.print(inputArr[i]);//
System.out.print(\" \");
} //Printing input array on the console end
System.out.println(\"\");
System.out.println(\"After Merge sort from low to high\");
//merge Sort Main logic started
RandomNumber mms = new RandomNumber();
mms.sort(inputArr);//Passing our input array calling sort() method
for(int i:inputArr){
System.out.print(i);//printing Final values from low to high
System.out.print(\" \");
}
}
public void sort(int inputArr[]) {
this.array = inputArr;
this.length = inputArr.length;
this.tempMergArr = new int[length];
doMergeSort(0, length - 1);//Calling Merge sort main logic
}
private void doMergeSort(int lowerIndex, int higherIndex) {
if (lowerIndex < higherIndex) {
int middle = lowerIndex + (higherIndex - lowerIndex) / 2;
// Below step sorts the left side of the array
doMergeSort(lowerIndex, middle);
// Below step sorts the right side of the array
doMergeSort(middle + 1, higherIndex);
// Now merge both sides
mergeParts(lowerIndex, middle, higherIndex);
}
}
private void mergeParts(int lowerIndex, int middle, int higherIndex) {
//Compare elements at First and Second,
//and move smaller element at Merged array
for (int i = lowerIndex; i <= higherIndex; i++) {
tempMergArr[i] = array[i];
}
int i = lowerIndex;
int j = middle + 1;
int k = lowerIndex;
while (i <= middle && j <= higherIndex) {
if (tempMergArr[i] <= tempMergArr[j]) {
array[k] = tempMergArr[i];
i++;
} else {
array[k] = tempMergArr[j];
j++;
}
k++;
}
while (i <= middle) {
array[k] = tempMergArr[i];
k++;
i++;
}
}
}
=============================
Expected Out put
Random Numbers
19 95 97 32 86 36 48 34 46 71
Input Array
19 95 97 32 86 36 48 34 46 71
After Merge sort from low to high
19 32 34 36 46 48 71 86 95 97.
In this chapter we will learn about arrays as a way to work with sequences of elements of the same type. We will explain what arrays are, how we declare, create, instantiate and use them. We will examine one-dimensional and multidimensional arrays. We will learn different ways to iterate through the array, read from the standard input and write to the standard output. We will give many example exercises, which can be solved using arrays and we will show how useful they really are.
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.
The purpose of this C++ programming project is to allow the student .pdfRahul04August
The purpose of this C++ programming project is to allow the student to perform parallel array
and multidimensional array processing. The logic for string and Cstring has already been
completed, so the assignment can be started before we actually cover string and Cstring in detail.
This program has the following three menu options:
Solution
/*
This program uses simple arrays, multidimensional arrays, cstrings, strings, and files.
It allows a payroll clerk to choose an option from a menu. The choices are:
A: List the Payroll Information by Employee Name
B: Search Payroll Information by Employee Name
X: Exit the Payroll Information Module
The following items for each employee are saved in the file p10.txt:
Employee ID (1000 - 9999)
Last Name (15 characters)
First Name (15 characters)
Rate (5.00 - 10.00)
Hours W1,W2,W3,W4 (0-60)
*/
#include // file processing
#include // cin and cout
#include // toupper
#include // setw
#include // cstring functions strlen, strcmp, strcpy stored in string.h
#include // string class
#define stricmp strcasecmp
#define strnicmp strncasecmp
using namespace std;
//Disable warning messages C4267 C4996.
//To see the warnings, comment out the following line.
//#pragma warning( disable : 4267 4996)
//Warning C4267: coversion from size_t to int, possible lost of data
//size_t is a data type defined in and is an unsigned integer.
//The function strlen returns a value of the type size_t, but in
//searchByName we assign the returned value to an int.
//We could also declare the variable as size_t instead of int.
// size_t stringLength;
//Warning C4996: strnicmp strcpy, stricmp was declared deprecated, means
//the compiler encountered a function that was marked with deprecated.
//The deprecated function may no longer be supported in a future release.
//Global Constants
//When using to declare arrays, must be defined with const modifier
const int ARRAY_SIZE = 20, HOURS_SIZE = 4, NAME_SIZE = 16;
//Declare arrays as global so we don\'t have to pass the arrays to each function.
//Normally we wouldn\'t declare variables that change values a global.
int employeeId[ARRAY_SIZE];
string firstName[ARRAY_SIZE];
char lastName[ARRAY_SIZE][NAME_SIZE];
double rate[ARRAY_SIZE];
int hours[ARRAY_SIZE][HOURS_SIZE];
int numberOfEmps; //count of how many employees were loaded into arrays
int sumHours[ARRAY_SIZE] = {0}; //initialize arrays to zero by providing a
double avgHours[ARRAY_SIZE] = {0}; //value for the first element in the array
//Function Prototypes
void loadArray( );
void sumAndComputeAvgHours( );
void listByName( );
void searchByName( );
void sortByName( );
void swapValues(int i, int minIndex);
void listEmployees( );
void listEmployeesHeadings( );
void listEmployeesDetails(int i);
void listEmployeesTotals( );
void displayContinuePrompt( );
//Program starts here
int main()
{
//Declare and initialize local main variables
char choice; //menu option
//Load the arrays with data
loadArray();
//Sum and compute the average hours
sumAndComputeAv.
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
Identify five muscles of the head area that have a name that is very .pdfarri2009av
Identify five muscles of the head area that have a name that is very similar to the name of the
skull bone or bony structure the muscle is located on or attached to.
Solution
(Muscle) (Bone or the bony structure)OrbicularisOrbital
surfaceZygomaticusZygomatic boneTemporalisTemporal BoneFrontalisFrontal
BoneNasalisNasal Bone.
Identify non-neoplastic conditions effecting pregnancy. Describe STI conditions common to
females and how they are distributed.
Solution
During pregnancy, there are several non-neoplastic conditions that effect pregnancy. Some of
them are dysfunctional cysts, lesions of an ovary, tumors in breast, lymphoma, cervical cancer,
myeloma. these conditions may be benign or myeloma. the treatment depends on the condition
and effects the pregnancy.
The STI conditions that are common in women are human papillomavirus(HPV), gonorrhea,
chlamydia, and genital herpes. The HPV is the most common in women and is the main cause of
cervical cancer. This condition is distributed through direct sexual contact. Gonorrhea is
distributed through unprotected oral, anal, or vaginal sex. people with numerous sexual partners
or who does not have safe sex are at greater risk of the disease. Chlamydia is passed through
unprotected sex or oral sex. Genital herpes gets transmitted through the mucous membrane
which can be lining of mouth, nose, and genitals. Once the virus enters the body they start
multiplying and incorporate themselves into your body cells..
More Related Content
Similar to Write a program that obtains the execution time of selection sort, bu.pdf
Operator overloading is a technique by which operators used in a programming language are implemented in user-defined types with customized logic that is based on the types of arguments passed.
Hi, Please find my codeimport java.util.Random;public class Pro.pdfanujsharmaanuj14
Hi, Please find my code:
import java.util.Random;
public class ProcessArray {
private int rows; //The attribute for number of rows in matrix
private int columns; //The attribute for number of columns in matrix
private int[][] firstArray; //The attribute for the first array
private int[][] secondArray; //The attribute for the second array
public int[][] getFirstArray() { return firstArray;}
public int[][] getSecondArray() { return secondArray;}
public ProcessArray(int rows, int columns){ //Constructor of object ProcessArray
this.rows = rows;
this.columns = columns;
int[][] array = new int[rows][columns];
initializeArray(array);
randomlyFillArray();
computeArrayValues();
printArray(secondArray);
}
public void initializeArray(int[][] array){ //Initializes first and second arrays and sets each value
to 0
firstArray = new int[rows][columns];
secondArray = new int[rows][columns];
}
public void randomlyFillArray(){ //Fills first array with random numbers
for(int i = 0; i < firstArray.length;i++){
for(int j = 0; j < firstArray[0].length;j++){
Random r = new Random();
int num = r.nextInt(16);
firstArray[i][j] = num;
}
}
}
public void computeArrayValues(){
int col = firstArray[0].length;
int row = firstArray.length;
for(int i = 0; i < row; i++){
for(int j = 0; j< col; j++){
secondArray[i][j] = 0;
if((i - 1) >=0){
secondArray[i][j] += firstArray[i-1][j];
if((j+1) < col)
secondArray[i][j] += firstArray[i-1][j+1];
if(j > 0)
secondArray[i][j] += firstArray[i-1][j-1];
}
if((j+1) < col)
secondArray[i][j] += firstArray[i][j+1];
if(j > 0)
secondArray[i][j] += firstArray[i][j-1];
if((i+1) < row){
secondArray[i][j] += firstArray[i+1][j];
if((j+1) < col)
secondArray[i][j] += firstArray[i+1][j+1];
if(j > 0)
secondArray[i][j] += firstArray[i+1][j-1];
}
}
}
}
public void printArray(int[][] Array){
System.out.println(\"\ Initial Array Filled With Random Numbers: \ \");
for(int a = 0; a < firstArray.length; a++){
for(int b = 0; b < firstArray[0].length; b++){
if(b == 0)
System.out.printf(\"%d \", firstArray[a][b]);
else
System.out.printf(\"%d \", firstArray[a][b]);
}System.out.println();
}System.out.println();
System.out.println(\"Computed Array: \ \");
for(int a = 0; a < secondArray.length; a++){
for(int b = 0; b < secondArray[0].length; b++){
if(b == 0)
System.out.printf(\"%d \", secondArray[a][b]);
else
System.out.printf(\"%d \", secondArray[a][b]);
}
System.out.println();
}System.out.println();
}
public static void main(String[] args) {
ProcessArray pr = new ProcessArray(3, 4);
}
}
/*
Sample Output:
Initial Array Filled With Random Numbers:
7 3 6 12
10 2 11 10
12 14 1 7
Computed Array:
15 36 38 27
38 64 55 37
26 36 44 22
*/
Solution
Hi, Please find my code:
import java.util.Random;
public class ProcessArray {
private int rows; //The attribute for number of rows in matrix
private int columns; //The attribute for number of columns in matrix
private int[][] firstArray; //The attribute for the first array
private int[][] secondArray; //The attribute for the second arr.
Merge Sort java with a few details, please include comments if possi.pdffeelinggifts
Merge Sort java with a few details, please include comments if possible Generate an array with
100 random integers between 0 and 1000 Print the original array to the screen Use your merge
sort algorithm to sort the array from lowest to highest Print the sorted array to the screen
Solution
/* Class name MergeSortRandomNumber.java */
import java.util.Random;
public class MergeSortRandomNumber{
private int[] array;
private int[] tempMergArr;
private int length;
public static void main(String[] args) {
int inputArr[] =new int[10];// Storing array elements default 10 we can modify depends on
requirement
Random r = new Random();//Create Object for Random Predefined class
System.out.println(\"Random Numbers\");//Printing Random Numbers
for(int i=0;i<10;i++)
{
int Low = 0;//Start from 0
int High = 100;//Up to 100
int Result = r.nextInt(High-Low) + Low;
System.out.print(Result);//Prining on the console random numbers
System.out.print(\" \");
inputArr[i]=Result;
}
System.out.println(\"\");
System.out.println(\"Input Array\");//Printing input array on the console start
for(int i=0;i<10;i++)
{
System.out.print(inputArr[i]);//
System.out.print(\" \");
} //Printing input array on the console end
System.out.println(\"\");
System.out.println(\"After Merge sort from low to high\");
//merge Sort Main logic started
RandomNumber mms = new RandomNumber();
mms.sort(inputArr);//Passing our input array calling sort() method
for(int i:inputArr){
System.out.print(i);//printing Final values from low to high
System.out.print(\" \");
}
}
public void sort(int inputArr[]) {
this.array = inputArr;
this.length = inputArr.length;
this.tempMergArr = new int[length];
doMergeSort(0, length - 1);//Calling Merge sort main logic
}
private void doMergeSort(int lowerIndex, int higherIndex) {
if (lowerIndex < higherIndex) {
int middle = lowerIndex + (higherIndex - lowerIndex) / 2;
// Below step sorts the left side of the array
doMergeSort(lowerIndex, middle);
// Below step sorts the right side of the array
doMergeSort(middle + 1, higherIndex);
// Now merge both sides
mergeParts(lowerIndex, middle, higherIndex);
}
}
private void mergeParts(int lowerIndex, int middle, int higherIndex) {
//Compare elements at First and Second,
//and move smaller element at Merged array
for (int i = lowerIndex; i <= higherIndex; i++) {
tempMergArr[i] = array[i];
}
int i = lowerIndex;
int j = middle + 1;
int k = lowerIndex;
while (i <= middle && j <= higherIndex) {
if (tempMergArr[i] <= tempMergArr[j]) {
array[k] = tempMergArr[i];
i++;
} else {
array[k] = tempMergArr[j];
j++;
}
k++;
}
while (i <= middle) {
array[k] = tempMergArr[i];
k++;
i++;
}
}
}
=============================
Expected Out put
Random Numbers
19 95 97 32 86 36 48 34 46 71
Input Array
19 95 97 32 86 36 48 34 46 71
After Merge sort from low to high
19 32 34 36 46 48 71 86 95 97.
In this chapter we will learn about arrays as a way to work with sequences of elements of the same type. We will explain what arrays are, how we declare, create, instantiate and use them. We will examine one-dimensional and multidimensional arrays. We will learn different ways to iterate through the array, read from the standard input and write to the standard output. We will give many example exercises, which can be solved using arrays and we will show how useful they really are.
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.
The purpose of this C++ programming project is to allow the student .pdfRahul04August
The purpose of this C++ programming project is to allow the student to perform parallel array
and multidimensional array processing. The logic for string and Cstring has already been
completed, so the assignment can be started before we actually cover string and Cstring in detail.
This program has the following three menu options:
Solution
/*
This program uses simple arrays, multidimensional arrays, cstrings, strings, and files.
It allows a payroll clerk to choose an option from a menu. The choices are:
A: List the Payroll Information by Employee Name
B: Search Payroll Information by Employee Name
X: Exit the Payroll Information Module
The following items for each employee are saved in the file p10.txt:
Employee ID (1000 - 9999)
Last Name (15 characters)
First Name (15 characters)
Rate (5.00 - 10.00)
Hours W1,W2,W3,W4 (0-60)
*/
#include // file processing
#include // cin and cout
#include // toupper
#include // setw
#include // cstring functions strlen, strcmp, strcpy stored in string.h
#include // string class
#define stricmp strcasecmp
#define strnicmp strncasecmp
using namespace std;
//Disable warning messages C4267 C4996.
//To see the warnings, comment out the following line.
//#pragma warning( disable : 4267 4996)
//Warning C4267: coversion from size_t to int, possible lost of data
//size_t is a data type defined in and is an unsigned integer.
//The function strlen returns a value of the type size_t, but in
//searchByName we assign the returned value to an int.
//We could also declare the variable as size_t instead of int.
// size_t stringLength;
//Warning C4996: strnicmp strcpy, stricmp was declared deprecated, means
//the compiler encountered a function that was marked with deprecated.
//The deprecated function may no longer be supported in a future release.
//Global Constants
//When using to declare arrays, must be defined with const modifier
const int ARRAY_SIZE = 20, HOURS_SIZE = 4, NAME_SIZE = 16;
//Declare arrays as global so we don\'t have to pass the arrays to each function.
//Normally we wouldn\'t declare variables that change values a global.
int employeeId[ARRAY_SIZE];
string firstName[ARRAY_SIZE];
char lastName[ARRAY_SIZE][NAME_SIZE];
double rate[ARRAY_SIZE];
int hours[ARRAY_SIZE][HOURS_SIZE];
int numberOfEmps; //count of how many employees were loaded into arrays
int sumHours[ARRAY_SIZE] = {0}; //initialize arrays to zero by providing a
double avgHours[ARRAY_SIZE] = {0}; //value for the first element in the array
//Function Prototypes
void loadArray( );
void sumAndComputeAvgHours( );
void listByName( );
void searchByName( );
void sortByName( );
void swapValues(int i, int minIndex);
void listEmployees( );
void listEmployeesHeadings( );
void listEmployeesDetails(int i);
void listEmployeesTotals( );
void displayContinuePrompt( );
//Program starts here
int main()
{
//Declare and initialize local main variables
char choice; //menu option
//Load the arrays with data
loadArray();
//Sum and compute the average hours
sumAndComputeAv.
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
Identify five muscles of the head area that have a name that is very .pdfarri2009av
Identify five muscles of the head area that have a name that is very similar to the name of the
skull bone or bony structure the muscle is located on or attached to.
Solution
(Muscle) (Bone or the bony structure)OrbicularisOrbital
surfaceZygomaticusZygomatic boneTemporalisTemporal BoneFrontalisFrontal
BoneNasalisNasal Bone.
Identify non-neoplastic conditions effecting pregnancy. Describe STI conditions common to
females and how they are distributed.
Solution
During pregnancy, there are several non-neoplastic conditions that effect pregnancy. Some of
them are dysfunctional cysts, lesions of an ovary, tumors in breast, lymphoma, cervical cancer,
myeloma. these conditions may be benign or myeloma. the treatment depends on the condition
and effects the pregnancy.
The STI conditions that are common in women are human papillomavirus(HPV), gonorrhea,
chlamydia, and genital herpes. The HPV is the most common in women and is the main cause of
cervical cancer. This condition is distributed through direct sexual contact. Gonorrhea is
distributed through unprotected oral, anal, or vaginal sex. people with numerous sexual partners
or who does not have safe sex are at greater risk of the disease. Chlamydia is passed through
unprotected sex or oral sex. Genital herpes gets transmitted through the mucous membrane
which can be lining of mouth, nose, and genitals. Once the virus enters the body they start
multiplying and incorporate themselves into your body cells..
From a mixed field, what is easier to facilitate through artificial s.pdfarri2009av
From a mixed field, what is easier to facilitate through artificial selection? Monoculture of
(dominant) round peas. Monoculture of (recessive) wrinkled peas. Both scenarios have equal
difficulty
Solution
Ans. C both scenario have equal difficulty.
Farmers and breeders allowed only the plants and animals with desirable characteristics to
reproduce, causing the evolution of farm stock. This process is called artificial selection. So to
perform this particular selection both kind of selection will face the same difficulty..
Explain how you would tell if something that looks like a leaf (flat.pdfarri2009av
Explain how you would tell if something that looks like a leaf (flat and green plant part) is infact,
developmentally, a leaf.
Thanks!
Solution
A flat borad green plant part can be called as leaf if
1: it is present laterally to the shoot apex.
2: it is developed as determinate outgrowth of the shoot apex.
3: An axillary bud is located in the axil of the green flat plant part.
4: Successive leaves follow a particular pattern of arrangement i.e. they are developed in
phyllotaxy.
5: Two most common visible structural parts of leaves as lamina and petiole. The lamina is the
broad flat part of the leaf that has veins..
Explain what a standard deviation value measures in quantitative dat.pdfarri2009av
Explain what a standard deviation value measures in quantitative data?Explain what a standard
deviation value measures in quantitative data?
Solution
Standard deviation is a measure of spread or variability of data. It is the expected difference
between a data point and the mean value of that data..
Einstein, in his famous photoelectric effect experiment demonstr.pdfarri2009av
Einstein, in his famous \"photoelectric effect experiment\" demonstrated that light can behave as
a waves. In 1924, Louis de Broglie suggested that just as light exhibits wave properties. All
microscopic material particles such as electrons, protons, atoms, molecules etc. have also dual
character. They behave as a particle as well as wave. This means that an electron which has been
regarded as a particle also behaves like a wave. The particle nature of an electron is explained by
classical mechanics. For example, electron has a mass ~ 9.1 X10*-31 kg. But the classical
mechanics fails to explain the wave nature of electron. The wave nature of electron is explained
by quantum mechanics. Can you give more examples of wave behavior of electron in order to
illustrate dual character of electron?
Solution
the wave nature of electron was explained by the experiments like Thompsons Experiment, in
which G.P.Thompson allowed electron beam pass through a thin foil of gold and got caught on
the photographic plate on whic he found the Diffraction pattern of electron beam just like x-ray,
thus this experiment allows wave nature of electron..
Contrast autochthonous and allochthonous food webs. Which type would.pdfarri2009av
Contrast autochthonous and allochthonous food webs. Which type would be expected to
dominate in a clear lake?
Solution
Contrast autochthonous and allochthonous food webs:
The allochthonous food webs are associated with high inputs of organic matter to obtain carbon
from surface catchment or ground water catchment where amount o flight is lower & low
primary production. This food webs forms among heterotrophic ecosystems mainly in dystrophic
lakes
Autochthonous food webs are mainly associate with production of organic carbon from
photosynthesis inside the clear lake, in which higher carbon generated mainly in eutrophic lakes
where high light incidence across the clear lake.
Based on the below and using the 12 categories of threats identify 3 .pdfarri2009av
Based on the below and using the 12 categories of threats identify 3 examples you can find
online, in the media for each of the threats listed on the right column. You can use news articles
to justify the threats. Use the most current news article you can find. Add the reference link for
each article and place in APA format. Prepare a memo to your CEO with your finding. On the
same memo research current vendors that provide phishing email tools to train your employees
and provide a recommendation to the CEO about which to buy. Compare at least 2 vendors and
identify the following. Features Cost Add the Phishing Quiz Exercise discussed in class to the
bottom of your memo pages. Take the quiz and answer the below Identify which questions you
got wrong from the quiz Provide a brief explanation on why you got it wrong. What did you
learn about phishing emails and what would you recommend in order to avoid falling for a
phishing email?
Solution
1) Threat to intellectual property: Hacking , After conducting a forensic review of the drives,
Bailey(CEO of IT company) learned that intruders had been lurking on two of his company’s
servers for almost a year. These hackers, who were traced to a university in Beijing, had entered
the company’s extranet through an unpatched vulnerability in the Solaris operating system. As
far as Bailey could tell, they hadn’t accessed any classified information. But they were able to
view mountains of intellectual property, including design information and product specifications
related to transportation and communications systems, along with information belonging to the
company’s customers and partners.
Activist hackers, or hacktivists, can also be a danger to companies. For example, early last year
members of Anonymous, the hacker collective, copied and publicly released sensitive files of
H.B. Gary Federal, a security company.
Cpoyrights deviation or piracy :
Intellectual property theft involves robbing people or companies of their ideas, inventions, and
creative expressions—known as “intellectual property”—which can include everything from
trade secrets and proprietary products and parts to movies, music, and software.
It is a growing threat—especially with the rise of digital technologies and Internet file sharing
networks. And much of the theft takes place overseas, where laws are often lax and enforcement
is more difficult. All told, intellectual property theft costs U.S. businesses billions of dollars a
year and robs the nation of jobs and tax revenues.
Preventing intellectual property theft is a priority of the FBI’s criminal investigative program. It
specifically focuses on the theft of trade secrets and infringements on products that can impact
consumers’ health and safety, such as counterfeit aircraft, car, and electronic parts. Key to the
program’s success is linking the considerable resources and efforts of the private sector with law
enforcement partners on local, state, federal, and international levels.
.
Blair, R. B. 1996. Land use and avian species diversity along an urb.pdfarri2009av
Blair, R. B. 1996. Land use and avian species diversity along an urban gradient. Ecological
Applications 6:506–519.
http://academic.uprm.edu/~jchinea/cursos/comunidades/refs/blair1996.pdf
Questions 1. The author predicts that different bird species will respond differently to
urbanization. What are the three response groups the author expects to find and how is each
predicted to respond to urbanization? 2. Although not explicitly stated in the text, the author
compared bird densities among sites using analysis of variance (ANOVA). Describe the
experimental design of the ANOVA: what were the response and predictor variables, and
treatment levels? Explain how the author used replication in both space and time. 3. The author
presents data on bird densities within sites in both Table 1 and Figure 3. Which presentation do
you find more interpretable and why? What information is common to both, what is unique to
either one or the other? Could you limit the redundancy of these two presentations by combining
them into one table or figure? If so, which would you choose and how would you lay it out? 4.
The golf course had the highest bird species richness, density, and biomass (when Rock Doves
were excluded from the analysis), and the second highest diversity (Figure 4). Summarize the
author’s explanation for this result. 5. Based on the study results, briefly argue the pros and cons
of golf courses as they relate to bird diversity and abundance.
Solution
1: The author predicts three groups of birds which he called as urban exploiters, urban avoiders
and suburban adaptable. The urban exploiters are expected to get adapted to the changes and to
reach their highest densities at the developed sites. The urban avoiders are expected to respond in
a sensitive way to the anthropogenic changes in their habitat and are expected to have their
maximum densities at the natural sites only. The suburban adaptables are expected to exploit
some additional available resources leading to their moderate development..
An attack in which an authentic-looking e-mail or website entices a .pdfarri2009av
An attack in which an authentic-looking e-mail or website entices a user to enter his or her
username, password, or other sensitive information is called ________. (Select the most specific
answer.)
A- a spyware attack
B-identity theft
C- phishing
D- social engineering
A- a spyware attack
B-identity theft
C- phishing
D- social engineering
Solution
C - phishing ,
is the method that attackers use to get login credentials and other sensitive information by
sending emails that resemble original login authentication procedure..
Consider a relation T with six attributes ABCDEF where AB is a compo.pdfarri2009av
Consider a relation T with six attributes ABCDEF where AB is a composite primary key for T.
Assume T has the following functional dependencies:
AB -> CDEF
A -> CEF
F -> E
In what normal form is relation T? Explain why?
Is it possible to decompose T into a number of relations in order to achieve a higher normal
form? Explain how.
Solution
T(A,B,C,D,E,F)
AB -> CDEF
A -> CEF
F -> E
The relation T is in First Normal Form assuming all attribute values are atomic. But it is not in
second normal form because attribute E is functionally dependent on the attribute F.But F is not
part of key attributes so relation is not in second normal form. attribute.A relation is in second
normal form if all non key attributes are fully functionally deprndent on attribute keys.
Yes , it is possisble to decompose the relation into number of relations in order to achieve the
higher normalization. Following are the tables into which we can decompose the relation T
Table1(A,C,E,F)
Table2 (A,B,D)
Table3 (F,E)
underlined attributes are primary keys.
A vague appointment Four people make an appointment to meet each ot.pdfarri2009av
A vague appointment: Four people make an appointment to meet each other at the café in town.
However, this particular town has four cafés. What is the probability that none of them meet?
Solution
There are 4^4 = 256 ways to go to the 4 cafes.
Meanwhile, there are 4! = 24 ways to permute them, so that no 2 people are on the same cafe.
Thus,
P(none meets) = 24/256 = 0.09375 [answer].
Assume real numbers R for now. Consider relation on R, x y iff x .pdfarri2009av
Assume real numbers R for now. Consider relation on R, x y iff x y Z.
(a) Is it an equivalence relation?
(b) Compute [1/2]
(c) Classify all elements of R/ . That is state: “Every element of R/ is of the form ...” – include
all the details, so that you don’t count any element twice.
(d) Bonus question: (you don’t need to answer): Is there a geometric way to think about R/ ?
Solution
a)
x-x=0 is in Z for all real numbers x
SO R is reflexive
IF, x-y is in Z then y-x is also in Z
So, R is symmetrix
IF, x-y and y-z are in Z
then x-y+y-z=x-z is also in Z
Hence, R is transitive
Hence, R is an equivalence relation
b)
[1/2]={n+1/2: n is in Z}
c)
Elements of R/~ are of the form:
a+R, where, a is a real number in (0,1]
We need only consider real numbers outside this interval because all other real numbers will
differ by an integer from one of the numbers in this interval..
An enzyme aggase requires 16 units of activity for wild type functio.pdfarri2009av
An enzyme aggase requires >16 units of activity for wild type function. Two alleles of aggase
have been identified. Wild type allele A_1 produces 12 units of enzyme and mutant allele A_2
produces 5 units of enzyme. Which allele is dominant and which is haploinsufficient? Explain
your reasoning.
Solution
Haploinsufficiency is a potential mechanism in which a diploid species can express a single
functional copy of that gene and the other one copy of gene function will be lost due to mutation
finally trigger loss-of-function mutation so that it is not possible to generate a complete wild-type
phenotype with one functional copy of allele. Therefore, in the above case, enzyme aggase need
>16 units of enzyme, in which only A1 generates 12 units & the remaining A2 produced 5 units
together 17 units to produce a complete wild-type phenotype. Here, haplosuffciency can occur
with a single functional copy of gene, A1 & A2 alleles \"individually\" both are does not produce
enough product to meet >16 units of enzyme to display the wild type\'s so that both are
considered as haplosufficient
Dominance can be observed only in allele A1 because it can mask the allelic recessive locus due
to heterozygosity & Mendelian inheritance in which A1 is responsible for the phenotype
Other reason:
1. Dominant gain of function in which protein expressed from the mutant gene is constitutively
active due to base substitutions finally protein expression is further downregulated because of
increase in expression of enzyme proteins.
2. Loss of Function/ Haploinsufficiency: It is also due to loss of heterozygosity thereby by loss
of gene function with haploinsufficiency. Finally, resultant organism possesses only one
functional gene copy with truncated protein..
17. Of these, which represents a heterozygote a. aa b. Ab c. .pdfarri2009av
17. Of these, which represents a heterozygote?
a. aa
b. Ab
c. AA
d. both a. and c.
18. Active transport across a cell membrane is
a. moving a molecule from lower to higher concentcation
b. moving a molecule from higher to lower concentration
c. moving a from outside the cell to inside the cell
d. by which cells tet rid of waste products
19. All of the following are true about the cell membrane except _____.
a. They are mainly composed of lipids and
b. All polar molecules pass freely, directly through the membrane
c. They are selectively permeable.
d. They have a lipid bilayer
20. Which cellular process produces the most ATP?
a. Photosynthesis
b. aerobic respiration
c. meiosis
d. anaerobic respiration
21. A plant can regulate the amount of water in its cells by
a. moving to a more aqueous environment
b. increasing the amount of solute in the cytoplasm
c. reducing its rate of respiration
d. drinking a tall glass of refreshing rain water
22. Eye color is represented by the alleles AaBBCc. This is an example of ______.
a-complete dominant inheritance
b. heterozygote advantage
c-sex-linked inheritance
d-polygenic inheritance
23. During amniocentesis the baby\'s cells are obtained from the ____.
a. fluid around the embryo
b. placenta
c. uterine wall
d. developing embryo
Solution
17. Heterozygous is represented by
b. Ab
18. Active transport across cell membrane is
a. moving molecule from lower to higher concentration.
19. All are true about cell membrane except
a. They are mainly composed of lipids.
20. Which cellular process produces most ATP?
b. Aerobic respiration
21. A plant can regulate the amount of water in its cells by
b. increasing the amount of solute in the cytoplasm.
22. Eye colour represented by the alleles AaBBCc is an example of
d. Polygenic inheritance
23. During amniocentesis the baby\'s cells are obtained from the
a. fluid around the the embryo.
1. Match the decription listed with the corresponding structureA. .pdfarri2009av
1. Match the decription listed with the corresponding structure
A. corpus callosum
B. hypothalamus
C. mammillary bodies
D. pineal body (gland)
1. controls hormone secretion from the pituitary gland
2. fiber tract that connects the left cerebral hemisphere to the right cerebral hemisphere
3. involved in suckling reflex and chewing
4. primary relay center for sensory information coming into the brain
5. secretes the hormone melatonin from its precursor molecule serotonin
Solution
Ans). A. corpus callosum - 2. fiber tract that connects the left cerebral hemisphere to the right
cerebral hemisphere
B. hypothalamus - 1. controls hormone secretion from the pituitary gland
C. mammillary bodies - 4. primary relay center for sensory information coming into the brain
D. pineal body (gland) - 5. secretes the hormone melatonin from its precursor molecule serotonin.
1.) What are some factors that should be taken into account when est.pdfarri2009av
1.) What are some factors that should be taken into account when establishing criteria for
recruitment and selection of employees in a global corporation?
2.) What are the most important factors that should be taken into account when establishing
criteria for recruitment and selection of employees for international assignments and why?
Solution
1. the people who are representing in global corportaion should have good skills and positive at
the work and even after the work also. they should be in a position to mould them selves
according to the need and requirement. they should have awareness about different culture,
tradition and respect the people who follows it. they need to konw differences between the
company norms and rules in host country and parent country also. some times the legal aspects
and other aspects related to work will be different. the person who wants to work for different
global companies should know the variations and differences also.
the major part is cultural barriers, the new comers should adapt or ready to adapt new culture and
practice it. they should know the traditions and values followed by the people and respect them.
even they need to consider the race, gender, and community aspects also.
2. the first factor is the strength in the group, how many people requires to complete the
assignment.
second factor is how the group should form, who are the different kinds and specilists represents
in the group. do they ready to work in teams as well as individuals with out having any ego or
personal problems, should assess. the seniority and skill expertise of the people should be match,
otherwise it creates new problems. the traditions and cultures which they follows and are they
open to adapt and follow the new culture should be consider.
there are two kinds of problems in this type of group, one is related to work. it can be resolved
and every one can note and complete their given tasks. they can perform their roles correctly and
achieve the targets. the second problem is relates to out of work. it may relates to personal egos,
differentiations in the payments among the members, respect the others and their cultures and so
on. these kind of problems are vary difficult to solve and the team representatives should not
create these sort of problems..
Write a program that asks the user for the name of a file. The progr.pdfarri2009av
Write a class named testscores. The class constructor should accept an array of rest scores as its
argument., The class should have a member function that returns the average of the test scores. If
any test score in the array is negative or greater than 100, the class should throw an exception.
Demonstrate the class in a program.
Solution
#include
#include
using namespace std;
class TestScores{
private:
float total = 0; //intiialising total marks
int length; //declaring variable for the size of scores array
bool invalid = false;
public:
TestScores(vector scores){
length = scores.size(); //length of vector of scores
for(int i = 0; i100){
cout<<\"Error! Invalid test score!\"; //error for invalid input
total = 0;
invalid = true;
}
else{
total+=scores[i];
}
}
}
float average(){
if(invalid==true){
return 0;
}
return this->total/this->length;
}
};
int main(){
vector scores;
scores.push_back(20);
scores.push_back(25);
scores.push_back(30);
scores.push_back(35);
scores.push_back(40);
scores.push_back(455);
scores.push_back(50);
TestScores testScores = TestScores(scores);
cout<<\"Average: \"<.
Wings of bats area. Plesiomorphic (ancestral) feature for mammals.pdfarri2009av
Why is an engine with port injection vs. carburetion more likely to have fuel dilute the
lubricating oil? Why did some aircraft engines in World War II have water injection? What is
the physical phenomenon? What is the difference between multipoint port injection systems and
a common rail system?
Solution
11.
Combustion in SI Engine Mixture preparation: - Carburation (no longer used in North
American markets) - Port injection - fuel is sprayed into the air stream just before the inlet valve.
Direct injection - fuel is injected into the cylinder (DISI).
Ignition: spark plug Flame kernel initiation and propagation model 101
Most car engines use port injection or a carburetor. Diesel engines use direct fuel injection -- the
diesel fuel is injected directly into the cylinder. The injector on a diesel engine is its most
complex component. The injector has to be able to withstand the temperature and pressure inside
the cylinder and still deliver the fuel in a fine mist. Some diesel engines contain a glow plug that
heats the combustion chambers and raises the air temperature when the engine is cold so that the
engine can start.
12.
cause, Water injection (engine) In internal combustion engines, water injection, also known as
anti-detonant injection (ADI), can spray waterinto the incoming air or fuel-air mixture, or
directly into the cylinder, in order to cool certain parts of the induction system where \"hot
points\" could produce premature ignition.
War Emergency Power (WEP) is an American term for a throttle setting on some World War II
military aircraft engines. For use in emergency situations, it produced more than 100% of the
engine\'s normal rated power for a limited amount of time, often about five minutes.
Maximum normal power would be limited by a mechanical stop, for instance a wire across the
throttle lever slot, but a more forceful push would break the wire, allowing extra power.
13.
Assuming you are aware of the basic functioning of an engine, CRDi and MPFi are both
electronically operated fuel supply systems for diesel and petrol engines respectively.
CRDi - common rail diesel ignition
MPFI - multi-point fuel injection
CRDi consists of a common rail which holds fuel at a very high pressure (~1400 bar) and injects
diesel directly into the cylinder during the transition from compression stroke to power stroke.
Due to the high pressure injection, the fuel burns efficiently and hence power and fuel efficiency
figures are improved.
MPFI on the other hand is simply multi point fuel injection. Here, the carburetor is replaced with
a MAP sensor and injection points in the intake manifold. the MAP sensor relays to the ECU as
to the amount of air entering the manifold and accordingly the quantity of fuel to be injected into
the cylinder heads is ascertained (to maintain the best possible air-fuel mixture as per the
requirements).
the main purpose of an injection system is to supply properly metered fuel to the combustion
chamber via intake valve.
Why do financial assets show up as component of household wealth.pdfarri2009av
Which of the Karnaugh maps below represents the expression, X = AC + BC + B? The greatest
single-digit value in the octal number system equals 1 8 9 7 Which of the following is a
correct form of Boolean addition? A synchronous inputs are best described as having full
control over the FF, regardless of the input or clock states being to the clock, but not to the
inputs being tied to the inputs, but independent of the clock having little or no control over the
FF, except during the active clock input Which statement below best describes the function of a
decoder? Decoders are used to prevent improper operation of digital systems. A decoder will
convert a binary number into a specific output representing a particular character or digit.
Decoders are special ICs that are used to make it possible for one brand of computer to talk to
another. A decoder will convert a decimal number into the proper binary equivalent.
Solution
37)
None of the fig represents AC+BC+B
38)
The greatest single digit value in octal is 7.
39)
0+1=1 is correct
41) decoder expression is option B.
How to Make a Field invisible in Odoo 17Celine George
It is possible to hide or invisible some fields in odoo. Commonly using “invisible” attribute in the field definition to invisible the fields. This slide will show how to make a field invisible in odoo 17.
Synthetic Fiber Construction in lab .pptxPavel ( NSTU)
Synthetic fiber production is a fascinating and complex field that blends chemistry, engineering, and environmental science. By understanding these aspects, students can gain a comprehensive view of synthetic fiber production, its impact on society and the environment, and the potential for future innovations. Synthetic fibers play a crucial role in modern society, impacting various aspects of daily life, industry, and the environment. ynthetic fibers are integral to modern life, offering a range of benefits from cost-effectiveness and versatility to innovative applications and performance characteristics. While they pose environmental challenges, ongoing research and development aim to create more sustainable and eco-friendly alternatives. Understanding the importance of synthetic fibers helps in appreciating their role in the economy, industry, and daily life, while also emphasizing the need for sustainable practices and innovation.
Acetabularia Information For Class 9 .docxvaibhavrinwa19
Acetabularia acetabulum is a single-celled green alga that in its vegetative state is morphologically differentiated into a basal rhizoid and an axially elongated stalk, which bears whorls of branching hairs. The single diploid nucleus resides in the rhizoid.
Palestine last event orientationfvgnh .pptxRaedMohamed3
An EFL lesson about the current events in Palestine. It is intended to be for intermediate students who wish to increase their listening skills through a short lesson in power point.
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.
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.
A Strategic Approach: GenAI in EducationPeter Windle
Artificial Intelligence (AI) technologies such as Generative AI, Image Generators and Large Language Models have had a dramatic impact on teaching, learning and assessment over the past 18 months. The most immediate threat AI posed was to Academic Integrity with Higher Education Institutes (HEIs) focusing their efforts on combating the use of GenAI in assessment. Guidelines were developed for staff and students, policies put in place too. Innovative educators have forged paths in the use of Generative AI for teaching, learning and assessments leading to pockets of transformation springing up across HEIs, often with little or no top-down guidance, support or direction.
This Gasta posits a strategic approach to integrating AI into HEIs to prepare staff, students and the curriculum for an evolving world and workplace. We will highlight the advantages of working with these technologies beyond the realm of teaching, learning and assessment by considering prompt engineering skills, industry impact, curriculum changes, and the need for staff upskilling. In contrast, not engaging strategically with Generative AI poses risks, including falling behind peers, missed opportunities and failing to ensure our graduates remain employable. The rapid evolution of AI technologies necessitates a proactive and strategic approach if we are to remain relevant.
Chapter 3 - Islamic Banking Products and Services.pptx
Write a program that obtains the execution time of selection sort, bu.pdf
1. Write a program that obtains the execution time of selection sort, bubble sort, merge sort, quick
sort, heap sort, and radix sort for input size 50,000, 100,000, 150,000, 200,000, 250,000, and
300,000. Your program should create data randomly and print a table as shown in the following
sample run: long startTime System. nanoTime(); perform the task; long endTime = System.
nanoTime(); long executionTime = endTime - startTime;
Solution
Hello there,
please find attached code and it's output.I have printed intermediate SYSOUT. You can remove
those. It takes a bit longer time so wait for the final output! :-)
====O/P====
|Array |Selection |Insertion |Bubble |Merge |Quick |Radix |
|Size |Sort |Sort |Sort |Sort |Sort |Sort |
--------------------------------------------------------------------------------------------------------------------
--------------------------------
|50000 |855 |796 |2821 |16 |18 |21 |
|100000 |3482 |3243 |11422 |16 |0 |16 |
|150000 |7897 |7569 |26628 |25 |10 |7 |
|200000 |13683 |13360 |46701 |33 |10 |0 |
=====CODE=====
import java.util.Arrays;
import java.util.Random;
public class SortingAlgoPerformanceMeasurement {
static int[] size = { 50000, 100000, 150000, 200000 };
static String format = "|%1$-20s|%2$-20s|%3$-20s|%4$-20s|%5$-20s|%6$-20s|%7$-20s| ";
public static void main(String args[]) {
int max = 5000;
long startTime, endTime, executionTime;
long[][] time = new long[size.length][6];
Random generator = new Random();
for (int i = 0; i < size.length; i++) { // For getting size of different
int indexForAlgo = 0;
// array to be created
int[] array = new int[size[i]];
2. int[] unSortedArray = new int[size[i]];
for (int j = 0; j < size[i]; j++) { // For creating that many random
// numbers.
array[j] = generator.nextInt(max); // Prepare an array for all
// size
}
System.out.println("Unsorted array of length: " + array.length + " ");
System.out.println(Arrays.toString(array));
System.arraycopy(array, 0, unSortedArray, 0, size[i]); // Retaining
// the copy
// of
// unsorted
// array
startTime = System.currentTimeMillis();
selectionSort(array);
endTime = System.currentTimeMillis();
executionTime = endTime - startTime;
time[i][indexForAlgo] = executionTime;
indexForAlgo++;
System.out.println("O/P:selectionSort");
System.out.println(Arrays.toString(array));
System.arraycopy(unSortedArray, 0, array, 0, size[i]); // Again
// make
// it
// unsorted
//if (array.length != 100000 && array.length != 200000) {
startTime = System.currentTimeMillis();
insertionSort(array);
endTime = System.currentTimeMillis();
executionTime = endTime - startTime;
time[i][indexForAlgo] = executionTime;
System.out.println("O/P:insertionSort");
System.out.println(Arrays.toString(array));
System.arraycopy(unSortedArray, 0, array, 0, size[i]);
//}
indexForAlgo++;
5. int temp;
for (int i = 1; i < arr.length; i++) {
for (int j = i; j > 0; j--) {
if (arr[j] < arr[j - 1]) {
temp = arr[j];
arr[j] = arr[j - 1];
arr[j - 1] = temp;
}
}
}
}
/**
* Implements Bubble Sort.
*
* @param arr
*/
public static void bubbleSort(int[] arr) {
int n = arr.length;
int temp = 0;
for (int i = 0; i < n; i++) {
for (int j = 1; j < (n - i); j++) {
if (arr[j - 1] > arr[j]) {
// swap the elements!
temp = arr[j - 1];
arr[j - 1] = arr[j];
arr[j] = temp;
}
}
}
}
/**
* Implements Merge Sort.
*
* @param arr
*/
public static void mergeSort(int[] arr) {
6. if (arr.length <= 1) {
return;
}
// Split the array in half
int[] first = new int[arr.length / 2];
int[] second = new int[arr.length - first.length];
System.arraycopy(arr, 0, first, 0, first.length);
System.arraycopy(arr, first.length, second, 0, second.length);
// Sort each half
mergeSort(first);
mergeSort(second);
// Merge the halves together, overwriting the original array
merge(first, second, arr);
}
private static void merge(int[] first, int[] second, int[] result) {
// Merge both halves into the result array
// Next element to consider in the first array
int iFirst = 0;
// Next element to consider in the second array
int iSecond = 0;
// Next open position in the result
int j = 0;
// As long as neither iFirst nor iSecond is past the end, move the
// smaller element into the result.
while (iFirst < first.length && iSecond < second.length) {
if (first[iFirst] < second[iSecond]) {
result[j] = first[iFirst];
iFirst++;
} else {
result[j] = second[iSecond];
iSecond++;
}
j++;
}
// copy what's left
System.arraycopy(first, iFirst, result, j, first.length - iFirst);
7. System.arraycopy(second, iSecond, result, j, second.length - iSecond);
}
/**
* Implements Quick Sort.
*
* @param arr
*/
public static void quickSort(int[] arr, int low, int high) {
if (arr == null | arr.length == 0)
return;
if (low >= high)
return;
// pick the pivot
int middle = low + (high - low) / 2;
int pivot = arr[middle];
// make left < pivot and right > pivot
int i = low, j = high;
while (i <= j) {
while (arr[i] < pivot) {
i++;
}
while (arr[j] > pivot) {
j--;
}
if (i <= j) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
i++;
j--;
}
}
// recursively sort two sub parts
if (low < j)
quickSort(arr, low, j);
if (high > i)
8. quickSort(arr, i, high);
}
private static int getMax(int arr[], int n) {
int mx = arr[0];
for (int i = 1; i < n; i++)
if (arr[i] > mx)
mx = arr[i];
return mx;
}
// A function to do counting sort of arr[] according to
// the digit represented by exp.
private static void countSort(int arr[], int n, int exp) {
int output[] = new int[n]; // output array
int i;
int count[] = new int[10];
Arrays.fill(count, 0);
// Store count of occurrences in count[]
for (i = 0; i < n; i++)
count[(arr[i] / exp) % 10]++;
// Change count[i] so that count[i] now contains
// actual position of this digit in output[]
for (i = 1; i < 10; i++)
count[i] += count[i - 1];
// Build the output array
for (i = n - 1; i >= 0; i--) {
output[count[(arr[i] / exp) % 10] - 1] = arr[i];
count[(arr[i] / exp) % 10]--;
}
// Copy the output array to arr[], so that arr[] now
// contains sorted numbers according to curent digit
for (i = 0; i < n; i++)
arr[i] = output[i];
}
/**
* Implements Radix Sort.
*
9. * @param arr
*/
static void radixSort(int arr[]) {
// Find the maximum number to know number of digits
int m = getMax(arr, arr.length);
// Do counting sort for every digit. Note that instead
// of passing digit number, exp is passed. exp is 10^i
// where i is current digit number
for (int exp = 1; m / exp > 0; exp *= 10)
countSort(arr, arr.length, exp);
}
public static void printInTabularFormat(long[][] time) {
System.out.println(" ");
System.out.format(format, "Array", "Selection", "Insertion", "Bubble", "Merge",
"Quick", "Radix");
System.out.format(format, "Size", "Sort", "Sort", "Sort", "Sort", "Sort", "Sort");
System.out
.println("---------------------------------------------------------------------------------------------
-------------------------------------------------------");
int sizeIndex = 0;
for (long[] arr : time) {
System.out.format(format, size[sizeIndex], arr[0], arr[1], arr[2], arr[3], arr[4], arr[5]);
sizeIndex++;
}
}
}
===
Let me know if you have any doubts.
Thanks.