In a random sample of male and female graduates of the New York School for the Arts between
the ages of 22-35 you know that:
• the probability a man is a ballet dancer is 0.245.
• the probability a woman is a musical performer is 0.365
• the probability a man is a musical performer, given that he\'s a ballet dancer is 0.250.
• the probability a woman is an actress is 0.550.
• the probability a woman is an actress, given that she\'s a musical performer is .785.
Compute the following probabilities:
A. P (man is a ballet dancer and a musical performer)
B. P (woman is an actress and a musical performer)
C. P (woman is an actress or a musical performer)
Solution
=0.245*(1-0.365)=0.155
b. P (woman is an actress and a musical performer)
=0.365*0.55=0.2
c. P (woman is an actress or a musical performer)
=P(woman is an actress)+P(musical performer)-P(actress or performer)
=0.55+0.365-0.785*0.365=0.628.
In Java code, implement the HeapSort algorithm. Your function must t.pdf
1. In Java code, implement the HeapSort algorithm. Your function must take an ArrayList as input
and output a sorted ArrayList. Allow the program to accept user input that becomes added to the
ArrayList, if no elements are added by the user, handle the exception.
Solution
Hi, Please find my program.
Please let me know in case of any issue.
import java.util.ArrayList;
import java.util.Scanner;
//Java program for implementation of Heap Sort
public class HeapSort
{
public void sort(ArrayList list)
{
int n = list.size();
// Build heap (relistangelistay)
for (int i = n / 2 - 1; i >= 0; i--)
heapify(list, 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 = list.get(0);
list.set(0, list.get(i));
list.set(i, temp);
// call max heapify on the reduced heap
heapify(list, i, 0);
}
}
// To heapify a subtree rooted with node i which is
// an index in list[]. n is size of heap
void heapify(ArrayList list, int n, int i)
{
int largest = i; // Initialize largest as root
2. 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 && list.get(l) > list.get(largest))
largest = l;
// If right child is larger than largest so far
if (r < n && list.get(r) > list.get(largest))
largest = r;
// If largest is not root
if (largest != i)
{
int swap = list.get(i);
list.set(i, list.get(largest));
list.set(largest, swap);
// Recursively heapify the affected sub-tree
heapify(list, n, largest);
}
}
/* A utility function to print list of size n */
static void printlist(ArrayList list)
{
int n = list.size();
for (int i=0; i list = new ArrayList();
System.out.print("How many elements you want to sort: ");
int n = sc.nextInt();
System.out.println("Enter "+n+" integers: ");
for(int i=0; i