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

Final 2021

The document is a final exam for the Data Structures course (CS 211) held on June 21, 2021, consisting of multiple-choice questions, traversal sequences, and programming tasks related to linked lists and stacks. It includes questions on queue operations, binary search trees, prefix expressions, and complexities of various data structures. The exam is structured to assess students' understanding of key concepts in data structures and algorithms.

Uploaded by

mayadanasr996
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Final 2021

The document is a final exam for the Data Structures course (CS 211) held on June 21, 2021, consisting of multiple-choice questions, traversal sequences, and programming tasks related to linked lists and stacks. It includes questions on queue operations, binary search trees, prefix expressions, and complexities of various data structures. The exam is structured to assess students' understanding of key concepts in data structures and algorithms.

Uploaded by

mayadanasr996
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Final Exam 2021

Course Name: Data Structures Code: CS 211


Marks: 60 Marks Time: 2 Hour
2nd
Year-2nd Semester Date: 21-6-2021
Question 1:- Answer the following questions:- (25 marks)
I. Fill in the table below with the correct answer. Only answers in this table will be
corrected:-
Question 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
No.
Answer

1. The essential condition which is checked before insertion in a linked queue is?
a) Underflow b) Overflow
c) Front value d) Rear value
2. In linked list implementation of a stack, from where is the item deleted?
a) the head of link list b) the centre position of link list
c) the tail of the link list d) Node before the tail
3. In linked list implementation of a queue, front and rear pointers are tracked. Which of these
pointers will change during an insertion into a NONEMPTY queue?
a) Only front pointer b) Only rear pointer
c) Both front and rear pointer d) No pointer will be changed
4. Minimum number of queues to implement stack is ___________
a) 3 b) 4 Eng. Moataz Said
c) 1 d) 2 Both answers are accepted
5. Linked list data structure offers considerable saving in _____________
a) Computational Time b) Space Utilization
c) Space Utilization and Computational Time d) Speed Utilization
6. What kind of linked list is best to answer questions like “What is the item at position n?”
a) Singly linked list b) Doubly linked list
c) Circular linked list d) Array implementation of linked list
7. Assume a single linked list with head pointer and its current content is 1->2->3->4->5. What will
the list be after executing the statement head->next->next->next = NULL?
a)1->2 b) 1->2->3
c) 1->2->3->4 d) 1->2->3->4
8. Templates are abstract recipe for producing a concrete code, and it is used for
a)Producing functions b) Producing classes
c) Both A and B d) none of the above
9. You want to declare an array of 200 Furniture class objects with the declaration, which of the
following declaration is correct?
a) Furniture=new Furniture[200]; b) Furniture[] =new Furniture[200];
c) Furniture[] myChairs=new Furniture[200]; d) Furniture myChairs[]=new Furniture[200];
10. While the performing of enqueue operation,
a) rear decrease b) front increase
c) front decrease d) rear increase
1|Page
Best Wishes
Dr. Shereen A. Hussien
Final Exam 2021

11. Which of the following data structure is nonlinear type?


a) Array b) Graph
c) Stack d) Queue
12. In a stack the command to access nth element from the top of the stacks will be
a) S[top-n] b) S[top+n]
b) S[top-n-] d) none of the above
13. The postfix form of A*B+C/D is?
a) *AB/CD+ b) AB*CD/+
c) A*BC+/D d) ABCD+/*
14. What is the order of magnitude of this algorithm?
for (int i = 1; i <= n; i += 2)
for (int j = 1; j <= n; j - = 2)
x += 1;
a) O (n) b) O (log n)
c) O (n^2) d) O (1)
15. If a queue is to be built using a single linked list, which of the following mappings of queue
operations to linked list operations is correct and gives better performance?
a) enqueue would be addToHead and dequeue would be removeFromHead
b) enqueue would be addToTail and dequeue would be removeFromHead
c) enqueue would be addToTail and dequeue would be removeFromTail
d) enqueue would be addToHead and dequeue would be removeFromTail
II. Consider the following binary search tree, Write the traversal sequences:-

Preorder Traversal F B A E C D H J L
Postorder Traversal A D C E B J L H F
Inorder Traversal A B E D C F J H L

III. Write the Adjacency matrix for the following graph

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

2|Page
Best Wishes
Dr. Shereen A. Hussien
Final Exam 2021

Question 2:- (10 marks)


I. Evaluate the following prefix expression using stack by filling the below empty stacks after
each scan:- / * 1 2 + 4 * 3 6

II. Consider the given linked list, Draw the impact of each the following segments with
clarifying where variables node1, node2, node3 referring to in the list
head
Adam Ali Baher Dalia Fady

Segment 1:- Draw the list after these 2 statements


Node node1 = head->next; -----------------------------------------------------------------------
node1->info = “Asmaa”; ----------------------------- ------------------------------------------
-----------------------------------------------------------------------
node 1

Segment 2:- Draw the list after these 3 statements


node2 = node1->next; --------------------------------------------------------------------------
node2 = node2->next; ---------------------------------------------------------------------------
node1->next = node2; ---------------------------------------------------------------------------
node 1 node 2
Segment 3:- Draw the list after these 3 statements
Node node3 = new Node (“nour”); -----------------------------------------------------------------------------
node1->next = node3; -----------------------------------------------------------------------------
node3->next = node2; -----------------------------------------------------------------------------
node 1 node 3 node 2

3|Page
Best Wishes
Dr. Shereen A. Hussien
Final Exam 2021

Question 3:- (10 marks)


I. Consider a given linked list 1->2->3->4->5->6. What is the output of the following functions:-
void fun(node* head)
{
if(head == NULL)
return;
cout<< head->info; The output = -------------------------------------
if(head->next != NULL )
fun(head->next->next);
cout<< head->info;
}

II. Consider the following stack of characters, where STACK is allocated N=8 memory
cells STACK : A,C,D,F,K,_,_,_. What is the stack contents after performing these
sequence of operations:-
POP(STACK,ITEM)
POP(STACK,ITEM)
POP(STACK,ITEM)
PUSH(STACK,R) Stack Contents = --------------------------------
PUSH(STACK,L)
PUSH(STACK,S)
PUSH(STACK,P)
POP(STACK,ITEM)

III. Consider a given queue where Q: 1,2,3,4 What is the output of the following functions:-
void do (node* qfront)
{
If (qfront== NULL) if do was a different name
return;
do (qfront->next); The output = -------------------------------------
cout<< qfront->info;
}
but it will give error because do
Question 4:- can't be a function name (15 marks)
I. Fill in this table. Write the worst case complexity (Big-O) of each operation for each data
structure:-

Operation Queue Linked List List


Insert_item ( ) O(1) O(n) O(n)
Delete_item ( ) O(1) O(n) O(n)
Search_item ( ) O(n) O(n) O(n)

4|Page
Best Wishes
Dr. Shereen A. Hussien
Final Exam 2021

II. Write a RemoveDuplicates() function that takes elements and returns elements after
deletting any duplicate using List Structure. Elements are not sorted.
Input:- 12->11->12->21->41->43->21
Output:- 12->11->21->41->43.
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------

III. Write a FindMin() function that takes a set of elements and returns the smallest element
using Stack linked list-based Structure. Elements are not sorted.
Input : 15->14->13->22->17
Output : Minimum element in linked list 13
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------

5|Page
Best Wishes
Dr. Shereen A. Hussien

You might also like