Questions
Java: Complete the methods marked TODO. Will rate your answer! -------------------------------------------------------------------------------------------------- package search; import java.util.ArrayList; import...

Java: Complete the methods marked TODO. Will rate your answer!

--------------------------------------------------------------------------------------------------

package search;

import java.util.ArrayList;
import java.util.List;

/**
* An abstraction over the idea of a search.
*
* @author liberato
*
* @param <T> : generic type.
*/
public abstract class Searcher<T> {
protected final SearchProblem<T> searchProblem;
protected final List<T> visited;
protected List<T> solution;

/**
   * Instantiates a searcher.
   *
   * @param searchProblem
   *            the search problem for which this searcher will find and
   *            validate solutions
   */
public Searcher(SearchProblem<T> searchProblem) {
    this.searchProblem = searchProblem;
    this.visited = new ArrayList<T>();
}

/**
   * Finds and return a solution to the problem, consisting of a list of
   * states.
   * The list should start with the initial state of the underlying problem.
   * Then, it should have one or more additional states. Each state should be
   * a successor of its predecessor. The last state should be a goal state of
   * the underlying problem.
   * If there is no solution, then this method should return an empty list.
   *
   * @return a solution to the problem (or an empty list)
   */
public abstract List<T> findSolution();

/**
   * Checks that a solution is valid.
   * A valid solution consists of a list of states. The list should start with
   * the initial state of the underlying problem. Then, it should have one or
   * more additional states. Each state should be a successor of its
   * predecessor. The last state should be a goal state of the underlying
   * problem.
   *
   * @param solution : solution
   * @return true iff this solution is a valid solution
   * @throws NullPointerException
   *             if solution is null
   */
public final boolean isValidSolution(List<T> solution) {
        // TODO
        return false;
}
}


--------------------------------------------------------------------------------------------------------

package search;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Stack;

/**
* An implementation of a Searcher that performs an iterative search,
* storing the list of next states in a Stack. This results in a
* depth-first search.
*
*/
public class StackBasedDepthFirstSearcher<T> extends Searcher<T> {

/**
   * StackBasedDepthFirstSearcher.
   * @param searchProblem : search problem
   */
public StackBasedDepthFirstSearcher(SearchProblem<T> searchProblem) {
    super(searchProblem);
}

@Override
public List<T> findSolution() {
    // TODO
    return null;
}
}

----------------------------------------------------------------------------------------------------

package search;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

/**
* An implementation of a Searcher that performs an iterative search,
* storing the list of next states in a Queue. This results in a
* breadth-first search.
*
*/
public class QueueBasedBreadthFirstSearcher<T> extends Searcher<T> {

/**
   * QueueBasedBreadthFirstSearcher.
   * @param searchProblem : search problem
   */
public QueueBasedBreadthFirstSearcher(SearchProblem<T> searchProblem) {
    super(searchProblem);
}

@Override
public List<T> findSolution() {
    // TODO
    return null;
}
}


---------------------------------------------------------------------------------

package mazes;

import java.util.List;

import search.Solver;

public class MazeDriver {

/**
   * Supproting main method.
   */
public static void main(String[] args) {
    MazeGenerator mg = new MazeGenerator(24, 8, 0);
    Maze m = mg.generateDFS();
    System.out.println(m.toString());
    Solver<Cell> s = new Solver<Cell>(m);
    List<Cell> r = s.solveWithRecursiveDFS();
    for (Cell cell : r) {
      System.out.println(cell);
    }
    System.out.println(r.size());
    // System.out.println("--------");
    // List<Cell> d = s.solveWithIterativeDFS();
    // for (Cell cell : d) {
    //    System.out.println(cell);
    // }
    // System.out.println(d.size());
    // System.out.println("--------");
    // List<Cell> q = s.solveWithBFS();
    // for (Cell cell : q) {
    //    System.out.println(cell);
    // }
    // System.out.println(q.size());
}
}


------------------------------------------------------------------------------------------------------------------

package puzzle;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import search.SearchProblem;
import search.Solver;

