Download Q1: What kind of linked list begins with a pointer to the first node

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Lattice model (finance) wikipedia , lookup

Quadtree wikipedia , lookup

Red–black tree wikipedia , lookup

Interval tree wikipedia , lookup

Binary search tree wikipedia , lookup

B-tree wikipedia , lookup

Linked list wikipedia , lookup

Transcript
The Islamic University of Gaza
Faculty of Engineering
Department of Computer Engineering
Fall 13-14
ECOM 3408
Data Structures and Algorithms
Quiz# 1
_________________________________ / ‫االسم باللغة العربية‬
_____________________________________ / ‫الرقم الجامعي‬
Q1: What kind of linked list begins with a pointer to the first node, and each node
contains a pointer to the next node, and the pointer in the last node points back to the
first node?
a.
b.
c.
d.
Circular, singly-linked list.
Circular, doubly-linked list.
Singly-linked list.
Doubly-linked list.
Q2: You are given pointers to first and last nodes of a singly linked list, which of the
following operations are dependent on the length of the linked list?
a.
b.
c.
d.
Delete the first element
Insert a new element as a first element
Delete the last element of the list
Add a new element at the end of the list
Q3: What does the following function do for a given Linked List with first node as head?
void fun1(Node head)
{
if(head == null)
return;
fun1(head.getNext());
System.out.println(head.getElement());
}
a.
b.
c.
d.
Prints all nodes of linked lists
Prints all nodes of linked list in reverse order
Prints alternate nodes of Linked List
Prints alternate nodes in reverse order
Q4: In general, linked lists allow:
a.
b.
c.
d.
Insertions and removals anywhere.
Insertions and removals only at one end.
Insertions at the back and removals from the front.
None of the above.
Q5: Given that each node in a linked list has a previous pointer and a next pointer; the
list contains a pointer to the tail; and we have a node x that we wish to insert at the end.
Which of the following will successfully append the node to the non-empty list?
a.
b.
c.
d.
e.
f.
tail = x ; x.setPrev(tail) ; tail.setNext(x) ;
tail.setPrev(x) ; x.setNext(tail) ; tail = x ;
x = tail ; tail.setNext(x) ; x.setPrev(tail) ;
tail.setNext(x) ;x.setPrev(tail) ; tail = x ;
tail.setNext(x) ;x.setPrev(tail) ; x = tail ;
x.setNext(tail) ; tail.setPrev(x) ; tail = x ;
Q6: Which of the following points is/are true about Linked List data structure when it is
compared with array? (You may choose more than one answer if you want)
a.
b.
c.
d.
e.
Arrays have better cache locality that can make them better in terms of performance.
It is easy to insert and delete elements in Linked List
Random access is not allowed in a typical implementation of Linked Lists
The size of array has to be pre-decided, linked lists can change their size any time.
All of the above
Q7: Recursion is memory-intensive because:
a.
b.
c.
d.
Recursive functions tend to declare many local variables.
Previous function calls are still open when the function calls itself and the activation records
of these previous calls still occupy space on the call stack.
Many copies of the function code are created.
It requires large data values
Q8: How many pointers are contained as data members in the nodes of a circular,
doubly linked list of integers with five nodes?
a.
b.
c.
d.
5
8
10
15
Q9: Which of the following will successfully delete a node pointed to by x in the middle
of a non-empty list?
a.
b.
c.
d.
x.setPrev(x.getNext()) ; x.setNext(x.getPrev()) ; delete x ;
x.getNext().setPrev(x.getPrev()) ;x.getPrev().setNext(x.getNext()); delete x ;
x.getNext().setPrev(x.getPrev().getNext()) ;
x.getPrev().setNext(x.getNext().getPrev()) ;delete x ;
x.setNext(x.getPrev()) ; x.setPrev(x.getNext()) ; delete x ;
Q10: What value does function mystery return when called with a value of 4?
int mystery ( int number )
{
if ( number <= 1 )
return 1;
else
return number * mystery( number – 1 );
}
a.
b.
c.
d.
0
1
4
24
Q11: Write a method that will delete a node containing a given information in singly
linked list L1.
ANSWER:
void deleteNode( Node node )
{
AnyType data = node.getData();
Node cur = head;
While(cur.getNext()!= null)
{
if(cur.getData().equals(data))
{
delNode(cur);
return;
}
else
cur = cur.getNext();
}
}
Q12: Write a method that will calculate the size of a given linked list L1.
ANSWER:
public static int listLength(IntNode head)
{
IntNode cursor;
int answer;
answer = 0;
for (cursor = head; cursor != null; cursor = cursor.next())
answer++;
return answer;
}