Data Structures and Performance | Week 4
Course Name: Data Structures and Performance
Course Link: Data Structures and Performance
These are Data Structures and Performance Week 4 Coursera Answers
Programming Assignment: Implement and Test a Linked List
Steps: Create two java files MyLinkedList.java and MyLinkedListTester.java, and upload both files in their respective columns.
MyLinkedList.java:
package textgen;
import java.util.AbstractList;
public class MyLinkedList<E> extends AbstractList<E> {
LLNode<E> head;
LLNode<E> tail;
int size;
public MyLinkedList() {
this.head = new LLNode<>(null);
this.tail = new LLNode<>(null);
this.head.next = tail;
this.tail.prev = head;
}
public boolean add(E element) {
if (element == null) {
throw new NullPointerException("List can't take null");
}
LLNode<E> newNode = new LLNode<>(element);
newNode.prev = tail.prev;
newNode.next = tail;
tail.prev.next = newNode;
tail.prev = newNode;
this.size++;
return true;
}
public E get(int index) {
if (index >= size || index < 0) {
throw new IndexOutOfBoundsException("MyLinkedList get method index outOfBound : " + index);
} else {
LLNode<E> targetNode = getNode(index);
return targetNode.data;
}
}
private LLNode<E> getNode(int index) {
LLNode<E> currentNode = head;
for (int i = 0; i <= index; i++) {
currentNode = currentNode.next;
}
return currentNode;
}
public void add(int index, E element) {
if (element == null) {
throw new NullPointerException("List can't take null");
}
if (index > size || index < 0) {
throw new IndexOutOfBoundsException("LLNode add failed: " + index);
}
LLNode<E> newNode = new LLNode<>(element);
LLNode<E> node = getNode(index);
newNode.prev = node.prev;
newNode.next = node;
newNode.prev.next = newNode;
node.prev = newNode;
this.size++;
}
public int size() {
return size;
}
public E remove(int index) {
if (index >= size || index < 0) {
throw new IndexOutOfBoundsException("LLNode remove outOfBound: " + index);
}
LLNode<E> targetNode = getNode(index);
targetNode.prev.next = targetNode.next;
targetNode.next.prev = targetNode.prev;
this.size--;
return targetNode.data;
}
public E set(int index, E element) {
if (element == null) {
throw new NullPointerException("List can't take null");
}
if (index >= size || index < 0) {
throw new IndexOutOfBoundsException("LLNode set failed: " + index);
}
LLNode<E> node = getNode(index);
E oldValue = node.data;
node.data = element;
return oldValue;
}
public String toString() {
String output = "";
LLNode<E> curNode = head;
while (curNode != null) {
output += curNode.toString();
curNode = curNode.next;
}
return output;
}
}
class LLNode<E> {
LLNode<E> prev;
LLNode<E> next;
E data;
public LLNode(E e, LLNode<E> prev) {
this(e);
this.prev = prev;
if (prev != null) {
prev.next = this;
}
}
public LLNode(E e) {
this.data = e;
this.prev = null;
this.next = null;
}
public String toString() {
return "prev: " + prev + " ,data = " + data + ", next" + next + "\n";
}
}
These are Data Structures and Performance Week 4 Coursera Answers
MyLinkedListTesting.java:
Answer: Please login to see answer.
These are Data Structures and Performance Week 4 Coursera Answers
Week 4 Reflective Programming Assignment Quiz
Q1. How much time did it take to complete the MyLinkedList project (both implementation and tester)?
- < 1 hour
- 1-2 hours
- 2-3 hours
- 3-4 hours
- 4-5 hours
- 5+ hours
Answer: Please login to see answer.
These are Data Structures and Performance Week 4 Coursera Answers
Q2. How difficult would you rate the MyLinkedList assignment relative to other programming projects you’ve done (in and outside this course)?
- Extremely easy
- Easy
- Somewhat Easy
- Somewhat Difficult
- Difficult
- Extremely Difficult
Answer: Please login to see answer.
These are Data Structures and Performance Week 4 Coursera Answers
Q3. Did you enjoy the MyLinkedList programming assignment?
- I really enjoyed the programming assignment
- I enjoyed the programming assignment
- I am neutral about the programming assignment
- I did not enjoy the programming assignment
- I really did not enjoy the programming assignment
Answer: Please login to see answer.
These are Data Structures and Performance Week 4 Coursera Answers
Q4. Please tell us, in 1-2 sentences, what was the trickiest part for you about the MyLinkedList assignment (including either implementation or testing).
Answer: Please login to see answer.
These are Data Structures and Performance Week 4 Coursera Answers
Q5. Did you do the optional Markov Text Generation Project?
- Yes, and I got it working!
- Yes, but I didn’t quite finish it or didn’t quite get it working completely
- No
Answer: Please login to see answer.
These are Data Structures and Performance Week 4 Coursera Answers
Q6. How long did you work on the Markov Text Generator Extension?
- Not applicable (I didn’t work on the Markov Text Generator)
- < 1 hour
- 1-2 hours
- 2-3 hours
- 3-4 hours
- 4 hours
These are Data Structures and Performance Week 4 Coursera Answers
Q7. How difficult would you rate the Markov Text Generator extension relative to other programming projects you’ve done (in and outside this course)?
- Extremely easy
- Easy
- Somewhat easy
- Somewhat hard
- Hard
- Extremely hard
Answer: Please login to see answer.
These are Data Structures and Performance Week 4 Coursera Answers
Q8. Did you enjoy the programming assignment on Markov Text Generation
- Not applicable
- I really enjoyed the programming assignment.
- I enjoyed the programming assignment.
- I am neutral about the programming assignment.
- I did not enjoy the programming assignment.
- I really did not enjoy the programming assignment.
Answer: Please login to see answer.
These are Data Structures and Performance Week 4 Coursera Answers
Q9. Please tell us, in 1-2 sentences, what was the trickiest part for you about the Markov Text Generator extension (including either implementation or testing).
Answer: Please login to see answer.
These are Data Structures and Performance Week 4 Coursera Answers
More Weeks of the course: Click Here
More Coursera courses: https://progiez.com/coursera