Questions
Two resistors have resistances R(smaller) and R(larger), where R(smaller) < R(larger). When the resistors are connected...

Two resistors have resistances R(smaller) and R(larger), where R(smaller) < R(larger). When the resistors are connected in series to a 12.0-V battery, the current from the battery is 1.43 A. When the resistors are connected in parallel to the battery, the total current from the battery is 9.95 A. Determine the two resistances.

In: Physics

Use the DC Construction kit (the PHET simulator) to build a simple circuit to perform the...

Use the DC Construction kit (the PHET simulator) to build a simple circuit to perform the following task:
You are asked to use a single resistor and a 110 V DC battery for the purpose of boiling a liter of water (4,184 Joule/Kg*degree Celsius), with a staring temperature of 20 C, in exactly 4 minutes.

In: Electrical Engineering

write a c++ program to perform the following operations on stack of Integers (Array Implementation of...

write a c++ program to perform the following operations on stack of Integers (Array Implementation of Stack with maximum size MAX)

(i) Push an Element on to stack

(ii) Pop an Element from stack

(iii) Demonstrate how stack can be used to check Palindrome

(iv) Display the status of stack

(v) Exit

In: Computer Science

Urinalysis Questions *List two instances when a patient would have a routine urinalysis. List 4 diseases...

Urinalysis Questions
*List two instances when a patient would have a routine urinalysis. List 4 diseases that a routine examination could reveal.

*Why is a clean-catch midstream specimen ordered? What is the clean-catch technique?

*Explain how to collect a 24-hour urine specimen. What is the purpose for this test?

*Why might a first morning specimen be ordered?

In: Nursing

Use list/link list and write in C++ Food ordering system 1. Place Order 2. View the...

Use list/link list and write in C++

Food ordering system

1. Place Order
2. View the food details
3. Modify food details
4. Delete food details

5. Exit

Order should let the customer to enter the food code, flavor, weight(kg), unit price, qty, customer ID, name, address and contact number. It will also have an order id automatically assigned with a unique ID when new order is added. When view the food details, it should also calculate the unit price * qty as a bill amount. You should also be able to modify all the food details and delete food details.

In: Computer Science

List and briefly describe the five employer labour relations strategies towards unionization. List three reasons why...

List and briefly describe the five employer labour relations strategies towards unionization.

List three reasons why union density higher in Canada than in the United States? Do you think that union density in Canada will decline to the level in the United States?

Briefly Explain 400 words for each answer.

In: Operations Management

Question(on Python). There is a Python program what could solve the simple slide puzzles problem by...

Question(on Python). There is a Python program what could solve the simple slide puzzles problem by A* algorithm. Please fill in the body of the a_star() function.

In order to solve a specific problem, the a_star function needs to know the problem's start state, the desired goal state, and a function that expands a given node. To be precise, this function receives as its input the current state and the goal state and returns a list of pairs of the form (new_state, h'-score). There is exactly one such pair for each of the possible moves in the current state, with new_state being the state resulting from that move, paired with its h'-score. Note that this is not the f'-score but the h'-score, i.e., an (optimistic) estimate of the number of moves needed to reach the goal from the current state. The expand function does not know g’and therefore cannot compute f'; this has to be done by the a_star function.

The a_star function calls the expand function (in this context, slide_expand) in order to expand a node in the search tree, i.e., obtain the states that can be reached from the current one and their h’-scores. Again, please note that these are not f’-scores but h’-scores;
a_star needs to compute the h’-scores for sorting the list of open nodes. Also, note that slide_expand does not (and cannot) check whether it is creating a search cycle, i.e., whether it generates a state that is identical to one of its ancestors; this has to be done by a_star. The given slide_expand function uses the same scoring function as discussed in class – it simply counts the number of mismatched tiles (excluding the empty tile).

Please add code to the a_star function so that slide_solver can find an optimal solution for Example #1 and, in principle, for any slide puzzle. You are not allowed to modify any code outside of the a_star function. Hints: It is best to not use recursion in a_star but rather a loop that expands the next node, prevents any cycles in the search tree, sorts the list of open nodes by their scores, etc., until it finds a solution or determines that there is no solution. It is also a good idea to keep a list of ancestors for every node on the list, i.e., the list of states from the start that the algorithm went through in order to reach this node. When a goal state is reached, this list of ancestors for this node can be returned as the solution.

