Questions
List several advantages that method of steepest descent has over Newton's method and give a brief...

List several advantages that method of steepest descent has over Newton's method and give a brief explanation of each advantage. Also list advantages that Newton's method has over steepest descent method and give a brief explanation of each advantage as well.

In: Computer Science

Q14 Describe a maintenance plan for: a) Vacuum, and b) SF6 breakers • Cover the two...

Q14 Describe a maintenance plan for: a) Vacuum, and b) SF6 breakers • Cover the two types separately. • Be specific and do not list generic information (some research may be required). • List any special precautions during maintenance. • 10 + 5 = 15 marks.

In: Electrical Engineering

In C++, write a function that takes in as inputs two arrays, foo and bar, and...

In C++, write a function that takes in as inputs two arrays, foo and bar, and their respective array sizes. The function should then output the concatenation of the two arrays as a singly linked list. You may assume that you are provided a singly linked list header file.

In: Computer Science

1. What is an animal? List characteristics describing animals. 2. What is the Cambrian Explosion? 3....

1. What is an animal? List characteristics describing animals.

2. What is the Cambrian Explosion?

3. Is the kingdom “Animalia” monophyletic or polyphyletic?

4. How do you describe invertebrates? What are examples of invertebrates?

5. List criteria that are used to classify invertebrates.

In: Biology

Write a function argmax(somelist=[]) to return the index of the largest number in a numerical list,...

Write a function argmax(somelist=[]) to return the index of the largest number in a numerical list, or None if the list is empty. If there are ties, then return the index of the first occurrence of the largest number. Sample: argmax([2, 2, 4, 4, 1]) returns 2. in python program

In: Computer Science

Q1-      Write a program that takes a list of values as an input from the user....

Q1-      Write a program that takes a list of values as an input from the user. The program should further ask the user about sorting the list in ascending or descending order. It is desirable to use Arraylist/Vector in place of simple arrays. (Object Oriented Programming java)

In: Computer Science

​​​​​​This is an assignment that I'm having trouble figuring out in python: Modify Node class so...

​​​​​​This is an assignment that I'm having trouble figuring out in python:

  • Modify Node class so it has a field called frequency and initialize it as one.

  • Add a search function. If a number is in the list, return its frequency.

  • Modify Insert function. Remove push, append, and insertAfter as one function called insert(self, data). If you insert a data that is already in the list, simply increase this node’s frequency. If the number is not in the list, add it to the beginning of the list.

  • Modify Delete function. When you delete a node, reduce its frequency. If frequency becomes zero, remove the node from the list.

  • Modify Print function to print out all the numbers with their frequency in the list.

The program that we are suppose to modify:

class Node:
def __init__(self,d):
self.data=d;# data in the node
self.next=None #address of next node
"""add a field called frequency here"""
class LinkedList:
def __init__(self):
self.head=None #linked list at the beginning is empty. head is None
  
def print(self):#print every node's data
temp=self.head#let temp points to head
while temp:#As long as temp is not None (the end)
"""modify print, so frequency is also printed out frequency """
print(temp.data,end="")#print data
temp=temp.next # let temp points to the next Node
print()
"""complete the folloing function """   
def insert(self,d):
temp=self.head
"""
travel the list like print, if d is in there break the loop
if yes, increase its freq
if not add it the front of the list like "push"
"""
  
  

