In: Statistics and Probability
Let’s assume there is 1 fake coin out of 1000 coins. ( P[Coin=fake] = 0.001 ) The probability of showing head for fake coin is 0.9 (P[Head | Coin=fake] = 0.9). For normal coin, the probability of showing head is 0.5 (P[Head | Coin=normal] = 0.5).
i. Bayes theorem, If you have a coin, and toss it one time. You got a head. What is the probability that this coin is fake?
ii. If you toss a coin 10 times, you got 8 head out of ten tosses. What is the probability of this event if the coin is fair (P[X=8|Coin=normal], X is a random variable representing number of head out of ten tosses)? What is the probability of this event if the coin is fake( P[X=8|Coin=fake])?
iii. If you toss a coin 10 times, you got 8 head out of ten tosses. What is the probability that this coin is fake?
iv. Calculate the probability that you will get a head after you get 8 head out of ten tosses? What is the probability if you are Frequentist? What is it if you are Bayesian?
In: Statistics and Probability
GRADED PROBLEM SET #5
Answer each of the following questions completely. There are a total of 20 points possible in the assignment.
In: Math
Implement the SimpleQueue interface with the MyQueue class. You can use either a linked list or a dynamic array to implement the data structure.
A queue is a specialised form of list in which you can only get and remove the first element in the queue.
The class should be able to work with the following code:
SimpleQueue queue = new MyQueue();
NB: You cannot import anything from the standard library for this task. The data structure must be of your own creation, not a modified form of a pre-existing class.
-----------------------------------------------------------
public interface SimpleQueue {
/**
* Returns true if the queue is empty, else
false.
*
* @return whether the queue is empty
*/
public boolean isEmpty();
/**
* Removes all elements from the queue.
*/
public void clear();
/**
* Returns the first element, null if empty.
*
* @return the first element
*/
public T peek();
/**
* Returns and removes the first element, null if
empty.
*
* @return the first element
*/
public T dequeue();
/**
* Appends the element to the end of the queue. Does
nothing if the element is null.
*
* @param elem the element to be
added
*/
public void enqueue(T elem);
/**
* Returns the size of the queue
*
* @return the size of the queue
*/
public int size();
/**
* Returns true if the queue contains the given
element.
*
* @return whether the element is
present
*/
public boolean contains(T elem);
}
In: Computer Science
In this Java program you will implement your own doubly linked
lists.
Implement the following operations that Java7 LinkedLists have.
1. public DList()
This creates the empty list
2. public void addFirst(String element)
adds the element to the front of the list
3. public void addLast(String element)
adds the element to the end of the list
4. public String getFirst()
5. public String getLast()
6. public String removeLast()
removes & returns the last element of the list.
7. public String removeFirst()
removes & returns the front element of the list.
8. public String get(int index)
Returns the value at “position” index. IndexOutOfBoundsException
should be
thrown if the index is non-existent.
9. public String set(int index, String value)
changes the value at “position” index and returns the old value.
IndexOutOfBoundsException should be thrown if the index is
non-existent.
10. public int indexOf(Object obj)
Returns the index of obj if it is in the list and -1 otherwise.
11. public int size()
12.public boolean contains(Object obj)
Returns true if obj appears in the list and false otherwise.
13. public Iterator iterator()
Returns an iterator over the list. This should be a non static
inner class.
In: Computer Science
IN JAVA:
Repeat Exercise 28, but add the methods to the LinkedStack class.
Add the following methods to the LinkedStacked class, and create a test driver for each to show that they work correctly. In order to practice your array related coding skills, code each of these methods by accessing the internal variables of the LinkedStacked, not by calling the previously defined public methods of the class.
- String toString()—creates and returns a string that correctly represents the current stack. Such a method could prove useful for testing and debugging the class and for testing and debugging applications that use the class. Assume each stacked element already provided its own reasonable toString method.
- intsize()—returnsacountofhowmanyitemsarecurrentlyonthestack.Do not add any instance variables to the LinkStacked class in order to implement this method.
- void popSome(int count)—removes the top count elements from the stack; throws StackUnderflowException if there are less than count elements on the stack .
- booleanswapStart()—if there are less than two elements on the stack returns false; otherwise it reverses the order of the top two elements on the stack and returns true.
- T poptop( )—the “classic” pop operation, if the stack is empty it throws StackUnderflowException; otherwise it both removes and returns the top element of the stack.
package ch02.stacks;
import support.LLNode;
public class LinkedStack implements StackInterface
{
protected LLNode top; // reference to the top of this stack
public LinkedStack()
{
top = null;
}
public void push(T element)
// Places element at the top of this stack.
{
LLNode newNode = new LLNode(element);
newNode.setLink(top);
top = newNode;
}
public void pop()
// Throws StackUnderflowException if this stack is empty,
// otherwise removes top element from this stack.
{
if (isEmpty())
throw new StackUnderflowException("Pop attempted on an empty
stack.");
else
top = top.getLink();
}
public T top()
// Throws StackUnderflowException if this stack is empty,
// otherwise returns top element of this stack.
{
if (isEmpty())
throw new StackUnderflowException("Top attempted on an empty
stack.");
else
return top.getInfo();
}
public boolean isEmpty()
// Returns true if this stack is empty, otherwise returns
false.
{
return (top == null);
}
public boolean isFull()
// Returns false - a linked stack is never full
{
return false;
}
}
In: Computer Science
You are provided with a StackInterface to implement your stack, make sure to implement the data structure using java.util.ArrayList and naming your implementation ArrayListStack (make sure to use generics like you have been for the data structures so far). The provided StackTester assumes you name your implementation that way. Note that you have also been provided a PalindromeTester with the specific isPalindrome() method you are required to implement, following the approach above. The method should take whitespace, case-sensitivity, digits, and symbols into account (see documentation above method).
Additionally, provide your implementation for a CircularArrayQueue<E> based on the java.util.Queue interface, passing the JUnit tests provided for the following six methods.
Queue interface methods to implement:
| return type | method + description |
|---|---|
| boolean | add(E e) |
| Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions, returning true upon success and throwing an IllegalStateException if no space is currently available. | |
| E | element() |
| Retrieves, but does not remove, the head of this queue. | |
| boolean | offer(E e) |
| Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions. | |
| E | peek() |
| Retrieves, but does not remove, the head of this queue, or returns null if this queue is empty. | |
| E | poll() |
| Retrieves and removes the head of this queue, or returns null if this queue is empty. | |
| E | remove() |
|
Retrieves and removes the head of this queue. |
StackInterface.java
public interface StackInterface<E> {
/**
* Returns true if the stack is empty; otherwise, returns false
*
* @return true if empty, false otherwise
*/
public boolean empty();
/**
* Returns the object at the top of the stack without removing it
*
* @return reference (shallow copy) of object at top of stack
*/
public E peek();
/**
* Returns the object at the top of the stack and removes it
*
* @return reference of removed object from top of stack
*/
public E pop();
/**
* Pushes an item onto the top of the stack and returns the item pushed.
*
* @param obj object to push onto top of stack
* @return item that was pushed
*/
public E push(E obj);
}In: Computer Science
Show your work!
2. We did a poll of students in a BUS 232 class. The students were asked to name their favorite color. The result is shown in Table 2.
Table 2
Favorite Color
|
Red |
Blue |
Purple |
Total |
|
|
Female |
2 |
2 |
0 |
4 |
|
Male |
0 |
3 |
1 |
4 |
|
Total |
2 |
5 |
1 |
8 |
Number of E whoare∈favorof F
Hint: Conditional Probability Rule: P (F | E) =
Totalnumberof E
Suppose that one student is selected at random from the group. (4 points) What is the probability as a fraction in the simplest form that:
.
3. Suppose you roll a fair die three times. What would be the probability of getting ONE three times? Hint: Use the law of large number, which is the theoretical probability. Show the answers as a fraction in the simplest form. (2 point)
P (1 for the first roll, 1 for the second roll and 1 for the third roll roll) =
In: Statistics and Probability
Q1/
A batch of printed circuit cards is populated with semiconductor chips with 25% are defective cards. Five of these are selected randomly for function testing.The random variable X has a binmial distribution.
Find the probability that we get exactly one defective card
0.564
0.395
0.764
0.987
ــــــــــــــــــــــــــــــــــــــــــــــــــــــــــ
Q2/
A batch of printed circuit cards is populated with semiconductor chips with 45% are defective cards. Five of these are selected randomly for function testing . The random variable X has a binomial distribution
Find the probability that we get at least 5 defectives cards
|
0.00097
|
ــــــــــــــــــــــــــــــــــــــــــــــــــــــــــ
Q3/
A batch of printed circuit cards is populated with semiconductor chips with 35% are defective cards. Five of these are selected randomly for function testing. The random variable X has a binomial distribution.
Find the probability that we get less than 5 defective cards
|
0.199 |
||
|
0.564 |
||
|
0.342 |
||
|
0.994 |
ــــــــــــــــــــــــــــــــــــــــــــــــــــــــــ
Q4/
The mean number of typing errors in a document is 6 per page. The random variable X has a Poisson distribution. Find the probability that in a 3 pages chosen at random there are 10 mistakes
|
0.192 |
||
|
0.352 |
||
|
0.014 |
||
|
0.74 |
ــــــــــــــــــــــــــــــــــــــــــــــــــــــــــ
Q5/
The mean number of typing errors in a document is 4 per page. The random variable X has a Poisson distribution. Find the probability that in a 2 pages chosen at random there are more than one mistake
|
0.6765 |
||
|
0.9996 |
||
|
0.294 |
||
|
0.753 |
In: Statistics and Probability
7. Suppose the number of photons emitted by an atom during a one-minute time window can be modeled as a Poisson random variable with parameter ? = 2. Now, suppose you watch the atom for two minutes, and the number of emitted photons in each minute is an independent Poisson process. Calculate the probability that you see exactly one photon during the two minutes. (Hint: this is the probability that you see no photons in the first minute and one photon in the second minute, plus the probability that you see one photon in the first minute and no photons in the
second minute.) Similarly calculate the probability that you see exactly two photons during the two minutes.
Compare these probabilities to the probabilities that a Poisson random variable with parameter ? = 4 takes the value one, or two. Are they the same?
8. Sketch the PDF and CDF of a continuous random variable that is uniform on [0,2].
9. A line segment of length 1 is cut once at random. What is the probability that the longer piece is more than twice the length of the shorter piece?
10. An atom of Uranium-238 is unstable and will eventually decay (i.e., emit a particle and turn into a different element). Given an atom of Uranium-238, the time elapsed until it decays, in years, is modeled as an Exponential random variable with parameter ? = 0.000000000155. How many years must pass for there to be a 50% chance that the Uranium atom decays?
In: Statistics and Probability