A_Star.py

import numpy as np

example_1_start = np.array([[2, 8, 3],
                           [1, 6, 4],
                           [7, 0, 5]])

example_1_goal = np.array([[1, 2, 3],
                           [8, 0, 4],
                           [7, 6, 5]])
 
example_2_start = np.array([[ 2,  6,  4,  8],
                            [ 5, 11,  3, 12],
                            [ 7,  0,  1, 15],
                            [10,  9, 13, 14]])

example_2_goal = np.array([[ 1,  2,  3,  4],
                           [ 5,  6,  7,  8],
                           [ 9, 10, 11, 12],
                           [13, 14, 15,  0]])

# For a given current state, move, and goal, compute the new state and its h'-score and return them as a pair. 
def make_node(state, row_from, col_from, row_to, col_to, goal):
    # Create the new state that results from playing the current move. 
    (height, width) = state.shape
    new_state = np.copy(state)
    new_state[row_to, col_to] = new_state[row_from, col_from]
    new_state[row_from, col_from] = 0
    
    # Count the mismatched numbers and use this value as the h'-score (estimated number of moves needed to reach the goal).
    mismatch_count = 0
    for i in range(height):
        for j in range(width):
            if new_state[i ,j] > 0 and new_state[i, j] != goal[i, j]:
                mismatch_count += 1
   
    return (new_state, mismatch_count)

# For given current state and goal state, create all states that can be reached from the current state
# (i.e., expand the current node in the search tree) and return a list that contains a pair (state, h'-score)
# for each of these states.   
def slide_expand(state, goal):
    node_list = []
    (height, width) = state.shape
    (empty_row, empty_col) = np.argwhere(state == 0)[0]     # Find the position of the empty tile
    
    # Based on the positin of the empty tile, find all possible moves and add a pair (new_state, h'-score)
    # for each of them.
    if empty_row > 0:
        node_list.append(make_node(state, empty_row - 1, empty_col, empty_row, empty_col, goal))
    if empty_row < height - 1:
        node_list.append(make_node(state, empty_row + 1, empty_col, empty_row, empty_col, goal))
    if empty_col > 0:
        node_list.append(make_node(state, empty_row, empty_col - 1, empty_row, empty_col, goal))
    if empty_col < width - 1:
        node_list.append(make_node(state, empty_row, empty_col + 1, empty_row, empty_col, goal))
    
    return node_list
  
# TO DO: Return either the solution as a list of states from start to goal or [] if there is no solution.               
def a_star(start, goal, expand):
    return []