"""
def push(self,new_d):#will add new node at the beginning
newNode=Node(new_d) #create a Node
newNode.next=self.head #Let new Node's next to be the original head
self.head=newNode #update head as the New Node
def insertAfter(self,prev_data, new_data):
temp=self.head#let temp be the head
while temp and temp.data!=prev_data:#as long temp is not None and data is not prev_data
temp=temp.next
#if you can get here. One of the condition must be false
if temp==None:#There is no prev_data because you have reached the end
print("The given previous node does not exist")
return
#if you can reach here, temp.data=prev.data
newNode=Node(new_data)#create a new node after Node temp
  
newNode.next=temp.next#make newNode's next as temp's next
temp.next=newNode# make temp's(prev) next as NewNode
def append(self,new_data):# add new_data at the end of the list
newNode=Node(new_data)#create a Node with new_data

if self.head==None:#in case the list is empty
self.head=newNode
return

last=self.head#let last be head
while last.next:#as long last next is not None, continue
last=last.next# let last as its next
#when loop terminates, last.next is None, therefore last points to the last Node
last.next=newNode
"""
def delete(self,key):#delete a Node with data "key"
temp=self.head #let temp be head
if temp is not None:#if list is not empty
if temp.data==key:#if key is at the first Node
"""reduce temp'frequency
if its frequency becomes 0, execute the next three lines"""
self.head=temp.next #let head to head's next
temp=None
return
  
while temp is not None:#if list is not empty
if temp.data==key:#loop ends if key is found
break
prev=temp#prev is node before
temp=temp.next
#Loop ends either temp is None or loop ends because of "break" which means key is found
if temp==None:
return #return because key is not in the list
#when temp.data is same as key
"""reduce temp'frequency
if its frequency becomes 0, execute the next three lines"""
prev.next=temp.next
temp=None
  
  
  
  
  
list=LinkedList()
list.insert(5)
list.insert(9)
list.insert(5)
list.insert(6)
list.insert(6)
list.insert(9)

list.print()
list.delete(5)
list.print()
list.delete(5)
list.print()
list.delete(6)
list.print()
list.delete(6)
list.print()

  

In: Computer Science

The problem is known as the Josephus Problem (or Josephus permutation) and postulates a group of...

The problem is known as the Josephus Problem (or Josephus permutation) and postulates a group of people of size N >= 1 are standing in a circle waiting to be eliminated. Counting begins at a specified point in the circle and proceeds around the circle in a specified direction. After a specified number of M >= 1 people are counted, the M^th person in the circle is eliminated. The procedure is repeated with the remaining people, starting with the next person, going in the same direction and counting the same number of people, until only one person remains.

For example, suppose that M = 3 and there are N = 5 people named A, B, C, D and E. We count three people starting at A, so that C is eliminated first. We then begin at D and count D, E and back to A, so that A is eliminated next. Then we count B, D and E, and finally B, D and B, so that D is the one who remains last.

For this computer assignment, you are to write and implement a C++ program to simulate and solve the Josephus problem. The input to the program is the number M and a list of N names, which is clockwise ordering of the circle, beginning with the person from whom the count is to start. After each removal, the program should print the names of all people in the circle until only one person remains. However, to save printing space, print the names of the remaining people only after K >= 1 eliminations, where K is also an input argument to the program. The input arguments N, M and K can be entered from stdin in the given order. (see josephus.d for values)

Programming Notes:

  • Name the people in the circle in the following sequence: A1, A2 ... A9, B1, B2 ... B9, C1, C2 ..., and start counting from the person A1. Enter input values N, M and K when the program prompts for them and use a list<string> container to store the names of N people.

  • void init_vals(list<string> &L, args &in) It reads the input values N, M and K of the struct args in when the program prompts for them. The routine prints out those values on stdout, and fills the names of people in the list L. You can find the definition of the struct args in the header file josephus.h, which is defined as:

struct args 
{
        unsigned N;
        unsigned M;
        unsigned K;
}; 
  • void print_list(const list<string> &L, const unsigned &cnt) It prints out the contents of the list L at the beginning and after removing K names (each time) from the list, until only one name remains in the list, where cnt has an initial value 0 and it indicates the total number of removals so far. At the end, it also prints the name of the last remaining person. For printout, print only up to 12 names in a single line, where the names are separated by single spaces.

  • The main() routine first calls the routine init_vals() and initializes cnt to 0, and then calls the print_list() to print out the names of people in circle. After that it locates the M^th person in the list, and using the member function erase(), it removes that person from the list, and by calling the print_list() prints out the current contents of the list. This process continues (in a loop) until only one person remains in the list.

    • If i (with initial value 0) indicates the position of a person in list L, then the statement: j = (i + (M –1))%L.size() returns the position of the M^th person from the position i.

    • Since the argument to the erase() function is an iterator, you can convert the index value j to an iterator by the advance(p, j) function, where p = L.begin().

  • To store the names in an empty list, first change the size of the list to N, and then use the generate() function in the STL. The last argument to this function is the function object SEQ(N), which is defined in the header file josephus.h.

