1. Homepage
  2. Programming
  3. PITT CS445 Algorithms and Data Structures I Project 2: LinkedDS

PITT CS445 Algorithms and Data Structures I Project 2: LinkedDS

Engage in a Conversation
PITTCS445CS0445Algorithms and Data Structures ILinkedDSJava

Algorithms and Data Structures I CourseNana.COM

Project 2: LinkedDS[1] CourseNana.COM

Background

This project is designed to increase your experience with linked data structures. Similar to Project 1, you will work with control structures, class-building, interfaces, and generics to create a new linked data structure called a LinkedDS<T>. The LinkedDS<T> will implement the SequenceInterface<T>, so before doing anything else, take a look at the method comments in SequenceInterface.java. CourseNana.COM

  CourseNana.COM

After you finish reviewing SequenceInterface.java, take a look at the client code in Project2.java. Just like Project 1, you cannot modify any of the code in SequenceInterface.java or Project2.java. CourseNana.COM

  CourseNana.COM

As with most complicated programming assignments, there are multiple ways to implement the SequenceInterface<T> methods, some more efficient than others. The comments in SequenceInterface.java outline the running time (efficiency) requirements for your implementations. I 100% recommend pencil & paper work and drawing pictures to familiarize yourself with the algorithm you’d like to implement before you write any code. CourseNana.COM

  CourseNana.COM

Note: The primary data structure in your LinkedDS<T> must be a one-dimensional array of linked lists. You may not use any predefined Java collection class (e.g. ArrayList) for your LinkedDS<T> data fields. You may not declare any one-dimensional arrays except for the alphabet and for the return value of any methods that return an array (declaring a one-dimensional array and then resizing it before returning is OK). CourseNana.COM

LinkedDS

Your LinkedDS<T> class header must be: CourseNana.COM

  CourseNana.COM

public class LinkedDS<T> implements SequenceInterface<T> {  CourseNana.COM

  CourseNana.COM

You must use the following instance variables inside the LinkedDS<T> class: CourseNana.COM

  CourseNana.COM

private Node[] array; // 1-D array of linked lists CourseNana.COM

private int size; // the number of items in the sequence CourseNana.COM

private T[] alphabet; // the possible item values (e.g., the decimal digits) CourseNana.COM

private T firstItem; //the first item CourseNana.COM

private T lastItem; //the last item CourseNana.COM

  CourseNana.COM

The Node private inner class is already defined in LinkedDS.java:: CourseNana.COM

  CourseNana.COM

private static class Node { CourseNana.COM

    private int item; //index in alphabet of item CourseNana.COM

    private Node next; CourseNana.COM

  CourseNana.COM

    private Node(int item){ CourseNana.COM

        this.item = item; CourseNana.COM

        next = null; CourseNana.COM

    } CourseNana.COM

} CourseNana.COM

  CourseNana.COM

Besides the methods in SequenceInterface<T>, the following constructor is required: CourseNana.COM

  CourseNana.COM

public LinkedDS(T[] alphabet) CourseNana.COM

  CourseNana.COM

Here’s an example of how the LinkedDS should work using a 1D array of linked lists. CourseNana.COM

  CourseNana.COM

The alphabet for decimal digits is the same as it was in the example for Project 1: {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}. Remember, your LinkedDS<T> must work on any generic type, not just decimal integers. Just like Project 1, let’s use the sequence 9875732732 as an example. This diagram shows how it would look in a LinkedDS: CourseNana.COM

  CourseNana.COM

  CourseNana.COM

Each of the ten digits of the alphabet is represented by an array of Node objects. Each entry in the array is a Node that serves as the head of a linked list that contains the successors of an item in the sequence, stored by their position in the sequence in ascending order. In the example, the first two lists are empty because 0 and 1 are not in the example sequence (9875732732). CourseNana.COM

  CourseNana.COM

The Node at index 2 (which represents the decimal digit 2) has only one other node in its chain: a 7, meaning that the item at index 7 is what follows 2 in the sequence. There’s only one item in 2’s linked list because 2 is only succeeded by another number once in the sequence. The Node at index 7 (which represents the decimal digit 7) has three nodes because 7, in its three occurrences in 9875732732, is followed by 5, 3, and 3, in that order. Every pair of consecutive items in the sequence results in a node in the diagram. CourseNana.COM

  CourseNana.COM

The sequence 9875732732 has the following properties: CourseNana.COM

