1.
public int function(int x, int n) {
if (n == 0)
return 1;
return x * function(x, n -1);
}
function(3,3) - What is the expected output?
| 3 |
| 12 |
| 9 |
| 27 |
2.
int fun(int x)
{
if(x == 0)
return 1;
else
return fun(x - 1);
}
fun(4)
| 18 |
| 1 |
| 24 |
| 4 |
3.
Which one of the following calls results 6?
int mystery(int n){
if (n == 1)
return 1;
else
return n * mystery(n - 1);
}
| mystery(3) |
| mystery(2) |
| mystery(1) |
|
mystery(6) |
4.
public void push(int new_data)
{
Node new_Node = new Node(new_data);
new_Node.next = head;
new_Node.prev = null;
if (head != null)
head.prev = new_Node;
head = new_Node;
}
The code snippet depicts stack implementation
| True |
| False |
5.
public int function(int x, int n) {
if (n == 0)
return 1;
return x * function(x, n -1);
}
function(3,3) - What is the expected output?
| 3 |
| 12 |
| 9 |
|
27 |
6.
What is the output of the doubly-linked list example below?
Node end = head;
while(end.next != null) {
System.out.println(node.name);
}
| This code will result in an error. |
| Looping to find the first node of the list. |
| Looping until the last node is found. |
| Endless loop |
1. public int function(int x, int n) { if (n == 0) return 1; return x...
1. static int function(int n){ return n * function(n + 1); } If you call the method function(2), the expected output is 3. True False 2. public void push(int new_data) { Node new_Node = new Node(new_data); new_Node.next = head; new_Node.prev = null; if (head != null) head.prev = new_Node; head = new_Node; } The code snippet depicts stack implementation True False 3. A ________ list is a linked data structure that consists of a set of sequentially linked records called...
C LANGUAGE I just need the void push() function, which inserts new node to the front of the list #include<stdio.h> #include<stdlib.h> typedef struct node { int data; struct node *next; } Node; //Creating head a as a global Node* Node *head; /* Given a node prev_node, insert a new node after the given prev_node */ void insertAfter (Node * prev_node, int new_data) { /*1. check if the given prev_node is NULL */ if (prev_node == NULL) { printf ("the given...
---> JAVA PROGRAM Public Static int EXX (int n,int x){ If (x==0){ return 1; } else If (n==1) { return 1; } else { return (n* EXX(n,x-1)); * what is the output when (5,0) *what is the output when (8,1) what is the output when (4,3)
b) Consider the following code. public static int f(int n) if (n == 1) return 0; else if (n % 2 == 0). return g(n/2); else return g(n+1); public static int g(int n) int r = n % 3; if (r == 0) return f(n/3); else if (r == 1) return f(n+2); else return f(2 * n); // (HERE) public static void main(String[] args) { int x = 3; System.out.println(f(x)); (1) (5 points) Draw the call stack as it would...
Improve the speed of public T get(int i) by having it work backward from the end of the array if you attempt to get a member which is closer to the end than the start. This improvement will be tested through timing tests on large lists. The method should still return null if i is not a valid index. Code import java.util.Iterator; public class DLList<T> implements Iterable<T> { private static class Node<T> { public Node<T> prev, next;...
Complete LinkedListCollection.java with following methods: public LinkedListCollection(); public LinkedListCollection(int size); public boolean isEmpty(); public int size(); // Return number of elements in the Collection. public String toString(); public boolean add(T element); // Add an element into the Collection, return true if successful public boolean remove(T target); // Remove the target from Collection, return true if successful public boolean removeAll(T target); // Remove all occurrences of Target, return if successful public void removeDuplicate(); // Remove duplicated element(s) public boolean equals(LinkedListCollection that);...
Suppose you were debugging the push() function of your program. Which of the following variables would be accessible to the debugger before the function is called? static struct node *stack; static struct node *new_node() { int size = sizeof(struct node); return malloc(size); void push(void *value) { struct node *n = new_node(); n->value = value; n->next = stack; stack = n; return malloc(size); void push (void *value) { struct node *n = new_node(); n->value = value; n->next = stack; stack =...
3. Consider the mystery method given. public static int mystery ( int n) [ if (n == 0 ) { return 1; How do we get the values for recurse? else if (n%2 == 0 ) { int recurse = mystery ( n - 1); int result = recurse + n; return result; since n =5, we go to the else statement and do int recurse = mystery(5-1) which equals 4? why is 3 written? else { int recurse =...
Please help me fix my errors. I would like to read and write the text file in java. my function part do not have errors. below is my code import java.io.FileInputStream; import java.io.InputStreamReader; import java.io.FileWriter; import java.io.IOException; public class LinkedList { Node head; class Node { int data; Node next; Node(int d) { data = d; next = null; } } void printMiddle() { Node slow_ptr...
this is i have code for double linked list with insert at sorted list. i have some error that stdout: ------- Error: compilation stderr: ------- InsertDouble.c: In function ‘list* InsertDouble(LIST, int)’: InsertDouble.c:51:14: error: cannot convert ‘list’ to ‘list*’ in assignment Currentptr = *head; // set a pointer which is current one ^ it keep give me this error i am not sure how to fix is anyone possible to help me? #include <stdio.h> #include <stdlib.h> typedef struct list { ...