Assignment Notes:

  • Include any necessary headers and add necessary global constants.

  • You are not allowed to use any I/O functions from the C library, such as scanf or printf. Instead, use the I/O functions from the C++ library, such as cin or cout.

In: Computer Science

4) Implement the Selection Sort algorithm discussed in class to sort a list of a certain...

4) Implement the Selection Sort algorithm discussed in class to sort a list of a certain size. The list is to be
implemented using a dynamic array as well as a singly linked list. You are required to compare the
performance (sorting time) for the dynamic array and singly-linked list-based implementations.

You are given the startup codes for the dynamic array and singly-linked list based implementations. You
are required to implement the Selection Sort function in each of these codes. The main function is written
for you in such a way that the code will run for different values of list sizes ranging from 1000 to 20000,
in increments of 1000. The inputs for the maximum value and number of trials are 5000 and 50 for all
cases. The codes will output the average sorting time (in milliseconds) for each of value of list size for the
two implementations.
You are then required to tabulate the average sorting times observed for the two implementations and then
plot the same in Excel. Generate one plot that displays (compares) the sorting times for both the
implementations. Use the Add Trend Line option in Excel, choose the Power function option and display
the equations and the R2 values for the two curves. The R2 values are expected to be closer to 1.0. Make
sure the two equations and the R2 values are clearly visible in your Excel plot. (Please answer in C++)

Dynamic list implementation code:

#include <iostream>
#include <ctime>
#include <ratio>
#include <chrono>
#include <time.h>
#include <stdlib.h>

using namespace std;

// implementing the dynamic List ADT using array
// operations to be implemented: read, Modify, delete, isEmpty, insert, countElements

class List{

   private:
       int *array;
       int maxSize; // useful to decide if resizing (doubling the array size) is needed
       int endOfArray;
  
   public:
       List(int size){
           array = new int[size];
           maxSize = size;
           endOfArray = -1;
       }
      
       void deleteList(){
           delete[] array;
       }
      
       bool isEmpty(){
          
           if (endOfArray == -1)
               return true;
          
           return false;
       }
      
       void resize(int s){
          
           int *tempArray = array;
          
           array = new int[s];
          
           for (int index = 0; index < min(s, endOfArray+1); index++){
               array[index] = tempArray[index];
           }
          
           maxSize = s;
          
       }
  
      
       void insert(int data){
          
           if (endOfArray == maxSize-1)
               resize(2*maxSize);
          
           array[++endOfArray] = data;
          
       }
      
      
       void insertAtIndex(int insertIndex, int data){
          
           // if the user enters an invalid insertIndex, the element is
           // appended to the array, after the current last element          
           if (insertIndex > endOfArray+1)
               insertIndex = endOfArray+1;
          
           if (endOfArray == maxSize-1)
               resize(2*maxSize);          
          
           for (int index = endOfArray; index >= insertIndex; index--)
               array[index+1] = array[index];
          
           array[insertIndex] = data;
           endOfArray++;
          
       }
      
      
       int read(int index){
           return array[index];
       }
      
       void modifyElement(int index, int data){
           array[index] = data;
       }
          
      
       void deleteElement(int deleteIndex){
          
           // shift elements one cell to the left starting from deleteIndex+1 to endOfArray-1
           // i.e., move element at deleteIndex + 1 to deleteIndex and so on
          
           for (int index = deleteIndex; index < endOfArray; index++)
               array[index] = array[index+1];
          
           endOfArray--;  
      
       }
      
       int countList(){
           int count = 0;
           for (int index = 0; index <= endOfArray; index++)
               count++;
          
           return count;
       }
      
