Questions
Use a dictionary to represent a directed graph in which each key is a pair (tuple)...

Use a dictionary to represent a directed graph in which each key is a pair (tuple) of two nodes, with the corresponding value set to the edge weight.

For example, W[u,v] =42.

Where in u → v.

Write a function to calculate the in and out degree of a given node.

What would be the advantages and disadvantages of this representation?


in python

In: Computer Science

A graph G = (V, E) is a near-tree if it is connected and has at...

A graph G = (V, E) is a near-tree if it is connected and has at most n+ 8 edges, where n = |V |. Give an algorithm with running time O(n) that takes a near-tree G with costs on its edges, and returns a minimum spanning tree of G. Assume all the edge costs are distinct.

In: Computer Science

Consider the cell described below at 291 K: Sn | Sn2+ (0.753 M) || Pb2+ (0.921...

Consider the cell described below at 291 K:

Sn | Sn2+ (0.753 M) || Pb2+ (0.921 M) | Pb

Given EoPb2+→Pb = -0.131 V, EoSn2+→Sn = -0.143 V. Calculate the cell potential after the reaction has operated long enough for the Sn2+ to have changed by 0.325 mol/L.

In: Chemistry

Design an O(n log n) algorithm that takes two arrays A and B (not necessarily sorted)...

Design an O(n log n) algorithm that takes two arrays A and B (not necessarily sorted) of size n of real numbers and a value v. The algorithm returns i and j if there exist i and j such that A[i] + B[j] = v and no otherwise. Describe your algorithm in English and give its time analysis.

In: Computer Science

Consider the cell described below at 261 K: Fe | Fe2+ (0.903 M) || Cd2+ (0.991...

Consider the cell described below at 261 K:

Fe | Fe2+ (0.903 M) || Cd2+ (0.991 M) | Cd

Given EoCd2+→Cd = -0.403 V, EoFe2+→Fe = -0.441 V. Calculate the cell potential after the reaction has operated long enough for the Fe2+ to have changed by 0.373 mol/L

In: Chemistry

Java Write a method, makeUserName, that is passed two Strings and an int: the first is...

Java

Write a method, makeUserName, that is passed two Strings and an int: the first is a first name, the second is a last name, and the last is a random number. The method returns a user name that contains the last character of the first name, the first five characters of the last name (assume there are five or more characters in last name), and the random number. An example: Assume that “John”, “Smith”, 45, are passed when the method is called, it will return “nSmith45” as the user name.

In: Computer Science

Consider the following incomplete declaration of a Name class for 2a-2c. public class Name something missing...

Consider the following incomplete declaration of a Name class for 2a-2c.

public class Name something missing

{

   private String first;

   private String last;

   public Name(String firstName, String lastName)

   {

      first = firstName;

     last = lastName;

   }

   //additional methods

}

2a) In the first two parts, you will modify the Name class so that it implements the Comparable interface. Show here what should go in place of something missing in the first line of the class declaration.

2b) In this part, implement the compareTo method. The standard ordering of names is to be used: alphabetical order by last name, and if the two last names are the same, alphabetical order by first name. Two names are considered the same if and only if both the first and last names are the same.

2c) Implement a toString method in the Name class, which takes no parameters and returns a String containing the full name: first name then last name. For example, if the first name is “John” and the last name is “Doe”, then toString should return “John Doe”.

In: Computer Science

Write a program call FancyMyName which asks you to write a program that tests the usage...

Write a program call FancyMyName which asks you to write a program that tests the usage of different methods for working with Strings.

This program will ask the user to enter their first name and their last name, separated by a space.

Read the user's response using Scanner. Separate the input string up into two strings, one containing the first name and one containing the last name. You can accomplish this by using the indexOf() hint*** find the position of the space, and then using substring() to extract each of the two names. Also output the number of characters in each name (first & last) and output the user's initials. The initials are the first letter of the first name together with the first letter of the last name

A sample run of the program should look something like this:

Please enter your first name and last name, separated by a space?

You entered the name: Steve Henry

Your first name is Steve: has 5 characters

Your last name is Henry: has 5 characters

Your initials are: SH

In: Computer Science

I am working on making a simple grade book that will take user input like name...

I am working on making a simple grade book that will take user input like name and grade and then return the name and grade of multiple inputs when the person quits the program. Here is the code that I have been working on. This is in Python 3. I can get one line to work but it gives me an error.

Here is what it is supposed to look like:

These are just examples
billy 100
greg 60
jane 90
stephanie 70

If I put an name and grade into my code it returns this:

david98

It returns for only one input for each and it finishes with an exit code of 1.

I need to have multiple inputs stored in the dictionary. I am new to dictionaries and I am having a little trouble with it.

Here is the code for my program:
grades = {}

while True:
    name = input("Enter a name (or 'quit' to stop): ")
    if name == 'quit':
        break
    grade = input("Enter a grade: ")


    def set_grade(name, grade):
        global grades
        grades[name] = grade


    def get_grade(name):
        if name in grades:
            return grades[name]


    def get_name(grade):
        if grade in grades:
            return grades[grade]


    set_grade(name, grade)
    print(name + get_grade(name))
    print(grade + get_name(grade))

In: Computer Science

In java language how would I write the following? Create an array called “boyNames” and store...

In java language how would I write the following?

  • Create an array called “boyNames” and store all names from the BoyNames.txt file
  • Similarly, create an array called “girlsNames” and store all names from the GirlNames.txt file
  • Create a text menu that allowing users to:

         1. Enter a name and the application must display a message indicating if the name is   among the most popular (found on either array)

  • If the name is found, tell the user if it is a boy’s or girl’s name

         2. Option to suggest a name. Program must suggest/display a name to the user by randomly selecting one from the appropriate array depending if the user wants a boy’s or girl’s name               

  3. Option to display all names starting with a specific letter. Display all names starting

         with a specific letter (e.g. all names starting with the letter R) depending if the user

         wants a boy’s or girl’s name

After a user either enters a name from (1) in the menu or is suggested a name from (2), the program must ask if the name is acceptable for the newborn or not

1. If the name is not acceptable, user must be given the option to exit the program or repeat the procedure. Either ask for a new name to search if user is in (1), or suggest a new name randomly if in (2).

         2. If the name is acceptable, program must ask the user to enter the newborn’s last name and expected date of birth.

         3. Then, the program must instantiate an object of the class called NewBorn using its constructor with the accepted name for the newborn, last name, and expected date of birth.

         4. Finally, program must display the state of the NewBorn object

In: Computer Science