  CourseNana.COM

first() == 9 CourseNana.COM

last() == 2 CourseNana.COM

size() == 10 CourseNana.COM

isEmpty() == false CourseNana.COM

getFrequencyOf(3) == 2 CourseNana.COM

getFrequencyOf(2) == 2 CourseNana.COM

getFrequencyOf(7, 3) == 2 //73 appeared twice in the sequence CourseNana.COM

successors(7) == {5, 3} //5 and 3 are the unique items that immediately follow 7 in the sequence CourseNana.COM

  CourseNana.COM

If we start with the example sequence 9875732732 and then call push(7), 7 will be inserted to the beginning of the sequence, it will become 79875732732, and this diagram shows the whole model: CourseNana.COM

  CourseNana.COM

CourseNana.COM

Note that a Node containing 9 was inserted into the beginning of 7’s linked list. This is because 9 is now the first item that comes after a 7 in the sequence. CourseNana.COM

  CourseNana.COM

The sequence 79875732732 has the following properties: CourseNana.COM

  CourseNana.COM

first() == 7 CourseNana.COM

last() == 2 CourseNana.COM

size() == 11 CourseNana.COM

isEmpty() == false CourseNana.COM

getFrequencyOf(3) == 2 CourseNana.COM

getFrequencyOf(2) == 2 CourseNana.COM

getFrequencyOf(7, 3) == 2 //73 appeared twice in the sequence CourseNana.COM

successors(7) == {9, 5, 3} //9, 5, and 3 are the unique items that immediately follow 7 in the sequence CourseNana.COM

  CourseNana.COM

After you have finished implementing LinkedDS<T>, the Project2.java test file should compile and run correctly and give the same output as shown in P2Out.txt. Just like Project 1, I strongly recommend that you stub out the code in Project2.java and test your methods incrementally, instead of all at once at the end. CourseNana.COM

Starter Code

All starter code and example output is available for download from this folder: CourseNana.COM

  CourseNana.COM

Project 2 Starter Code CourseNana.COM

  CourseNana.COM

Deliverables

You are responsible for submitting: CourseNana.COM

-       LinkedDS.java CourseNana.COM

  CourseNana.COM

All other files will be automatically supplied to Gradescope. I would suggest avoiding making code changes to any of the other files (besides stubbing out Project2.java to test parts of your implementations at a time as you work). CourseNana.COM

  CourseNana.COM

If you use Eclipse or any other Java IDEs to work on this project, remember to test on a command line before submitting. Sometimes editors add package lines to the top of .java files that will break the autograder. CourseNana.COM

Hints

-       To create an array of generic types (T) of size length, use this: T[] result = (T[])new Object[length]; CourseNana.COM

-       Adding @SuppressWarnings("unchecked") above that line will prevent your compiler from warning you about the unchecked cast. CourseNana.COM

-       Unlike our linked implementations in class, the Nodes here always contain ints as data. This is because the ints represent the index of the actual T item in the alphabet array. CourseNana.COM

-       See file P2Out.txt to see how your output should look. As noted, your output when running Project2.java should be identical to this. CourseNana.COM

-       Draw pictures! Drawing a picture of a linked chain will be much more helpful when debugging and deciding on an efficient way to implement the different methods. If you have access to a whiteboard, use it! If not, pencil & paper or a tablet will also work fine. CourseNana.COM



[1] Adapted from Dr. Sherif Khattab and Dr. John Ramirez’s coursework CourseNana.COM

Get in Touch with Our Experts

WeChat (微信) WeChat (微信)
Whatsapp WhatsApp
PITT代写,CS445代写,CS0445代写,Algorithms and Data Structures I代写,LinkedDS代写,Java代写,PITT代编,CS445代编,CS0445代编,Algorithms and Data Structures I代编,LinkedDS代编,Java代编,PITT代考,CS445代考,CS0445代考,Algorithms and Data Structures I代考,LinkedDS代考,Java代考,PITThelp,CS445help,CS0445help,Algorithms and Data Structures Ihelp,LinkedDShelp,Javahelp,PITT作业代写,CS445作业代写,CS0445作业代写,Algorithms and Data Structures I作业代写,LinkedDS作业代写,Java作业代写,PITT编程代写,CS445编程代写,CS0445编程代写,Algorithms and Data Structures I编程代写,LinkedDS编程代写,Java编程代写,PITTprogramming help,CS445programming help,CS0445programming help,Algorithms and Data Structures Iprogramming help,LinkedDSprogramming help,Javaprogramming help,PITTassignment help,CS445assignment help,CS0445assignment help,Algorithms and Data Structures Iassignment help,LinkedDSassignment help,Javaassignment help,PITTsolution,CS445solution,CS0445solution,Algorithms and Data Structures Isolution,LinkedDSsolution,Javasolution,