inverse a matrix using pseudo inverse using python (numpy can be used) for a 2d list (n x n).
In: Computer Science
JAVA
the task is to implement the missing methods in the LinkedIntSet class. Each method you must write has comments describing how it should behave. You may not add any new fields to the LinkedIntSet class and you may only add new code inside the bodies of the 5 methods you are asked to write. You may also write new private helper methods. However, you may not change any method headers, you may not change any code outside of the 5 methods, and you may not add any new data fields to the class.
public class LinkedIntSet {
private static class Node {
private int data;
private Node next;
public Node(int data, Node next)
{
this.data =
data;
this.next =
next;
}
}
private Node first;
public LinkedIntSet() {
first = null;
}
public int size() {
int counter = 0;
for (Node current = first; current
!= null; current = current.next)
counter++;
return counter;
}
public boolean contains(int i) {
for (Node current = first; current
!= null; current = current.next) {
if (current.data
== i)
return true;
}
return false;
}
// Ignore this equals method. Write the code for
the other equals method.
public boolean equals(Object otherObject) {
LinkedIntSet other = (LinkedIntSet)
otherObject;
return this.equals(other);
}
/***************************** NEW METHODS ************************************/
/**
* Adds <code>element</code> to this set if
it is not already present and
* returns <code>true</code>. If
<code>element</code> is already present, the
* set is unchanged and <code>false</code>
is returned.
*
* @param element the element to be added
* @return <code>true</code> if the element
was added and <code>false</code>
* otherwise.
*/
public boolean addElement(int element) {
// Replace the line below with your
answer
throw new RuntimeException("Not
implemented");
}
/**
* Removes an element from the set.
*
* @param element the element to be removed
* @return <code>ture</code> if the element
was removed and <code>false</code>
* otherwise.
*/
public boolean removeElement(int element) {
// Replace the line below with your
answer
throw new RuntimeException("Not
implemented");
}
/**
* Changes the set so that it is equal the union of
itself and
* <code>other</code>.
*
* @param other the set to union with
*/
public void union(LinkedIntSet other) {
// Replace the line below with your
answer
throw new RuntimeException("Not
implemented");
}
/**
* Changes the set so that is equal the intersection of
itself and
* <code>other</code>.
*
* @param other the set to intersect with
*/
public void intersect(LinkedIntSet other) {
// Replace the line below with your
answer
throw new RuntimeException("Not
implemented");
}
}
In: Computer Science
Dynamic Programming (DP) is an algorithmic technique for solving an optimization problem by breaking it down into simpler subproblems and utilizing the fact that the optimal solution to the overall problem depends upon the optimal solution to its subproblems. When the technique is applicable, this condition can be extended incrementally without having to alter previously computed optimal solutions to subproblems. Eventually the condition applies to all of the data and, if the formulation is correct, this together with the fact that nothing remains untreated gives the desired answer to the complete problem.
What would be 4 examples that describe Dynamic Programming?
In: Computer Science
In: Computer Science
Write a program to print random numbers and whether they were
even or odd. Ask the user to enter a positive number to indicate
how many random numbers to pull (verify number is positive). Zero
is positive.
Declare two variables and initialized to zero.
int evens = 0, odds = 0;
Use them to count how many evens and how many odds were
pulled.
Enter how many random numbers to pull : 3
41
odd
18467 odd
6334 even
1 even and 2 odd random numbers were generated.
In: Computer Science
The following tables form part of a database held in a relational DBMS:
Hotel (hotelNo, hotelName, hotelAddress, country)
Room (roomNo, hotelNo, type, price)
Guest (guestNo, guestName, guestAddress, country)
Booking (hotelNo, guestNo, dateFrom, dateTo, roomNo)
Write the SQL statements for the following questions:
1. List the rooms that are currently unoccupied at the Grosvenor Hotel, for:
(a) Use 2019-10-01 as today's date. Include all 'Grosvenor' hotels. List in hotelNo, roomNo order. Use NOT IN to perform the difference operation
(b) Use 2019-10-01 as today's date. Include all 'Grosvenor' hotels. List in hotelNo, roomNo order. Use NOT EXISTS to perform the difference operation.
(c) Use 2019-10-01 as today's date. Include all 'Grosvenor' hotels. List in hotelNo, roomNo order. Use LEFT JOIN to perform the difference operation.
(d) Use 2019-10-01 as today's date. Include all 'Grosvenor' hotels. List in hotelNo, roomNo order. Use MINUS to perform the difference operation.
In: Computer Science
(PYTHON) Lottery program. The program randomly generates a two-digit number, prompts the user to enter a single two- digit number, and determines whether the user wins according to the following rules. Write a loop to let the user play as many times as the user wanted. Use a sentinel or flag to quit out of the loop.
1.if the user’s input matches the lottery In the exact order, the award is $10,000.
2.if all the digits in the user’s input match all the digits in the lottery number, the award is $3,000.
3. if one digit in the user’s input matches a digit in the lottery number, the award is $1,000.
In: Computer Science
Write 3 classes with three levels of hierarchy: Base, Derive (child of base), and D1 (child of Derive class). Within each class, create a “no-arg” method with the same signature (for example void m1( ) ). Each of this method (void m1( ) ) displays the origin of the Class type. Write the TestDynamicBinding Class: (the one with the ‘psvm’ ( public static void main (String[] args)) to display the following. You are NOT allowed to use the “standard object.m1() “to display the message in the main(…) method. That would NOT be polymorphic! (minus 10 points for not using polymorphic method) Explain why your solution demonstrates the dynamic binding behavior? (minus 5 points for lack of explanation) From Parent Class From Derived:Parent Class From Derived:Parent Class From D1:Derived Class Explain why this demonstrates dynamic polymorphism: (minus 4 points for lack of explanation)
In: Computer Science
JAVA) I need to get 10 integer numbers from the user. Then I need to find sum of odd numbers, sum of even numbers, the lowest number of all numbers, the highest number of all numbers, and the average of all numbers( use double, with the two digit decimal)
process;
loopCount = 1
While LoopCount <= 10
Read number from the keyboard
If odd, add to the total of all odd numbers
If even, add to the total of all even numbers
Add to the total of ALL numbers
Determine the smallest and largest number
Increment loopCount
End Loop Identify and display all three totals and range of numbers
Compute and display the average
In: Computer Science
Using Java,
Given an array A[0 ... n-1], where each element of the array represent a vote in the election. Assume that each vote is given as an integer representing the ID of the chosen candidate. Can you determine who wins the election? What is the complexity of your solution? Hint: it is similar to finding the element that is repeated the maximum number of times.
In: Computer Science
c++
students.txt
20
Shawn Lynch 2.0 Hasan Stephens 2.6 Frank Wright 2.7 Hugo Ray 2.9 Justin Gardner 3.0 Kelly Jenkins 2.2 Rafael Seymour 3.7 Jose Cantu 0.6 David Gilmore 1.3 Emma Paterson 2.1 Jackie White 1.9 Robert Green 3.8 Julio Armstrong 1.1 Erik Cook 4.0 Jessica Hale 3.0 Vanessa Rivera 0.9 Sandra Ferguson 3.1 Christian Wang 1.1 Jackson Martinez 1.9 Austin Black 4.0
For your program, you will need to define a class Student, with private members for first name, last name, and GPA, and any methods you determine that you need (constructors, gets/sets, etc.) Once the class is defined, you will need to populate an array of Student objects to be sorted with data provided in the students.txt file.
First line in the text file will be size of the array.
Every line after the first contains three pieces of information, separated by spaces: First Name, Last Name, and GPA
and sort the Student data by GPA.(Using MergeSort)
display unsorted data and sorted data
In: Computer Science
Let G be any context-free grammar. Show that the number of strings that have a derivation in G of length n or less, for any n > 0, is finite.
Could you please answer with clear explanation. The question is from Elaine Rich's Automata, Computability and Complexity Chapter 11 Exercise 14.
In: Computer Science
<HTML JAVASCRIPT>
Please create an array of student names and another array of student grades.
Create a function that can put a name and a grade to the arrays.
Keep Read student name and grade until student name is “???”. And save the reading by using a function
Create another function to show all the grade in that object.
Create the third function that can display the maximum grade and the student’s name.
Create a sorting function that can sort the arrays based on the student’s grade.
Display all the grades and names sorted by the grade.
[Report]
PLEASE POST OUTPUT IN NOTEPAD++ or NOTEPAD! Thanks
In: Computer Science
Averaging measurements: Use python 3 to write this program
Assume that someone has collected a set of measurements and wants some statistical data about them. Write a program that asks a user for measurements and prints the average, the maximum, and the minimum measurement. Users should be allowed to enter as many measurements as they want, until entering a negative measurement. The negative measurement should not be processed, but is just used to indicate that the user has finished entering measurements. [Note: do not use a list to store the measurements.]
Note: Complete without using import sys. Only use simple for and while loops and if else statements.
In: Computer Science