Questions
In Python syntax, create a list of 10 numbers (any numbers). Create your list 3 times,...

  1. In Python syntax, create a list of 10 numbers (any numbers). Create your list 3 times, each time using a different syntax to define the list.
  1. Write a while loop that prints the numbers from 1 to 10.
  1. Convert your previous loop into a for loop.
  1. Rewrite your for loop to only have one number in the range.
  1. Write a for loop to print out each item of your list of 10 numbers, all on the same line, separated by & (ampersand).
  1. In the previous question, you may notice that your line of numbers ends with the &. See if you can change this to only print the last number instead of the &. Hint: You’ll need to be clever about printing the last number from within the loop to make this work.

In: Computer Science

Please Use your keyboard (Don't use handwriting) CS141 I need new and unique answers, please. (Use...

Please Use your keyboard (Don't use handwriting)

CS141

I need new and unique answers, please. (Use your own words, don't copy and paste)

Q1:

Show all the steps of the following data set when it being sorted with Insertion, Selection, and Merge Sort Algorithms. Then, calculate the performance of each one of them.(Big –O Notation)

18

4

26

9

21

15

20

10

Q2:

Write a program using LinkedList and ListIterator to obtain the following statements:

1. Create a linked list named "list" with these elements: "one", "four" "three", and “five.

2. Create a List Iterator named "iter1" related to "list".

3. Add the new element "two" after the element "one"

4. Remove the element "four" and “five”

5 Display all element of the list

6. Create a new List Iterator named "iter2" related to "list", to add new elements in the second, fourth and sixth positions and to create each new element you must use the value of the current element concatenated to " and a half". The new obtained list is: [one, one and a half, two, two and a half, three, three and a half]

Output sample:

[one, four, three, five]

[one, two, three]

[one, one and a half, two, two and a half, three, three and a half]

Q3:

a) Write the java code for doing a Linear Search on the array given below.

{24,2,45,20,56,75,2,56,99,53,12}

b) What would your search method return if we asked to search for the number 2 and return it’s index position?

In: Computer Science

python 3 We would like to add cursor-based APIs to the array-backed list API. To this...

python 3

We would like to add cursor-based APIs to the array-backed list API. To this end, we are including a cursor attribute, and two related methods. cursor_set will set the cursor to its argument index, and cursor_insert will insert its argument value into the list at the current cursor position and advance the cursor by 1.

E.g, given an array-backed list l that contains the values [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], running the following code

  l.cursor_set(5)
  l.cursor_insert('a')
  l.cursor_insert('b')
  l.cursor_insert('c')

will result in the updated list [0, 1, 2, 3, 4, 'a', 'b', 'c', 5, 6, 7, 8, 9]

When the cursor is set to the length of the list, cursor_insert should behave like append.

Programming rules:

  • You should only add code to the cursor_insert method; the rest of ArrayList is provided for reference and testing purposes only. cursor_set is already provided.
  • You must adhere to the same rules when using the built-in Python list as you did in the ArrayList lab.
  • Assume that cursor is set to a value between 0 and the length of the list (inclusive) when cursor_insert is called.
  • You may not use any other data structures (this includes the built-in Python list).

class ArrayList:
def __init__(self):
self.data = []
self.cursor = 0
  
def append(self, val):
self.data.append(None)
self.data[len(self.data)-1] = val
  
def cursor_set(self, idx):
self.cursor = idx
  
def cursor_insert(self, val):
# YOUR CODE HERE

In: Computer Science

in java This class will require the following fields: Node<T> head: the first Node in the...

in java

This class will require the following fields:

  • Node<T> head: the first Node in the chain
  • Node<T> tail: the last Node in the chain
  • int size: Keeps a count of the number of Nodes in the chain

Your LinkedList class must also support the following public methods.

  • LinkedList(): A default constructor sets both pointers to null and sets the size to 0.
  • int size(): Returns the size of the LinkedList.
  • void push_back(T): Creates a new Node and assigns it to the end of the list of Nodes while updating the size by 1.
  • void push_front(T): Creates a new Node and assigns it to the front of the list of Nodes while updating the size by 1.
  • T pop_back() throws ListEmptyException: Deletes the Node at the end of the list (or throws a ListEmptyException if this is not possible). Decreases size by 1. Returns the deleted element.
  • T pop_front() throws ListEmptyException: Deletes the Node at the front of the list (or throws a ListEmptyException if this is not possible). Decreases size by 1. Returns the deleted element.
  • T at(int) throws ListException: Returns the element stored at the specified index. If the index is out-of-bounds (either for being negative or greater than/equal the size of the list), throw a ListException with the message "Index out of bounds.” This method should operate at O(1) for accessing the first or last element in a list and at O(n) for any element other than the first or the last.
  • T front() throws ListEmptyException: Returns the first element (throws a ListEmptyException if the list is empty)
  • T back() throws ListEmptyException : Returns the last element (throws a ListEmptyException if the list is empty)
  • void printAll(): prints all the nodes in the LinkedList

In: Computer Science

Using java: Implement a basic doubly-linked list that implements a priority system sorting the elements that...

Using java:

Implement a basic doubly-linked list that implements a priority system sorting the elements that are inserted. Sort based on the speed of the warrior.

Driver code:

public class LinkedListDriver {
public static void main(String[] args) {
LinkedList list = new SortedDoublyLinkedList();

System.out.println(list);
Warrior krogg = new Warrior("Krogg", 30, 50, 200);
list.insert(krogg);

System.out.println(list);
Warrior gurkh = new Warrior("Gurkh", 40, 45, 180);
list.insert(gurkh);

System.out.println(list);
Warrior brynn = new Warrior("Brynn", 45, 40, 190);
list.insert(brynn);

System.out.println(list);
Warrior dolf = new Warrior("Dolf", 20, 65, 210);
list.insert(dolf);

System.out.println(list);
Warrior zuni = new Warrior("Zuni", 50, 35, 170);
list.insert(zuni);

System.out.println(list);
}
}

Warrior class:

public class Warrior {
private String name;
private int speed;
private int strength;
private int hp;
public Warrior(String name, int speed, int str, int hp) {
this.name = name;
this.speed = speed;
this.strength = str;
this.hp = hp;
}

public String getName() { return this.name; }
public int getSpeed() { return this.speed; }
public int getStrength() { return this.strength; }
public int getHp() { return this.hp; }

public String toString() { return this.name + "(" +
this.speed + ")"; }
}

Class that needs to be done:
interface LinkedList {
void insert(Warrior warrior);
String toString();
}

Expected output:
[ Zuni(50) Brynn(45) Gurkh(40) Krogg(30) Dolf(20) ]

In: Computer Science

Please use python: # Problem Description Given a directed graph G = (V, E), find the...

Please use python:

# Problem Description

Given a directed graph G = (V, E), find the number of connected components in G.

# Input

The graph has `n` vertices and `m` edges.
There are m + 1 lines, the first line gives two numbers `n` and `m`, describing the number of vertices and edges. Each of the following lines contains two numbers `a` and `b` meaning there is an edge (a,b) belong to E. All the numbers in a line are separated by space. (`1 <= a,b <= n`)

You can assume that 2 <= n <= 10000, 1 <= m <= 50000.

Your code should read the input from standard input (e.g.
using functions `input()/raw_input()` in Python and `cin/scanf` in C++).

# Output

One number representing the number of connected components in the graph.


Your code should write the output to standard output (e.g. using functions `print` in Python and `cout/printf` in C++).

# Requirement

Your algorithm should run in O(|V| + |E|) time.

Time limtation: 5 seconds.

Memory limitation: 1.0 GB.

# Environment

Your code will be running on Ubuntu 18.04.5.

Now only accept C++ and Python2/Python3 code, g++ version 7.5.0 and Python versions are Python 2.7.17 and Python 3.6.9.

# Examples and Testing

Some examples (e.g., input-x.txt and output-x.txt, x = 1, 2) are provided.
A figure corresponding input-1 can be found in this repo too.
For Python code, try the following to test your code
```
python ./solution.py < input-x.txt > my-output-x.txt
```
For C++ code, try the following to test your code
```
g++ -o mybinary solution.cpp
./mybinary < input-x.txt > my-output-x.txt
```

Your output `my-output-x.txt` needs to be *match exactly* to the given `output-x.txt`.
On Unix-based systems you can use `diff` to compare them:
```
diff my-output-x.txt output-x.txt
```
On Windows you can use `fc` to compare them:
```
fc my-output-x.txt output-x.txt
```

# Submission

If you want to upload a single file, make sure the file is named as `solution.py` (for Python) or `solution.cpp` (for C++).
If you submit via GitHub, make sure your file is located in directory `assignment3/problem1/solution.py` (for Python) or `assignment3/problem1/solution.cpp` (for C++).

# Hints

Use adjacency list to store all the edges.

In: Computer Science

When a magnet is plunged into a coil at speed v, as shown in the figure, a voltage is induced in the coil and a current flows in the circuit.(Figure 1)

When a magnet is plunged into a coil at speed v, as shown in the figure, a voltage is induced in the coil and a current flows in the circuit. (Figure 1)

Part A

If the speed of the magnet is doubled, the induced voltage is ________.

  • a.) twice as great
  • b.) four times as great
  • c.) half as great
  • d.) unchanged

 

In: Physics

When a magnet is plunged into a coil at speed v, as shown in the figure, a voltage is induced in the coil and a current flows in the circuit.(Figure 1)

When a magnet is plunged into a coil at speed v, as shown in the figure, a voltage is induced in the coil and a current flows in the circuit. (Figure 1)

Part A

If the speed of the magnet is doubled, the induced voltage is ________.

a.) twice as great

b.) four times as great

c.) half as great

d.) unchanged

 

In: Computer Science

Two 2.0 cm ×2.0 cm square aluminum electrodes, spaced 0.80 mm apart, are connected to a...

Two 2.0 cm ×2.0 cm square aluminum electrodes, spaced 0.80 mm apart, are connected to a 200 V battery.

Part A---- What is the capacitance? Express your answer in picofarads.

Part B ----What is the charge on the positive electrode? Express your answer in coulombs.

In: Physics

What is methyl mercury? II. Sources of Methyl Mercury? III. Health concerns and potential receptors? IV....

What is methyl mercury? II. Sources of Methyl Mercury? III. Health concerns and potential receptors? IV. Susceptibility ? V. Remediation? VI. Long term effects? VII. Existing studies and guidelines? VIII. Risk? IX. Is the trade off worth it? We need energy.?

In: Chemistry