0% found this document useful (0 votes)
15 views

Mid 2021-2022

The document is a midterm exam for a data structures course. It contains 10 multiple choice questions testing concepts like linked lists, time complexity, and pointers. It also contains 4 programming questions requiring the implementation of linked list functions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Mid 2021-2022

The document is a midterm exam for a data structures course. It contains 10 multiple choice questions testing concepts like linked lists, time complexity, and pointers. It also contains 4 programming questions requiring the implementation of linked list functions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Suez Canal University

Faculty of Computers and Informatics


Computer Science Department
Course Name: Data Structures Date:24-11-2021
Course Code: CS513 Time allowed: 1:30 hours
nd
Year: 2 year No. of Pages: 2 pages
Semester: First Total marks: 20
Midterm Exam – Academic Year 2021-2022
Answer all the following questions.
Question 1: Choose the Correct Answer. [5 Marks]
1. Suppose that p is a pointer variable that contains the NULL pointer, what happens if your program
tries to read or write *p?
a) A syntax error always occurs at b) A runtime error always occurs when *p
compilation time is evaluated
c) A runtime error always occurs when the d) The results are unpredictable
program finishes
2. Which of the following code segment deletes the node pointed to by q from a doubly linked list if
it is assumed that q points to the first node in the list and l pointer points to the beginning of the
list.
a) q->prev=q->next;q->next=q->prev; b) l=q->next;q->next=NULL;
c) l=q->next;l->prev=NULL; d) q->prev->prev=q->prev;q->next->next=q->next;
3. Consider a singly linked list where f is a pointer to the first node and l is a pointer to the last node
in the list. The time of which of the following operations depends on the length of the list?
a) Delete the first node of the list b) Delete the last node of the list
c) Add a node after the last node of the list d) Interchange the first 2 elements of the list
4. In linked list each node contain minimum of two fields. One field is data field to store the data
second field is?
a) Pointer to character b) Pointer to integer c) Pointer to node d) node
5. Which of the following operations is performed more efficiently by doubly linked list than by
singly linked list?
a) Deleting a node whose location in given b) Inverting a node after the node with given
location
c) Searching of an unsorted list for a given d) Traversing a list to process each node
item
6. A variation of linked list is circular linked list, in which the last node in the list points to first node
of the list. One problem with this type of list is?
a) It is not possible to add a node at the end b) It waste memory space since the pointer head
of the list. already points to the first node and thus the list
node does not need to point to the first node.
c) It is difficult to traverse the list as the d) All of them
pointer of the last node is now not
NULL
7. What kind of linked list is best to answer question like “What is the item at position n?”
a) Singly linked list b) Circular linked list
c) Doubly linked list d) Array implementation of linked list
8. In doubly linked lists, traversal can be performed?

Page 1 of 2
a) Only in forward b) Only in reverse c) In both directions d) None of them
direction direction
9. What does the following function do for a given Linked List with first node as start?

void f(node* start){


if(start==NULL) return;
printf(("%d ", start->info); f(start->next); }

a) Prints odd nodes of Linked List b) Prints nodes of Linked List in reverse order
c) Prints even nodes of Linked List d) Prints nodes of Linked List without reversing.
10. Suppose cursor refers to a node in a linked list (using the node class with instance variables called
data and link). What Boolean expression will be true when cursor refers to the tail node of the
list?
a) (cursor == NULL) b) (cursor->data == NULL)
c) (cursor->link == NULL) d) None of them
Question 2: Use list and node classes to answer the following question. [15 Marks]
a- What is the output of the following functions if they are members of the list class?
1. void fun1( )
{ node*p,*q;
if(head==NULL) cout<<"list empty.";
if(head->next==NULL) cout<<"still as before.";
else { p=head;
while(p->next!=NULL) { q=p; p=p->next; }
p->next=head; q->next=NULL; head=p; } }

2. void fun2( ) {
node* prev = NULL; node* current = head; node* next;
while (current != NULL)
{ next = current->next; current->next = prev; prev = current; current = next; }
head=prev; }

b- Using node and circularList classes, write a function void modifyNode (int n , int val) which
is used to modify the data of the node at position n in a circular list to be val.

c- Using node and doublyList classes, write a function void printOddInReverse ( ) which is
used to print odd nodes of a doubly linked list in reverse order.

d- Compute the running time for the following code segment.


int matrix[n][n] = { { 1, 2, 3 }, { 4, 5, 6 },{ 7, 8, 9 } };
char op; int i , j;
if(op ==’p’)
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++)
cout << matrix[i][j]; }
else cout<<”invalid operation”;
Dr. Safa Abd El-aziz Ahmed

Page 2 of 2

You might also like