Question

True False Question 2 (3 points) Given a singly linked list with more than two nodes, to remove the second node from a linked
Question 3 (3 points) Given the following singly linked list (a list with four nodes), what will be the value stored at the l
Question 4 (3 points) If the numbers 3, 8, 2, 4, 6, is added to a stack, in the order given. Then being removed from the stac
eu rt or Question 5 (3 points) (Bonus) Below shows a recursive method that can recognize whether a String parameter consists
Which of the following statement is not true? eu There is a recursive sum method as shown below. When sum (19) is called, sum
t ba Question 7 (3 points) The following code is executed and a NullPointerException arises in m20. Assume m20 method does no
d queu it is caught in main import nust pa Question 8 (3 points) on. For What does the following recursive method determine?
O returns true if b contains more elements than a, false otherwise eu returns true if as element value is larger than b, fal
jeu Question 10 (3 points) Which of the following methods could be used to sum all of the items in the singly linked list? or
public int sumito eu Node temp-head: ort pa or while (temp != null) { sum +-temp.item; temp - temp.next; return sum: nes Ques
0 0
Add a comment Improve this question Transcribed image text
Answer #1

1)curr=head.next so it points to second node. If we wnat to delete second node we have to point the first node to third node which is curr.next

head.next=curr.next (Option 2)

2)8 Option 1

whatever te reasons maybe but tatlast we are adding the node 8 to it so it becomes the last nodes and the previous nodes will be 22->27->32->34->8

3)Stack is last in first out and Queue will be First In First out s, whatever the value will be moved last into queue will be last one to be come out

3 8 2 4 6 are the values which are pushed to stack and top value is 6 as it is the last entered value and it will be the first to come ot of stack and the last value to come ot of stack is 3 and it will be the last to be added into queue

Otput is 3 (Option 3)

4)we have the string rotator

Here inside the function it satisfies 3rd elseif condition where first character and last character is equal so here it is equal so it calls the recursion by removing first and last chacter

otato Here also it is same we have first and last character same It removes them and calls again

tat Same like above.

a this is the last recursion where it's lenght is 1 so as per second if condition it returns TRUE

Option 1

5)The Option 1

Here it starts adding from 19 itself not less than 19 and also when it reaches to sum(1) using recursion it calls sum(1-2) which is sum(-1) which not equals to zero . It goes to recursive memory exhaustion.

It is false

6)As the m2 does not have mechanism to throw the errors it can't be caugfht.

It will terminate the program

Option 2

7)

It returns true if b contains more values otherwise false Because this is the only condition where it reaches to second if condition and 'b' and retrns true otherwise false

We may hve scenarios regarding false but according to these options it is correct

Option 2

8)In qeue the elements will come out in the same mannner as they enter

3 8 2 4 6 (3 is added first it will come out first)

In stack it will be last in first out and first in last out.

The value 3 will be pushed frst into the stack so it will be the lsat to come

Option 4

9)Option 4

Until last node it will traverse and adds the value

10)p(5)=p(4)+p(3)

p(4)=p(3)+p(2)

p(3)=p(2)+p(1)=3+2=5

p(4)=5+3=8

p(5)=8+5=13

Option 2

