I just need the 3) Dot Product and 4) Removing a Node really, but you'll probably need to do the first one to understand
Posted: Tue Jul 12, 2022 8:15 am
I just need the 3) Dot Product and 4) Removing a
Node
really, but you'll probably need to do the first one to
understand and complete the last two. You
can do the first one if you like but I don't want to
waste your time because I've already done it. And
theres no need to even do Milestone 2 because its
just how to debug in Intellij.
Please answer and I'll make sure to give you your
thumbs up/upvote!!!
YOU WILL BE NEEDING TO DO THIS ON INTELLIJ BTW, SO THE FOLLOWING CODES NEEDS TO BE ADDED TO THE CLASS
NODE-3. JAVA FILE:
SPARSEVECTOR.JAVA FILE:
this is all the info you need to be able to do it, thanks
Linked Lists and Debugging Procedures for Labs Labs will be run asynchronously with the exception of those in Section 2. Attendance at your scheduled lab section is strongly encouraged, but not required in order to accommodate for those who may not be comfortable meeting in person. You are strongly encouraged to work with a partner within your lab section. The TAs will assist you in finding one, if needed. Have a TA evaluate your progress on each milestone before you move onto the next. The labs are designed to be mostly completed by the end of the lab. If you are unable to complete all of the milestones by the end of the lab, you will have up until 10:00 p.m. CDT on the Monday following the release of the lab to have any remaining milestones graded (on Discord) by a TA during office hours. We suggest you get your milestones checked off as soon as you complete them since office hours tend to become extremely crowded close to the deadline. You will only receive credit for the milestones you have checked off by a TA. Regrades of a milestone are available but only if submitted before the last office hours on the following Monday. There is nothing to submit to Canvas for this lab. IntelliJ is required for this lab as part of this lab involves using a debugger. We recommend that you use IntelliJ for the remainder of this course as it is an extremely useful tool for coding in Java. Sparse vectors A vector is a one-dimensional array of elements. When doing linear algebra operations (e.g. addi- tion, cross product, dot product) in code, it's common to use an array. Sometimes, a large amount of the coefficients are zero. When this occurs, the vector is called sparse. It is a big waste of computational resources to not only store these zeros, but use them in linear algebra operations. In this lab, you'll be creating a sparse vector with linked lists. You should recall that a linked list is a series of Nodes that are connected to one another with a pointer. Iterating over a linked list amounts to traversing the nodes, one by one, until you've found what you're looking for. For example, the figure below shows a diagram of a sparse vector that has length five, but only three non-zero elements. Index: 0 Value: 3 Index: 1 Value: 27 Index: 4 Value: -1 It's important to note the length of a vector is separate from the number of nodes it has. In array. form, the above vector would be: 32700-1
1 Sparse vectors as linked lists Your first step is to download the Node and SparseVector classes from Canvas. Some of the methods are already implemented, such as tostring and trivial getter/setters. In milestone one, you will implement the following method: public void addElement(int index, double element). For now, we'll assume that addElement is valid for increasingly larger indices. That is, every time you add a node to the SparseVector, it will be added to the end of the linked list (so long as it does not exceed the vector's length). You should check the index is valid before adding a node, and alert the user if they've tried to add an element incorrectly. Implement the addElement method so that the following code SparseVector vec = new SparseVector (6); vec.addElement(0, 10.0); vec.addElement(3, -1.1); vec.addElement (5, 32.0); System.out.println(vec); outputs the result: 10.0, 0, 0, -1.1, 0, 32.0 As shown in the figure above for sparse vectors, remember that the zero elements are not included in the linked list. Studying the toString method provided for you in the SparseVector class may help you to understand the structure of the sparse vectors. Note that because zero elements are not included in the linked list, your linked list will likely have several "missing" indices (refer to the sample image above on page 1). Hint: There are three important cases to account for: (1) invalid index, (2) head is null, (3), head is not null. Be aware that this: Node a = b.getNext(); a = new Node (index,value); does not set b's next pointer. Why not? Milestone 1: Implement addElement and show your TA the result of using the code above. What happens if you add one more element at index 1? What about index 10?
2 Debugging By now, you should have a working Sparse Vector class that contains the addElement method. To get to this point, you likely had to do some debugging in order for your code to work correctly. For most of you, this debugging likely consisted of calls to System.out.println() to print out the value of a variable at different points in your program. However, IntelliJ has many built in debugging features that allow for easier debugging. For milestone two, you will need to use some of these debugging tools to go through your program. Take some time to practice using the built-in debugger and familiarize yourself with Step Into, Step Over, and Step Out. The PDF on IntelliJ debugging will likely be a helpful resource. Hint: Learning how to use the IntelliJ debugger will allow you to more quickly debug projects and labs going forward, so it is in your best interest to begin familiarizing yourself with it. Milestone 2: Go through your main method in Sparse Vector using the IntelliJ debugger and walk through- with a TA to show your understanding of IntelliJ's debugger functionality. • Explain the difference between Step Over and Step Into. • Give a situation where using Step Over instead of Step Into would be desirable. Explain what Step Out does. 3 Dot product Now that we can create sparse vectors, let's do some linear algebra. The dot product of two vectors consists of multiplying the entries of the same indices from both vectors, and summing all those products together to get the result. Therefore it follows that both vectors must be the same length for the dot product to be valid. For example, if x = [a, b, c] and y = [d, e, f, then x.y=ad+be+c* f. If your vectors were stored as an array, determining the dot product of two vectors a and b would look like for (int i=0; i
Node
really, but you'll probably need to do the first one to
understand and complete the last two. You
can do the first one if you like but I don't want to
waste your time because I've already done it. And
theres no need to even do Milestone 2 because its
just how to debug in Intellij.
Please answer and I'll make sure to give you your
thumbs up/upvote!!!

YOU WILL BE NEEDING TO DO THIS ON INTELLIJ BTW, SO THE FOLLOWING CODES NEEDS TO BE ADDED TO THE CLASS
NODE-3. JAVA FILE:
SPARSEVECTOR.JAVA FILE:
this is all the info you need to be able to do it, thanks
Linked Lists and Debugging Procedures for Labs Labs will be run asynchronously with the exception of those in Section 2. Attendance at your scheduled lab section is strongly encouraged, but not required in order to accommodate for those who may not be comfortable meeting in person. You are strongly encouraged to work with a partner within your lab section. The TAs will assist you in finding one, if needed. Have a TA evaluate your progress on each milestone before you move onto the next. The labs are designed to be mostly completed by the end of the lab. If you are unable to complete all of the milestones by the end of the lab, you will have up until 10:00 p.m. CDT on the Monday following the release of the lab to have any remaining milestones graded (on Discord) by a TA during office hours. We suggest you get your milestones checked off as soon as you complete them since office hours tend to become extremely crowded close to the deadline. You will only receive credit for the milestones you have checked off by a TA. Regrades of a milestone are available but only if submitted before the last office hours on the following Monday. There is nothing to submit to Canvas for this lab. IntelliJ is required for this lab as part of this lab involves using a debugger. We recommend that you use IntelliJ for the remainder of this course as it is an extremely useful tool for coding in Java. Sparse vectors A vector is a one-dimensional array of elements. When doing linear algebra operations (e.g. addi- tion, cross product, dot product) in code, it's common to use an array. Sometimes, a large amount of the coefficients are zero. When this occurs, the vector is called sparse. It is a big waste of computational resources to not only store these zeros, but use them in linear algebra operations. In this lab, you'll be creating a sparse vector with linked lists. You should recall that a linked list is a series of Nodes that are connected to one another with a pointer. Iterating over a linked list amounts to traversing the nodes, one by one, until you've found what you're looking for. For example, the figure below shows a diagram of a sparse vector that has length five, but only three non-zero elements. Index: 0 Value: 3 Index: 1 Value: 27 Index: 4 Value: -1 It's important to note the length of a vector is separate from the number of nodes it has. In array. form, the above vector would be: 32700-1
1 Sparse vectors as linked lists Your first step is to download the Node and SparseVector classes from Canvas. Some of the methods are already implemented, such as tostring and trivial getter/setters. In milestone one, you will implement the following method: public void addElement(int index, double element). For now, we'll assume that addElement is valid for increasingly larger indices. That is, every time you add a node to the SparseVector, it will be added to the end of the linked list (so long as it does not exceed the vector's length). You should check the index is valid before adding a node, and alert the user if they've tried to add an element incorrectly. Implement the addElement method so that the following code SparseVector vec = new SparseVector (6); vec.addElement(0, 10.0); vec.addElement(3, -1.1); vec.addElement (5, 32.0); System.out.println(vec); outputs the result: 10.0, 0, 0, -1.1, 0, 32.0 As shown in the figure above for sparse vectors, remember that the zero elements are not included in the linked list. Studying the toString method provided for you in the SparseVector class may help you to understand the structure of the sparse vectors. Note that because zero elements are not included in the linked list, your linked list will likely have several "missing" indices (refer to the sample image above on page 1). Hint: There are three important cases to account for: (1) invalid index, (2) head is null, (3), head is not null. Be aware that this: Node a = b.getNext(); a = new Node (index,value); does not set b's next pointer. Why not? Milestone 1: Implement addElement and show your TA the result of using the code above. What happens if you add one more element at index 1? What about index 10?
2 Debugging By now, you should have a working Sparse Vector class that contains the addElement method. To get to this point, you likely had to do some debugging in order for your code to work correctly. For most of you, this debugging likely consisted of calls to System.out.println() to print out the value of a variable at different points in your program. However, IntelliJ has many built in debugging features that allow for easier debugging. For milestone two, you will need to use some of these debugging tools to go through your program. Take some time to practice using the built-in debugger and familiarize yourself with Step Into, Step Over, and Step Out. The PDF on IntelliJ debugging will likely be a helpful resource. Hint: Learning how to use the IntelliJ debugger will allow you to more quickly debug projects and labs going forward, so it is in your best interest to begin familiarizing yourself with it. Milestone 2: Go through your main method in Sparse Vector using the IntelliJ debugger and walk through- with a TA to show your understanding of IntelliJ's debugger functionality. • Explain the difference between Step Over and Step Into. • Give a situation where using Step Over instead of Step Into would be desirable. Explain what Step Out does. 3 Dot product Now that we can create sparse vectors, let's do some linear algebra. The dot product of two vectors consists of multiplying the entries of the same indices from both vectors, and summing all those products together to get the result. Therefore it follows that both vectors must be the same length for the dot product to be valid. For example, if x = [a, b, c] and y = [d, e, f, then x.y=ad+be+c* f. If your vectors were stored as an array, determining the dot product of two vectors a and b would look like for (int i=0; i