       void print(){
          
           for (int index = 0; index <= endOfArray; index++)
               cout << array[index] << " ";
          
           cout << endl;
          
       }

};


void SelectionSort(List list){
  
// Implement the selection sorting algorithm here...
  
  
}


int main(){

   using namespace std::chrono;
  
   srand(time(NULL));
  

  
   int maxValue;
   cout << "Enter the max value: ";
   cin >> maxValue;
  
   int numTrials;
   cout << "Enter the number of trials: ";
   cin >> numTrials;

for (int listSize = 1000; listSize <= 20000; listSize += 1000){

double totalSortingTime = 0;
  
for (int trials = 1; trials <= numTrials; trials++){
  
   List integerList(1);
  
   for (int i = 0; i < listSize; i++){
      
       int value = 1 + rand() % maxValue;  
       integerList.insertAtIndex(i, value);
   }
  

  
  
   high_resolution_clock::time_point t1 = high_resolution_clock::now();
   SelectionSort(integerList);
   high_resolution_clock::time_point t2 = high_resolution_clock::now();
  
   duration<double, std::milli> sortingTime_milli = t2 - t1;
   totalSortingTime += sortingTime_milli.count();
  
   integerList.deleteList();
  
}
  
  
   cout << "Average sorting time for list size " << listSize << " is " << (totalSortingTime/numTrials) << " milli seconds " << endl;

} // list size   loop

   system("pause");
  
return 0;
}

In: Computer Science

The table below shows the critical reading scores for 14 students the first two times they...

The table below shows the critical reading scores for 14 students the first two times they took a standardized test. At α =0.01,

is there enough evidence to conclude that their scores improved the second time they took the​ test? Assume the samples are random and​ dependent, and the population is normally distributed. Complete parts​ (a) through​ (f).

Student

1

2

3

4

5

6

7

8

9

10

11

12

13

14

Score on first test

409

360

365

406

605

489

387

384

605

528

321

362

362

321

Score on second testScore on second test

418

437

442

454

536

533

386

520

673

581

331

390

392

342

a) Identify the claim and state H0 and Ha.

The claim is​ "The students' critical reading test scores ▼ (decreased, did not change, changed, improved) the second time they took the​ test.

Let μd be the hypothesized mean of the the​ students' first score minus their second score. State H0 and Ha.

Choose the correct answer below.

A. H0​: μ≥d

Ha​: μ<d

B. H0​: μ≤d

Ha​: μ>d

C. H0​: μ≥0

Ha​: μ<0

D.

H0​: μ≠0

Ha​:μ=0

E. H0​: μ≤0

Ha​:μ>0

F. H0​: μ=0

Ha​: μ≠0

​(b) Find the critical​ value(s) and identify the rejection​ region(s).

t 0= ​(Use a comma to separate answers as needed. Type an integer or a decimal. Round to three decimal places as​ needed.)

Identify the rejection​ region(s). Choose the correct answer below.

A. t<−2.650 or t>2.650

B. t<−2.650

C. t<−3.012 or t>3.012

D. t>3.012

​(c) Calculate d and sd.

d= ​(Type an integer or a decimal. Round to three decimal places as​ needed.)

Calculate sd.

sd=   Type an integer or a decimal. Round to three decimal places as​ needed.)

​(d) Use the​ t-test to find the standardized test statistic t.

t= ​(Type an integer or a decimal. Round to three decimal places as​ needed.)

​(e) Decide whether to reject or fail to reject the null hypothesis. Choose the correct answer below.

Fail to reject the null hypothesis.

Rejectthe null hypothesis.

​(f) Interpret the decision in the context of the original claim. Choose the correct answer below.

A. At the​ 1% significance​ level, there is not enough evidence that the​ students' critical reading scores improved the second time they took the test.

B. At the​ 1% significance​ level, there is enough evidence that the​ students' critical reading scores improved the second time they took the test.

C. The sample was not large enough to make a conclusion.

D. At the​ 1% significance​ level, there is evidence that the​ students' critical reading scores got worse the second time they took the test

In: Statistics and Probability