5. Refer to the following lists for the question below: list1: 20 -> 37 -> 45 ->
ID: 3599708 • Letter: 5
Question
5. Refer to the following lists for the question below:
list1: 20 -> 37 -> 45 -> null
list2: 13 -> 29 -> null
To be clear, list1 contains 3 nodes, list2 contains 2 nodes, andlist1.firstNode.data==20;
public void insertIt (Node nodeA, Node nodeB) {
nodeB.next = nodeA.next;
nodeA.next = nodeB;
}
What will list1 contain after calling:
insertIt(list1.firstNode, list2.firstNode);
6. Refer to the following lists for the question below:
list1: 35 -> 49 -> 14 -> null
To be clear, list1 has 3 nodes and list1.firstNode.data == 35;
currentNode = list1.firstNode.next;
currentNode = currentNode.next;
What is the value of currentNode.data ?
A. 35
B. 49
C. 14
D. null
E. None of the above
7. Refer to the following lists for the question below:
list1: 35 -> 49 -> 14 -> null
To be clear, list1 has 3 nodes and list1.firstNode.data == 35;
currentNode = list1.firstNode;
currentNode.next = currentNode.next.next;
currentNode = currentNode.next;
What is the value of currentNode.data ?
A. 35
B. 49
C. 14
D. null
E. none of the above
8. What is the order of growth of T( n ) = 3n^2 + 4n^3 +3 n ?
9. What is the the order of growth for the following algorithm.
for(int i=1; i<=n; i++) {
statement1
for(int j=1; j<=n; j++) {
statement2
for(int k=1; k<=5; k++) {
statement3
}
statement4
}
statement5
}
statement6
10. What is the order of growth for the following algorithm.
statement1
for i=2 to n-1 {
if(condition1) {
for i=1 t n
statement3
} else {
statement3
}
statement5
}
statement6
11. It is always possible to convert an iterative algorithm to a recursive algorithm. True or False?
12. Which property of recursion does the following method violate?
public int callIt (Node r) {
if (r != null)
return r.next;
else
return r;
}
13. Which property of recursion does the following method violate?
public Node callIt(Node r) {
if (r != null)
return callIt(r.next);
else
return r;
}
A.13 -> 20 -> 29 -> nullExplanation / Answer
Hi, I have answered first 4.
Please repost others in separate post.
5.
list1: 20 -> 37 -> 45 -> null
list2: 13 -> 29 -> null
public void insertIt (Node nodeA, Node nodeB) {
nodeB.next = nodeA.next;
13->37 -> 45 -> null
nodeA.next = nodeB;
20 ->13->37 -> 45 -> null
}
What will list1 contain after calling:
insertIt(list1.firstNode, list2.firstNode);
Ans: B. 20 -> 13 -> 37 -> 45 -> null
6)
list1: 35 -> 49 -> 14 -> null
currentNode = list1.firstNode.next;
currentNode = 49 -> 14 -> null
currentNode = currentNode.next;
14 -> null
What is the value of currentNode.data ?
Ans: C. 14
7)
list1: 35 -> 49 -> 14 -> null
currentNode = list1.firstNode;
currentNode = 35 -> 49 -> 14 -> null
currentNode.next = currentNode.next.next;
currentNode = 35 -> 14 -> null
currentNode = currentNode.next;
currentNode = 14 -> null
What is the value of currentNode.data ?
Ans: C. 14
8)
What is the order of growth of T( n ) = 3n^2 + 4n^3 +3 n ?
here 4n^3 > 3n^2 > 3n
So eliminating lower order term : O(n^3)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.