Add a comment
Know the answer?
Add Answer to:
True False Question 2 (3 points) Given a singly linked list with more than two nodes,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Question 2 (3 points) Given the following singly linked list (a list with four nodes), what...

    Question 2 (3 points) Given the following singly linked list (a list with four nodes), what will be the value stored at the last node when the following operations are executed? head->1111-151->11011->1211 Node curr = head; while(curr next !=null) { curr.item = curritem-head. item; curr = cur next; اسرة Node newNode = new Node(8): curr.next = newNode: 23 O 12 OS O21 Question 3 (3 points) Given a recursive method as shown below, what is the return value for P(5)...

  • Question 10 (3 points) Which of the following statement is not true? There is a recursive...

    Question 10 (3 points) Which of the following statement is not true? There is a recursive sum method as shown below. When sum (19) is called, summation of all odd numbers less than 19 will be calculated and returned public int sum(int x){ if (x == 0) return 0: else return sum(x-2) + x; The following code segment will throw a testException. This exception has been handled in the way that do nothing but to continue when this exception happens....

  • 1)Given a singly linked list contains four nodes and simply show as 4->3->2->1, where the head...

    1)Given a singly linked list contains four nodes and simply show as 4->3->2->1, where the head reference refers to the first node contains an Integer with value 4. If Node curr = head; curr= curr.next; are applied to this list, what is the number you can find in the first node? 2) Given a singly linked list contains 6 nodes, which is simply shown as 1->2->3->4->5->6. Assume head refers to the first node (contains 1) on the list. How many...

  • iImplement a Singly Linked List detectLoop in Java, it would check whether the linked list contains...

    iImplement a Singly Linked List detectLoop in Java, it would check whether the linked list contains a loop. Print true if yes, false if not. Test by using the following code: LL<Integer> L = new LL<>(); for (int i = 1000; i > 0; i-=3) sl.add(i); try { L.insert(122, L.getNode(70), L.getNode(21)); if (L.detectLoop()) System.out.println("True"); else System.out.println("False."); } catch(Exception e){ e.printStackTrace(); } class Linkedlist<E>{ private static class Node<E>{ private E element; private Node<E> next; public Node(E e, Node<E> n){ element =...

  • Given a singly linked list contains 5 nodes, which simply shows as 5->4->3->2->1, what is the...

    Given a singly linked list contains 5 nodes, which simply shows as 5->4->3->2->1, what is the value that you can find in the second node of the remaining list if the following statements are applied? Assume head reference refers the first node of the list. Node prev = head; Node curr = head. next; while(curr.next!=null) { if(prev.element > 3) { prev = curr; curr = curr.next; } else break; } head = prev.next; Question 3 options: 3 2 4 1...

  • Question 5 (3 points) (Bonus) Below shows a recursive method that can recognize whether a String...

    Question 5 (3 points) (Bonus) Below shows a recursive method that can recognize whether a String parameter consists of a specific pattern and returns true if the String has that pattern, false otherwise. public boolean pattern Recognizer(String 2) return true; if (2 == null) return true; else if (a.length(== 11 |(a.length() == 2&&2.charAt(0) == 2.charAt()))) else if (a.length() == 2 && 2.charAt(0) != a.charAt(1)) return false; else if (a.charAt(0) == a.charAt(a.length() - 1)) retum patterRecognizer(a substring(1, a.length() - 1)): else...

  • Data Structures - Singly Linked Lists You will add a method swapNodes to SinglyLinkedList class (below). This method should swap two nodes node1 and node2 (and not just their contents) given reference...

    Data Structures - Singly Linked Lists You will add a method swapNodes to SinglyLinkedList class (below). This method should swap two nodes node1 and node2 (and not just their contents) given references only to node1 and node2. The new method should check if node1 and node2 are the same node, etc. Write the main method to test the swapNodes method. You may need to traverse the list. package linkedlists; public class SinglyLinkedList<E> implements Cloneable {    // ---------------- nested Node class...

  • Given a singly-linked list interface and linked list node class, implement the singly-linked list which has...

    Given a singly-linked list interface and linked list node class, implement the singly-linked list which has the following methods in Java: 1. Implement 3 add() methods. One will add to the front (must be O(1)), one will add to the back (must be O(1)), and one will add anywhere in the list according to given index (must be O(1) for index 0 and O(n) for all other indices). They are: void addAtIndex(int index, T data), void addToFront(T data), void addToBack(T...

  • I am trying to make a linked list queue and I am trying to use the...

    I am trying to make a linked list queue and I am trying to use the display method I made just to see if its working but when I run it nothing is displayed please help. Also the newPlane boolean was made just so I can randomly decide if the plane is going to join the queue or not. public class PlaneSimulation { public static void main(String[] args) { int landTime = 2; int takeoffTime = 3; int avgArrivalInterval =...

  • C++ - I have a doubly linked list, but I haven't been able to get the...

    C++ - I have a doubly linked list, but I haven't been able to get the "reverse list" option in the code to work(It's option #in the menu in the program). I received this guidance for testing: Test 4 cases by entering (in this order) c,a,z,k,l,m This tests empty list, head of list, end of list and middle of list. Then delete (in this order) a,z,l. This tests beginning, end and middle deletes. This exhaustively tests for pointer errors. #include...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT