CS445 Recitation 7:25pm8:15pm - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

CS445 Recitation 7:25pm8:15pm

Description:

Your class should perform similarly to Java's ArrayList T class. BUT YOU ARE NOT ALLOWED TO DIRECTLY OR IN DIRECTLY USE Java's ArrayList T class. ... – PowerPoint PPT presentation

Number of Views:80
Avg rating:3.0/5.0
Slides: 16
Provided by: sys49
Category:

less

Transcript and Presenter's Notes

Title: CS445 Recitation 7:25pm8:15pm


1
CS445 Recitation725pm-815pm
  • Feb 6 8, 2007 (T,H)
  • The first test will be Tuesday February 13.
  • There will be no recitations during test week.

2
An opportunity
  • FYI GoldenGate is opening a small office in
    Pittsburgh which may expand if successful. This
    company definitely has a lot of potential to be a
    good partner for us.
  • GoldenGate Software Pre-Interview Meeting
    GoldenGate Software of San Francisco, CA is
    hiring talented software graduates. They have a
    pre-interview meeting on Feb. 12 at 5pm, where
    you will get the chance to meet with GoldenGate's
    top engineering and technology executives. For
    more information, read the flyer on the CS Home
    page. Make sure to you bring your resume.
    Refreshments will be provided.

3
Homework 3
  • Problem statement
  • In the Euclidean Traveling Salesman Problem (TSP)
    you are given a set of cities (which are points
    in the plane) and are asked to find a shortest
    tour that connects all of them and returns to the
    starting city. The problem is equivalent to many
    important practical problems.
  • Greedy Search
  • Greedy Search is a simple, yet relatively
    effective. algorithm that starts with a city and
    always adds the city closest to the most recently
    added. Briefly, this can be stated as
  • Add the starting city to the tour.
  • While there are unvisited cities
  • Find the city closest to the last visited city.
  • Add it to the tour.
  • Add the starting city to the tour.

4
Homework 3
1
2
3
4
5
7
8
0
6
a
1
b
2
c
d
e
3
f
4
5
5
Homework 3
1
2
3
4
5
7
8
0
6
a
1
b
2
c
d
e
3
f
4
5
Start from a, the tour is a, c, f, d, b, e, a
6
Homework 3
1
2
3
4
5
7
8
0
6
a
1
b
2
c
d
e
3
f
4
5
Start from b, a tour is b, d, e, f, c, a, b
7
Homework 3
1
2
3
4
5
7
8
0
6
a
1
b
2
c
d
e
3
f
4
5
Start from b, another tour is b, e, d, f, c, a,
b
8
Homework 3
  • First, you will implement the class
    MyArrayListltTgt with the following methods
  • public MyArrayList() creates a new list.
  • public T add(T element) adds an element at the
    end and returns it.
  • public T add(int index, T element) adds an
    element at index and returns it.
  • public T get(int index) returns the element at
    index.
  • public T remove(int index) removes the element at
    index.
  • public boolean contains(T element) looks for
    element.
  • public int size() returns the size of the list.
  • public String toString() returns a string
    suitable for printing.
  • Your class should perform similarly to Java's
    ArrayListltTgt class. BUT YOU ARE NOT ALLOWED TO
    DIRECTLY OR IN DIRECTLY USE Java's ArrayListltTgt
    class. In particular, there should be no
    arbitrary limit on the size of the list, and
    retrieval with get() should require only a
    constant amount of time.

9
Homework 3
  • Two examples earn no or few points

import java.util.ArrayList
//
Absolutely no point public class MyArrayListltTgt
extends ArrayListltTgt
import java.util.ArrayList public class
MyArrayListltTgt private ArrayListltTgt elements
public MyArrayList() elements new
ArrayListltTgt() public T add(T element)
elements.add(element) return element public
T add(int index, T element) elements.add(index,
element) return element public T remove(int
index) T element elements.get(index)
elements.remove(index) return element public
String toString()
// MAYBE some partial points
for this method String result "" for
(int i 0 i lt elements.size() i) result
elements.get(i) " " return result

10
Homework 3
  • Second, you will implement the City class which
    must have an appropriate toString() method.

11
Homework 3
  • Third, you will implement the TravelingSalesman
    class with the following methods
  • public TravelingSalesman() constructs a new TSP.
  • public void addCity(String n, int x, int y) adds
    a city to the TSP.
  • public MyArrayListltCitygt tour(String c) greedily
    finds a tour.
  • In addition, you should probably implement a few
    auxiliary classes to help solve this problem.

12
Homework 3
  • Documentation
  • All of your files should include a header with
    your name and email address.
  • Your code should be cleanly designed, logically
    organized, and easy to follow. Document any
    tricky or subtle parts of the code.
  • You also need to include the files
  • README contains brief documentation in
    plain-text.
  • DemonstrateTSP.java demonstrates your code.
  • You can use Dr. Aroniss files TSP-README and
    DemonstrateTSP.java (in the miscellaneous
    directory) as examples.
  • If you cannot finish this project, document what
    you have in the README file and drive any parts
    that work in DemonstrateTSP.java. Make it easy
    for us to award partial credit!

13
Homework 3
  • Bundle your files with tar or zip and submit it
    to
  • /afs/cs.pitt.edu/public/incoming/aronis/cs445/home
    work-3/xxx.tar
  • or
  • /afs/cs.pitt.edu/public/incoming/aronis/cs445/home
    work-3/xxx.zip
  • where XXX indicates how you bundled your
    files.
  • How to use tar
  • Create a tar file
  • tar -cf ShuyiShao.tar README MyArrayList.java
    City.java DemonstrateTSP.java
  • List all files in ShuyiShao.tar verbosely
  • tar tvf ShuyiShao.tar
  • Extract all files from ShuyiShao.tar
  • tar xf ShuyiShao.tar
  • This project is due Friday February 16 at
    1159pm.

14
Hw2 grading policies
  • No significant problems 10 points
  • Minor problems 8 points
  • Major problems 6 points
  • Doesn't work 4 points
  • Handed something in 2 points

15
HW 2 Solution
  • Good for recursion
Write a Comment
User Comments (0)
About PowerShow.com