/**
* A class to represent an instance of the eight-puzzle.
* The spaces in an 8-puzzle are indexed as follows:
* 0 | 1 | 2
* --+---+---
* 3 | 4 | 5
* --+---+---
* 6 | 7 | 8
* The puzzle contains the eight numbers 1-8, and an empty space.
* If we represent the empty space as 0, then the puzzle is solved
* when the values in the puzzle are as follows:
* 1 | 2 | 3
* --+---+---
* 4 | 5 | 6
* --+---+---
* 7 | 8 | 0
* That is, when the space at index 0 contains value 1, the space
* at index 1 contains value 2, and so on.
* From any given state, you can swap the empty space with a space
* adjacent to it (that is, above, below, left, or right of it,
* without wrapping around).
* For example, if the empty space is at index 2, you may swap
* it with the value at index 1 or 5, but not any other index.
* Only half of all possible puzzle states are solvable! See:
* https://en.wikipedia.org/wiki/15_puzzle
* for details.
*

* @author liberato
*
*/
public class EightPuzzle implements SearchProblem<List<Integer>> {

/**
   * Creates a new instance of the 8 puzzle with the given starting values.
   * The values are indexed as described above, and should contain exactly the
   * nine integers from 0 to 8.
   *
   * @param startingValues
   *            the starting values, 0 -- 8
   * @throws IllegalArgumentException
   *             if startingValues is invalid
   */
public EightPuzzle(List<Integer> startingValues) {
}

@Override
public List<Integer> getInitialState() {
    // TODO
    return null;
}

@Override
public List<List<Integer>> getSuccessors(List<Integer> currentState) {
    // TODO
    return null;
}


@Override
public boolean isGoal(List<Integer> state) {
    // TODO
    return false;
}

/**
   * supporting man method.
   */
public static void main(String[] args) {
    EightPuzzle e = new EightPuzzle(Arrays.asList(new Integer[] { 1, 2, 3,
        4, 0, 6, 7, 5, 8 }));

    List<List<Integer>> r = new Solver<List<Integer>>(e).solveWithBFS();
    for (List<Integer> l : r) {
      System.out.println(l);
    }
}
}

In: Computer Science

Using python, please complete these 4 exercises. Please limit your code to these skills: For loop...

Using python, please complete these 4 exercises. Please limit your code to these skills:

For loop

While loop

Input function

F strings

Tuples

Lists

Nested ifs

Elias

Exercise 1

Using the following list, do the following:

  1. Sort it in ascending order
  2. In a print statement, referencing the list and its index numbers, print the lowest value and the highest value.

[15, 70, 15, 38, 49, 98, 62, 89, 2, 21, 40, 74, 36, 36, 65, 1, 55, 16, 24, 56]

Exercise 2 (1 Point):

Using the following list, do the following:

1. Iterate through each element in the list

2. Print out whether the element is positive or negative or zero on a new line for each element.

[-2, 1, -2, 7, -8, -5, 5, 10, -6, 7]

Exercise 3 (2 Points):

Create a new list using the range function, appending the values from the range function's output into the list.

The range function must:

  1. Start at 1
  2. Stop at 50
  3. Skip every other number

Hint: Use either a for loop or a list comprehension

Exercise 4 (6 Points):

In this exercise, you will be required to do the following:

Take the following phrase: The only thing we have to fear is fear itself

  1. Convert it to a list
  2. Inspect each word in the list
    1. If the word in the list starts with a vowel (excluding y), then:
      1. add the letters "way" to the end of the word.
      2. EX: the word "and" would become "andway"
    2. If the word in the list does not start with a vowel (including y), then:
      1. take the first letter from the word and move it to the end of the word
      2. add to the end of the word, the letters "ay"
      3. EX: the word "money" would become "oneymay"
  3. Append each modified word to a new list
  4. convert the list to a string and print that string out
    1. HINT: use join()

So, the end result should be:

Hetay onlyway hingtay eway avehay otay earfay isway earfay itselfway

In: Computer Science

Write a statement that creates a list with the following string numbers:

  1. Write a statement that creates a list with the following string numbers:
          ‘9’, ‘5’, ‘12’, ‘31’, ‘4’, and ‘8’.

Assume listDATA references this data list. Write a for-loop that displays each element of this list and the total of all these numbers

in python programming

In: Computer Science

1. List THREE communication techniques with children. 2. Name FOUR habits to explore during health interview....

1. List THREE communication techniques with children. 2. Name FOUR habits to explore during health interview. 3. List FOUR clinical manifestations of failure to thrive. 4. List FOUR guidelines for assessing toilet training readiness.

In: Nursing

Write powershell scripts to connect to Horizon View server, list all users and last time logged...

Write powershell scripts to connect to Horizon View server, list all users and last time logged in, and list virtual machines powered on and off.

Powershell scripts to connect to Vmware horizon 7 and get list of users and VM's in pod.

In: Computer Science

Given lists L1, L2 and L3, delete all the nodes having even number in info part...

Given lists L1, L2 and L3, delete all the nodes having even number in info part from the list L1 and insert into list L2 and all the nodes having odd numbers into list L3.

Code needed in java.

In: Computer Science

Iterative Linear Search, Recursive Binary Search, and Recursive Selection Sort I need it in Java with...

Iterative Linear Search, Recursive Binary Search, and Recursive Selection Sort

I need it in Java with comments and I need the input file to be placed with Scanner not BufferedReader Please help I need Class River Class CTRiver and Class Driver

Class River describes river’s name and its length in miles. It provides accessor methods (getters) for both variables, toString() method that returns String representation of the river, and method isLong() that returns true if river is above 30 miles long and returns false otherwise.

Class CTRivers describes collection of CT rivers. It has no data, and it provides the following service methods. None of the methods prints anything, except method printLongRiversRec, which prints all long rivers. Input parameter n in all methods is number of occupied elements in the list.

// Prints all long rivers in the list. Print them in same order as they were in the list . List can be

// empy or not.

  • void printLongRiversRec(River[] list, int n)

// Returns index for the river object with given name. Returns -1 for unsuccessful search. List can

// be empy or not.

  • int linearSearch(River[] list, int n, String name)

// Returns ArrayList of rivers with length between min and max inclusive. If no such river was found,

// method returns an empty Arraylist<River>. List can be empy or not.

  • ArrayList <River> searchRange(River[] list, int n, int min, int max)

// Sorts list of rivers by comparing them by names. Apply selection sort recursively. List of rivers can be

// empy or nonempty. Empty list and list with one river only are sorted. Lists with two or more rivers are

// sorted by swapping last river in the list with river object that has name that is last in lexicographic order // in the array, and after that recursively sorting sublist of first n-1 rivers.

  • void sortByNameRec(River[] list, int n)

// PRECONDITION: Method assumes that input list is sorted by names. First and last are indices of the first

// and last river of the current sublist. Method returns index of river object with given name or returns -1

// if none of the rivers has that name. List of rivers can be empy or not.

  • int binarySearchRec(River[] list, int first, int last, String name)

The three methods highlighted in yellow must be implemented recursively.

File “input.txt”

Naugatuck   40

Pawcatuck   34

Quinebaug   69

Shepaug   26

Connecticut   407

Still   25

Quinnipiac   46

Housatoic 139

Class Driver has main method in it. Read data from the input file "input.txt" into an array of River objects, named riverList, and keep track of number of rivers stored in variable counter. Array riverList has capacity 100. Input file should be as shown. Program should work for any input file with up to 100 rivers in it.

  • Print all long rivers.
  • Apply one successful and one unsuccessful linear search.
  • Print all rivers with length between min and max (min and max are provided by user). Must use for each loop in the main method to print resulting ArrayList<River> returned by method searchRange .
  • Sort myList by river names, and print sorted list.
  • Apply one successful and one unsuccessful binary search on sorted list.

Must print appropriate explanation in English of all steps performed in outcome.

SUBMIT:

  • Copy of the code for each class and input file in separate rectangle.
  • Picture of program run from BlueJ.
  • Picture of UML diagram.

In: Computer Science

I'm working on a to-do list program in Python 2. I'm trying to delete an item...

I'm working on a to-do list program in Python 2. I'm trying to delete an item from the list and I'm not sure what I'm missing to do that. I haven't been able to get it to delete by string or by index number. Also, I'm trying to get the menu to run again after the user completes the add/delete/etc options. Do I need to put menu() menu_option = int(input("Welcome to your To-Do List. Please choose and option to continue: ")) after each if statement?

def menu():

   print "[1] Add an item to the list\n[2] Delete an item from the list\n[3] Print the list\n[4] Print the list in reverse\n[5] Quit the program"

menu()

menu_option = int(input("Welcome to your To-Do List. Please choose and option to continue: "))

todo_list = []

i = 0

count = 0

while menu_option != 5:

   

   if menu_option == 1:

      addedItem = str(input("Please add an item to the To-Do List. Type 'done' when you have entered all items."))

      if addedItem == 'done':

         break

      todo_list.append(addedItem)

      i += 1

      count += 1

   else: i += 1

   

  

   if menu_option == 2:

      deletedItem = str(input("Please enter the number of the item you would like to delete."))

      todo_list.remove(deletedItem)

    

      print "Item " + str(deletedItem) + " has been deleted"

In: Computer Science

Given an unordered list (defined using the UnorderedList class above), transform it into a Python list.When...

Given an unordered list (defined using the UnorderedList class above), transform it into a Python list.When the input list is empty, the output Python list should be empty as well.Example: When the input unordered list is [1,2,3], the output Python list should be [1,2,3] .

Use the following codes:

class Node:
def __init__(self, data):
self.data = data
self.next = None

def getData(self):
return self.data

def getNext(self):
return self.next

def setData(self, data):
self.data = data

def setNext(self, node):
self.next = node

class UnorderedList:
def __init__(self):
self.head = None

def add(self, data):
newNode = Node(data)
newNode.setNext(self.head)
self.head = newNode

def length(self):
cur = self.head
count = 0
while cur:
cur = cur.getNext()
count += 1
return count

def isEmpty(self):
return self.head == None

def search(self, data):
cur = self.head
while cur:
if cur.getData() == data:
return True
cur = cur.getNext()
return False

def remove(self, data):
if self.head.getData() == data:
self.head = self.head.getNext()
else:
cur = self.head
while cur.getNext() and cur.getNext().getData() != data:
cur = cur.getNext()
if cur.getNext():
cur.setNext(cur.getNext().getNext())

--------------------------------------------------------------------------------

"""
2. transform(lst)
Transform an unordered list into a Python list
Input: an (possibly empty) unordered list
Output: a Python list
"""
def transform(lst):
# Write your code here

In: Computer Science

Complete the following methods in java: Consult the rest of the methods of BigInteger from its...

Complete the following methods in java:

Consult the rest of the methods of BigInteger from its API documentation as needed to solve the following problems.

public static List<BigInteger> fibonacciSum(BigInteger n)

The unique breakdown into Fibonacci numbers can be constructed with a greedy algorithm that simply finds the largest Fibonacci number f that is less than or equal to n. Add this f to the result list, and break down the rest of the number given by the expression n-f the same way. This method should create and return some kind of List that contains the selected Fibonacci numbers in descending order. For example, when called with n = 1000000, this method would return a list that prints as [832040, 121393, 46368, 144, 55].

Your method must remain efficient even if n contains thousands of digits. To achieve this, maintain a list of Fibonacci numbers that you have generated so far initialized with

private static List<BigInteger> fibs = new ArrayList<>();

static { fibs.add(BigInteger.ONE); fibs.add(BigInteger.ONE); }

and then whenever the last Fibonacci number in this list is not big enough for your present needs, extend the list with the next Fibonacci number that you get by adding the last two known Fibonacci numbers. Keeping all your Fibonacci numbers that you have discovered so far in one sorted list would also allow you to do things such as using Collections.binarySearch to quickly determine if something is a Fibonacci number.

In: Computer Science