# Find and print a solution for a given slide puzzle, i.e., the states we need to go through 
# in order to get from the start state to the goal state.
def slide_solver(start, goal):
    solution = a_star(start, goal, slide_expand)
    if not solution:
        print('This puzzle has no solution. Please stop trying to fool me.')
        return
        
    (height, width) = start.shape
    if height * width >= 10:            # If numbers can have two digits, more space is needed for printing
        digits = 2
    else:
        digits = 1
    horizLine = ('+' + '-' * (digits + 2)) * width + '+'
    for step in range(len(solution)):
        state = solution[step]
        for row in range(height):
            print(horizLine)
            for col in range(width):
                print('| %*d'%(digits, state[row, col]), end=' ')
            print('|')
        print(horizLine)
        if step < len(solution) - 1:
            space = ' ' * (width * (digits + 3) // 2)
            print(space + '|')
            print(space + 'V')

slide_solver(example_1_start, example_1_goal)       # Find solution to example_1

In: Computer Science

JAVA How to make a graph class that uses a linked list class to store nodes...

JAVA

How to make a graph class that uses a linked list class to store nodes and linked list within each node to store adjacency list

The linked list class has been made already.  

import java.util.*;


public class LinkedList implements Iterable
{
private int size = 0;
private Node head;
private Node tail;


private class Node
{
private T data;
private Node prev;
private Node next;

public Node(T data)
{
this.data = data;

}

}

  
public Iterator iterator()
{
return new LinkedListIterator(this);
}

  
private class LinkedListIterator implements Iterator
{
private Node iterNext;

public LinkedListIterator(LinkedList theList)
{
iterNext = theList.head;
}

public boolean hasNext()
{
return (iterNext != null);
}

public T next()
{
T value;
  
if (iterNext == null)
{
  
value = null;
}
else
{
value = iterNext.data;
iterNext = iterNext.next;
}
  
return value;
}

public void remove()
{
throw new UnsupportedOperationException("Not supported");
}
}


public void insertFirst(T value)
{

Node nodeVal = new Node(value);

if(isEmpty())
{
nodeVal.next = null;
nodeVal.prev = null;
head = nodeVal;
tail = nodeVal;
size++;
}
else
{
nodeVal.next = head;
nodeVal.prev = null;
head.prev = nodeVal;
head = nodeVal;
size++;
}
}

public void insertLast(T value)
{

Node nodeVal = new Node(value);

if (isEmpty())
{
nodeVal.next = null;
nodeVal.prev = null;
head = nodeVal;
tail = nodeVal;
size++;
}
else
{
tail.next = nodeVal;
nodeVal.next = null;
nodeVal.prev = tail;
tail = nodeVal;
size++;
}
}


public int size()
{

return size;

}

public boolean isEmpty()
{
return size() == 0;
}

public Node deleteFirst()
{

Node returnVal;

if (isEmpty())
{
throw new RuntimeException("Empty list");   
}
else
{

Node temp = head;
returnVal = head;
head = temp.next;
head.prev = null;
size--;
}

return returnVal;
}

public Node deleteLast()
{

Node returnVal;
  
if (isEmpty())
{
throw new RuntimeException("Empty list");
}
else
{
Node temp = tail;
returnVal = tail;
tail = temp.prev;
tail.next = null;
size--;
}

return returnVal;
}


public Object peekFirst()
{
if (isEmpty())
{
throw new IllegalArgumentException("Empty list");
}

return head.data;
}

public Object peekLast()
{
if (isEmpty())
{
throw new IllegalArgumentException("Empty list");
}
  
return tail.data;
}


public void printNodes(LinkedList list)
{

Iterator itr = list.iterator();

System.out.println("Here is the current list");
  
if(isEmpty())
{
System.out.println("The list is empty\n");
}
else
{
while(itr.hasNext())
{
T o = (T)(itr.next());
System.out.print(o + " ");
}
}

}

}

  

IMPORTANT! The graph class must include these class fields;

vertices, edges (of type LinkedList)

and must include these methods;

a constructor, insertVertex, insertEdge, hasVertex, getVertexCount, getEdgeCount, getVertex, getEdge, getAdjacent, getAdjacentE

In: Computer Science

Fix the following java code package running; public class Run {    public double distance; //in...

Fix the following java code

package running;

public class Run {
   public double distance; //in kms
   public int time; //in seconds

   public Run prev;
   public Run next;

   //DO NOT MODIFY - Parameterized constructor
   public Run(double d, int t) {
       distance = Math.max(0, d);
       time = Math.max(1, t);
   }
  
   //DO NOT MODIFY - Copy Constructor to create an instance copy
   //NOTE: Only the data section should be copied over, not the links
   public Run(Run source) {
       this(source.distance, source.time);
   }

   //DO NOT MODIFY (return speed in kmph)
   public double speed() {
       return distance*3600/time;
   }

   /**
   * add an INSTANCE COPY of the passed object (using the copy constructor)
   * at the end of the list in which the calling object exists.
   * @param run
   */
   public void addToEnd(Run run) {
       System.out.println(run.next);
       //to be completed
   }

   /**
   * add an INSTANCE COPY of the passed object (using the copy constructor)
   * at the front of the list in which the calling object exists
   * @param run
   */
   public void addToFront(Run run) {
       //to be completed
   }

   /**
   *
   * @return number of objects in the list in which the calling object exists
   */
   public int size() {
       return 0; //to be completed
   }

   /**
   *
   * @return the index of the calling object in the list.
   * the index of the first object in the list is 0.
   */
   public int getIndex() {
       return 0; //to be completed
   }

   /**
   *
   * @param idx
   * @return the object that exists in the list at the passed index.
   * return null if there is no object at that index
   */
   public Run get(int idx) {
  
       return null; //to be completed
   }
  
   /**
   * return a text version of the list in which the calling object exists.
   * use "->" as the separator.
   */
   public String toString() {
       return null; //to be completed
   }
  
   //DO NOT MODIFY
   public String toStringIndividual() {
       return distance+" in "+time;
   }
  
   /**
   * insert an INSTANCE COPY of the second parameter (using the copy constructor)
   * at index idx, thereby pushing all subsequent items one place higher
   * (in terms of index).
   * @param idx
   * @param run
   * @return true if an INSTANCE COPY was successfully added at
   * the given index in the list, false otherwise.
   */
   public boolean add(int idx, Run run) {
       return false; //to be completed
   }

   /**
   *
   * @param thresholdSpeed
   * @return the highest number of consecutive items in the list
   * (to which the calling object belongs) that have a speed more than
   * the thresholdSpeed.
   */
   public int longestSequenceOver(double thresholdSpeed) {
       return 0; //to be completed
   }

   /**
   *
   * @param thresholdSpeed
   * @return an array containing representations of the runs (in order of sequence)
   * in the list to which the calling object belongs, that have a speed more than
   * the thresholdSpeed. return null if no such item exists in the list.
   */
   public String[] getRunsOver(double thresholdSpeed) {
       return null; //to be completed
   }
}

In: Computer Science

Having some trouble with this Java Lab (Array.java) Objective: This lab is designed to create an...

Having some trouble with this Java Lab (Array.java)

Objective:

This lab is designed to create an array of variable length and insert unique numbers into it. The tasks in this lab include:

Create and Initialize an integer array
Create an add method to insert a unique number into the list
Use the break command to exit a loop
Create a toString method to display the elements of the array

Task 1:

Create a class called Array, which contains an integer array called ‘listArray’. The integer array should not be initialized to any specific size.

Task 2:

Create a Constructor with a single parameter, which specifies the number of elements that needs to be created for listArray. The listArray needs to be created to this size.

Task 3:

Create a ‘add’ method to class Array which will search through the elements of listArray. A looping mechanism should be used to search the array of elements. If the value passed into add is not already in the list, it should be added. Once the element is added, you need to use the break statement to exit to search so the value isn’t added to each space in the array. If all elements of the array contain non-zero numbers, no more values will be added.

Task 4:

Create a ‘toString’ method to output the non-zero elements of the array. Use the program template and the Sample Output as a reference to guide your application development.

Sample output:

Enter Number of Elements to Create in Array: 10
Enter Number to Add to List (-1 to Exit): 4
4 (added)
Enter Number to Add to List (-1 to Exit): 9
9 (added)
Enter Number to Add to List (-1 to Exit): 21
21 (added)
Enter Number to Add to List (-1 to Exit): 4
4 (duplicate)
Enter Number to Add to List (-1 to Exit): 7
7 (added)
Enter Number to Add to List (-1 to Exit): -1
Array List: 4, 9, 21, 7,

Test Code (ArrayTest.java):

package arraytest;

import java.util.Scanner;



public class ArrayTest 
{
   public static void main(String[] args) 
   {
      int      elements, input;
      Scanner  keyboard = new Scanner( System.in );
      Array    arrayList;
      
      System.out.print( "Enter Number of Elements to Create in Array: " );
      elements = keyboard.nextInt();         // Read number of elements
      arrayList = new Array( elements );     // Instantiate array with no elements
      
      do
      {
         System.out.print( "Enter Number to Add to List (-1 to Exit): " );
         input = keyboard.nextInt();      // Read new Number to add
         if ( input != -1 )
         {
            arrayList.add( input );       // Add to array if not -1
         }
      } while ( input != -1 );
      
      // call toString method to display list
      System.out.println( arrayList );    
   }  
}

In: Computer Science