Test Yourself No Marks: Public Void Removeallnodesequaltovalue (T Value)
Test Yourself No Marks: Public Void Removeallnodesequaltovalue (T Value)
Q1: Here we have two generic classes, one for nodes in a linked list and one for linked
lists. You need to write the implementation for one method in the linked list class.
public class Node<T> {
public T data;
public Node next;
public void
removeAllNodesEqualToValue (T value)
that removes all the nodes with the given value from the linked list. For
example, if you have the following linked list:
1
Your answer
return 1 + sumArray(start,end);
2
else
return 0;
Your answer
public int sumArray(int a[], int start, int end){
if (start <= end)
return a[start] + sumArray(a, start+1,end);
else
return 0;
}
Call Returns
numberOfEvenDigits (967) 1
numberOfEvenDigits (24) 2
3
numberOfEvenDigits (681) 2
numberOfEvenDigits (-150) 1
Your answer
Q4: Find the number of steps, and then time complexity (Big-O) for the following
algorithms?
1) for (i = n; i> 1; i = i / 2) {
j=0
while(j<n){
4
System.out.println(i);
j++;
}
Your answer
Number of steps = n * log n
Time Complexity = O(n log n)
2) i=1;
while (i<n){
i++;
for(j=1; j < n*n ; j++){
System.out.println(i);
}// end for
}// end while
Your answer
Your answer
Time Complexity = O(n2)