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

17CSCI01C Data Structures Unseen Exam

The document is a confirmation sheet for the proofing and printing of an examination paper for the module 'Introduction to Data Structures & Algorithms' (Module Code: 17CSCI01C). It includes details about the proofreader's comments, confirmation of proofreading, marking schema, and instructions for printing and stationery requirements. The examination consists of multiple questions assessing various learning objectives related to data structures and algorithms.

Uploaded by

qfzg7f99qd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

17CSCI01C Data Structures Unseen Exam

The document is a confirmation sheet for the proofing and printing of an examination paper for the module 'Introduction to Data Structures & Algorithms' (Module Code: 17CSCI01C). It includes details about the proofreader's comments, confirmation of proofreading, marking schema, and instructions for printing and stationery requirements. The examination consists of multiple questions assessing various learning objectives related to data structures and algorithms.

Uploaded by

qfzg7f99qd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 23

Examination Paper Proofing & Printing

Confirmation Sheet

Informatics and Computer Science


Module Title Module Code
Introduction to Data Structures & Algorithms 17CSCI01C

Module Leader Professor Khaled Nagaty Semester


One
Proofed by Dr. Ghada Hassan

Proof-reader comments
-
Spelling and Grammar -
-
-
-
Template -
-
-
-
Marking schema -
-
-
-
ILOs matching -
-
-
Any Other Comments -
-
-
-

 This examination paper has been proof-read (spelling and grammar) 

 This examination paper follows the approved template 

 All questions (and sub questions) have their marks specified 

 Appropriate model answers were provided with breakdown of marks 

 This examination paper assesses the ILOs for the module 

 ILOs Matrix is included 

Signed (Proof Reader): Dr. Ghada Hassan

[Turn Over (only when instructed to do so)]


Examination Paper Proofing & Printing
Confirmation Sheet

Informatics and Computer Science


Module Title Module Code
Introduction to Data Structures & 17CSCI01C
Algorithms

Module Leader Professor Khaled Nagaty Semester


One
Proofed by Dr. Ghada Hassan

I hereby confirm that

 This examination paper has been proof-read (spelling and grammar) 

 This examination paper follows the approved template 

 All questions (and sub questions) have their marks specified 

 Appropriate model answers were provided with breakdown of marks 

 This examination paper assesses the ILOs for the module 

Signed (Proof Reader): Dr. Ghada Hassan

Printing instructions & stationery requirements

Number of copies of examination paper to be


printed

Date of examination

Number required per


student
Stationery Requirement(s) 8 page answer book

12 page answer
book
Graph paper

Other

Signed (Module Leader): Professor Khaled Nagaty

[Turn Over (only when instructed to do so)]


Module Code
17CSCI01C
Final Examination,
2019-2020
Informatics and Computer Science
Module Title Introduction to Data Structures & Algorithms

Module Leader Professor Khaled Nagaty Semester


One

Equipment allowed None

[Adjust to your exam by replacing items in bold, and remove this line]

Instructions to students:

- The exam paper is 3 pages long, and is in 1 section.

- Answer all questions.

- The allocation of marks is shown in brackets by the questions.

- The total mark of the exam is 100 marks.

This examination is 2 hours long.

[Turn Over (only when instructed to do so)]


Answer all Questions

Q1 Assume the following circularly doubly linked lists:


a) Which operation is true to delete Node "D". Assume P points to the
last node in the list.
i. front before = P before;
P before next = P next;

ii. P before next = P next;


front before = P before;

iii. P next before = P next;


front before = P before;

iv. P before next = P next;


front next = P before;

front
before next before next before next before next
A B C D

[5 marks]
b) What is the execution time required to delete the last element in a
circular linked list of length N. Assume P points to the last node in
the list.
i. O(N)
ii. O(log2 N)
iii. O(1)
iv. O(2)
[5 marks]

[Turn Over (only when instructed to do so)]


Q 2 Assume the following weighed graph:

a) Which of the following is the longest path from A to W?


i. AB C DTW
ii. AB DT W
iii. AD T W
iv. AH T W

b) Assume the following unweighted graph:

By using the Depth First Search algorithm which of the following is true?
i. A, B, E, G, I , J, C, F, H, D.
ii. A, E, B, I, J, F, H,G, C, D.
iii. A, G, F, H, J, D, B, C, E, I.
iv. A, H, I, J, E, G, F, E, C, B.

[Q2 Total: 20 marks, 10 each]

[Turn Over (only when instructed to do so)]


Q 3 What is the execution time of each piece of code:
a) Sum = 0;
for(i=1; i<N; i++)
for(j=1;j<i*i;j++)
if(j % i == 0)
for (k=0; k<j; k++)
Sum++;

a) O(n)
b) O(n2)
c) O(n3)
d) O(n5)

b) Sum = 0;
for(i=1; i<N; i++)
for(j=1;j<i*i; j++)
Sum++;

e) O(n)
f) O(nlog2 n)
g) O(n3)
h) O(n2)

c) Count=0;
for (i=1; i<log2 n; i++)
for (j=1; j<log2 n; j++)
Count++;

i) O(log2 n2)
j) O(log2 n)
k) O(log2 n)
l) O(n2)

[Q2 Total: 20 marks]

Q 4 Answer the following question:


a) What is a hash table or hash map?
[5 marks]
b) Suppose you have the following hash table:
0 1 23 4 5 6 7 8 9

Find the hash values to insert each of the following items in the hash
table{26 ,70 , 18 , 31, 54 ,93 }.
Use the following hash function:

[Turn Over (only when instructed to do so)]


Hash value = key value % number of slots in the hash table
[5 marks]
c) Suppose the hash table contains the following items
0 1 23 4 5 6 7 8 9
70 31 93 54 26 18
Use the linear probing method to resolve the conllision in the hash
table that occurs when the next item to insert is 40 and show the
contents of the hash table.
[10 marks]
[Q4 Total: 20 marks]

Q 5 Answer the following question


a) Write the code for the recursive function f (n)=n∗f (n−1), base
condition: if n≤1 then f (n)=1.
b) What is the time complexity of the hash table in the average case?
What is the time complexity if you have N elements in one bucket?
Justify your answer for each case scenario.

[Turn Over (only when instructed to do so)]


Module Code
17CSCI01C
Model Answer,
2019-2020
Informatics and Computer Science
Module Title Introduction to Data Structures & Algorithms

Module Leader Semester


Professor Khaled Nagaty One

Equipment allowed
“None”

[Adjust to your exam by replacing items in bold, and remove this line]

Instructions to students:

- The exam paper is 3 pages long, and is in 1 section.

- Answer all questions.

- The allocation of marks is shown in brackets by the questions.

- The total mark of the exam is 100 marks.

ILOS Assessed Exam Questions

ILO Intended learning Objective Q1 Q2 Q3 Q4 Q5

no.

1 Select the most appropriate data structure and 


algorithm for a given problem.[B2]
2 Recognize fundamental data structures and    
concepts of algorithms complexity analysis in
line with the principles of good software design.
[A1]
3 Develop an analytical approach to interpreting  
problem specifications and a systematic
approach to problem solving. [B5]
4 Design and implement moderately complex 
programs that are correct, robust and
maintainable. [C3]

[Turn Over (only when instructed to do so)]


Q 1 Assume the following circularly doubly linked lists:
ii. Which operation is true to delete Node "D". Assume P points to the
last node in the list.
v. front before = P before;
P before next = P next;

vi. P before next = P next;


front before = P before;

vii. P next before = P next;


front before = P before;

viii. P before next = P next;


front next = P before;

front
before next before next before next before next
A B C D

[5 marks]
iii. What is the execution time required to delete the last element in a
circular linked list of length N. Assume P points to the last node in
the list.
v. O(N)
vi. O(log2 N)
vii. O(1)
viii. O(2)
[5 marks]

Page 1 of 13
Q2
a) What is the output of the following segment of code:
stackType <int> stack;
int x, y;
x = 4;
y = 0;
stack.push (7);
stack.push (x);
stack.push(x+5);
y= stack.top( );
stack.pop( );
stack.push(x+y);
stack.push(y-2);
stack.push(3);
x = stack.top( );
stack.pop( );
cout << “x = ” << x << endl;
cout << “y = ” << y << endl;
while (!stack.isEmptyStack( ))
{
cout << stack.top ( ) << endl;
stack.pop ( );
}

[5 marks]
b) Show the steps to convert the arithmetic expression a+ b∗c−d from the
infix notation to the postfix notation using a stack.
[15 marks]
[Q1 Total: 20 marks]
Answer
a) x = 3 [1 marks]
y=9 [1 marks]
7 [1 marks]
13 [1 marks]
4 [0.5 marks]
7 [0.5 marks]

Page 2 of 13
b)

1) Initially the Stack is empty [0.25 marks] and the output postfix string is
empty [0.25 marks]. Now, the first character read from the expression is
'a' [0.25 marks]. Since it is character not an operator it is put to the output
postfix string [0.25 marks]. The next input character is '+' [0.25
marks]and since it is an operator so it is pushed onto the stack [0.25
marks].

[0.5 marks]

Next input character is 'b' [0.25 marks] so it will be put to the postfix string
[0.25 marks]. The next input character is '*' which is an operator [0.25
marks] so it is pushed to the top of the stack [0.25 marks] because '+' has
lower precedence than '*' [0.25 marks].

[1 mark]

The next input character is 'c' [0.25 marks] which is placed in the output
postfix string [0.25 marks]]. Next character input is '-[0.25 marks] and
since it is an operator [0.25 marks] its precedence is compared with that of
the topmost operator on the stack which is '*' [0.25 marks] and has a higher
precedence than '-' [0.25 marks]. So '*' will be popped out from the stack
[0.25 marks] and added to the output postfix string [0.25 marks]. Now, the
topmost element of the stack is '+' [0.25 marks] which has equal priority to
'-' [0.25 marks]. So, pop the '+' from the stack [0.25 marks] and add it to
the output postfix string [0.25 marks]. Finally, the '-' will be pushed to the
stack [0.25 marks].

Page 3 of 13
[2 marks]

Next input character is 'd' [0.25 marks] which is added to the output postfix
string [0.25 marks]. Now all characters have been scanned [0.25 marks]
so we must pop the remaining elements from the stack [0.25 marks] and
add it to the Postfix string [0.25 marks]. At this stage we have only '-' [0.25
marks] in the stack so it is popped out [0.25 marks] and added to the
Postfix string [0.25 marks]. Now all characters are scanned and the stack
and output postfix string looks like [0.25 marks]:

[4 marks]

[Q1 Total: 20 marks]

Q 3 Assume the following linked list where each node consists of two fields the
data field “info” field and the address field “link”. The “info” field stores
integers and the “link” field stores pointers.

a. What is the value of each of the following relational expressions:


i. front info > = 18
ii. front link ==I
iii. I link info = 16
iv. J link ==NUL
v. front info ==18
b) Write C++ statements to do the following:
i. Create and insert a node with 10 after the node pointed to by I.

Page 4 of 13
ii. Delete the node with 23, and deallocate the memory occupied by this
node.
iii. Make J point to the last node in the list.
[Q2 Total: 20 marks, 10
each]
Answer

a)

i. True
ii. True
iii. False
iv. False
v. True
[2 marks for each item]

b)

1) newNode = new nodeType; [1 mark]

newNode - >info = 10; [1 mark]

newNode - >link = A ->link; [1 mark]

A ->link = newNode; [1 mark]

2) p = A -> link; [1
mark]

A ->link = p-> link; [1


mark]

delete p; [2
marks]

3) B = B -> link -> link; [2 marks]

[Q2 Total: 20 marks, 10 each]

Page 5 of 13
Q 4 Answer the following questions:
a) Compare between tree and graph data structures. What is each one is
useful for? [12 marks]
b) Assume the following precedence graph.

In parallel processing independent statements can be executed in parallel


which can speed up the program execution. We say that statement Si
depends on statement Sj if Si requires results of Sj so that Si cannot be
executed before Sj.
i. Find the dependency list for each statement in the above graph.
[6 marks]
ii. What are the statements that can be executed in parallel? Justify your
answer. [2 marks]
[Q3 Total: 20 marks]
Answer

a) All tree structures are hierarchical by nature [0.5 marks] which means that
each node has only one parent node [0.5 marks]. Trees are useful in storing
data that have the hierarchy properties such as family tree or file systems
[1 mark]. There are three possible traversal methods for a tree namely, preorder
[0.5 marks], inorder [0.5 marks] and postorder [0.5 marks] methods. Some
data has no hierarchical property which means that a node can have more the
one parent or there are more connections between nodes which do not fit into a
hierarchy structure. Graph data structures can be useful in these situations [0.5
marks]. A graph, like a tree, is a collection of nodes and edges [0.5 marks], but
has no rules dictating the connection among the nodes [0.5 marks]. A graph
consists of a number of data nodes [0.5 marks], each of which is
Page 6 of 13
called a vertex [0.5 marks]. Any vertex may be connected to any other [0.5
marks], and these connections are called edges [0.5 marks]. A tree data
structure can be described as a connected [0.5 marks], acyclic graph [0.5
marks] with one node designated as the root node [0.5 marks]. It is acyclic
because there are no paths in a tree which start and end at the same node [0.5
marks]. A graph is cyclic if it contains paths that start and end at the same node
[1 mark]. There are two possible traversal methods for a graph namely, breadth-
first [0.5 marks] and depth-first [0.5 marks] methods. Graphs are very useful in
representing data networks such as: computer networks, maps of cities and
traffic roads [1 mark].

b)

i. Dependency lists are:

S1 : null [0.5 marks]

S2: null [0.5 marks]

S3: S1 [0.5 marks]

S4: S1, S2 [1 mark]

S5 : S1, S2, S4 [1.5 marks]

S6: S1, S2, S3, S4 [2 marks]

ii. From the dependency lists it is clear that S1 and S2 can be executed in
parallel [0.5 marks] because they do not wait any results from each other
[0.5 marks].

After finish S1 & S2 finished execution S3 & S4 can be executed in parallel as


no one waits for the results of other [0.5 marks].

Page 7 of 13
After S4 finished execution S5 & S6 can be executed in parallel as no one
depends on the results of the other [0.5 marks].

Page 8 of 13
Q 5 Answer the following question:
b) What is a hash table or hash map?
[5 marks]
d) Suppose you have the following hash table:
0 1 23 4 5 6 7 8 9

Find the hash values to insert each of the following items in the hash table
{26 ,70 , 18 , 31, 54 ,93 }.
Use the following hash function:
Hash value = key value % number of slots in the hash table
[5 marks]
e) Suppose the hash table contains the following items
0 1 23 4 5 6 7 8 9
70 31 93 54 26 18
Use the linear probing method to resolve the conllision in the hash table
that occurs when the next item to insert is 40 and show the contents of
the hash table. [10 marks]
[Q4 Total: 20
marks]
Answer

a)
 Hash table or hash map is a data structure used to store key-value pairs.
[1 mark]
 It is a collection of items stored to make it easy to find them later.
[1 mark]
 It uses a hash function to compute an index into an array of buckets or slots
from which the desired value can be found. [1 mark]
 It is an array of list where each list is known as bucket. [1 mark]
 It contains value based on the key. [1 mark]

Page 9 of 13
b)
Data Item Value % No. of Slots Hash Value
26 26 % 10 = 6 6 [1 mark]
70 70 % 10 = 0 0 [1 mark]
18 18 % 10 = 8 8 [1 mark]
31 31 % 10 = 1 1 [1 mark]
54 54 % 10 = 4 4 [0.5 marks]
93 93 % 10 = 3 3 [0.5 marks]

c) P=H (40) [1 mark]


44 % 10=0 [1 mark]
Position 0 is occupied by70. So we look elsewhere for a position to store
40 . [1 mark]

Using Linear Probing:


P=(P+1)% table−¿ ¿ [1 mark]
0+1 % 10=1 [1 mark] But,
position 1 is occupied by31[1 mark ], so we look elsewhere for a position
to store 40 . [1 mark]

Using linear probing, we try next position: 1+1 % 10=2 [1 mark]


Position 2 is empty, so 40 is inserted there. [1 mark]

0 1 23 4 5 6 7 8 9
70 31 40 93 54 26 18
[1 mark]

Page 10 of 13
Q 6 Answer the following question
a) Write the code for the recursive function f (n)=n∗f (n−1), base condition:
if n≤1 then f (n)=1.
b) What is the time complexity of the hash table in the average case? What
is the time complexity if you have N elements in one bucket? Justify your answer
for each case scenario.

Answer
a)
using namespace std; [0.5 marks]
int f(int n) [0.5 marks]
{ [0.5 marks]
if (n <= 1) [0.5 marks]
return 1; [1 mark]
else [0.5 marks]
return n*f(n-1); [2 marks]
} [0.5 marks]
int main() [0.5 marks]
{ [0.5 marks]
int num; [0.5 marks]
cout<<"Enter a number: "; [0.5 marks]
cin>>num; [0.5 marks]
cout<<"Output:"<<f(num); [0.5 marks]
return 0; [0.5 marks]
} [0.5 marks]

b) In the average case the time complexity is O(1). [1 mark] This is because if
a good hash function [1 mark] is chosen it is very rare that many items will
be hashed to the same key [2 marks]. In the worst case [1 mark], you could
be inserting N elements [1 mark] all of which hash to the same bucket
[1 mark]. Then, for this data set, deletion and search will also be O ( n ) [1
mark], this is because it too elements were hashed in to the same key this
key may take O(n) times [2 marks].
[Q5 Total: 20 marks, 10 each]

Page 11 of 13
Page 12 of 13
Module Specification – (Programme Specs Ver. 4.2) 2017/18

Module Code:17CSCI01C Title: Introduction to Data Structures and Algorithm Design


Level: C Modular weight:10 Faculty/Dept: ICS
Pre-requisite modules: CSCI01P, CSCI02P
Reassessment: No restriction
Module Leader: Dr. Ghada Hassan
Semester taught: One
Date of latest revision: April 2017

Aims
The aim of the module is to introduce the concepts of data structures and algorithm design and
provide a foundation for advanced studies in computer science. The main focus is on the use of
data structures and abstraction methods, both in terms of data representation and algorithmic
access.

Intended Learning Outcomes


On completion of this module students should be able to:
Knowledge and understanding

1. Recognize fundamental data structures and concepts of algorithms complexity analysis in line
with the principles of good software design. [ A1 ]

Subject-specific Cognitive skills

2. Select the most appropriate data structure and algorithm for a given problem.[B1]
3. Develop an analytical approach to interpreting problem specifications and a systematic
approach to problem solving. [B2]

Subject-specific Practical skills


4. Design and implement moderately complex programs that are correct, robust and
maintainable. [C1]

Transferable skills
5. Search for and retrieve needed information from programming language libraries and
documentation. [D1]

Employability
This module will provide opportunities for students to:
1. Understand the importance of maintaining performance under pressure. [A3]
2. Develop analytical and systematic problem solving skills. [B.1.2]
3. Carry out a range of complex ICT activities related to their work that involve application
software. [B.3.1]

Page 13 of 13
Indicative Content

 Aggregate Data Structures: strings, arrays, abstract data types (structures and classes)
 Pointers and dynamic memory.
 Stack abstraction and implementation.
 Queue abstraction and implementation.
 Linked lists abstraction and implementation.
 Trees: Binary Trees abstraction, traversals, and algorithms
 Heaps and priority queues
 Hashing and hash tables
 Introduction to algorithms, algorithms complexity, and time/space complexities.
 Sorting and searching algorithms: insertion sort, linear and binary search, and their
complexity analysis.

Methods of Learning, Teaching and Assessment


Total student effort for the module: 100 hours on average over one semester.

ILOs Typical Student Effort


Covered
Type of session Typical number Typical hours per Total hours
in the semester/s week
Lecture 1-5 12 2 24

Tutorial - - - -
Laboratory 2-5 12 2 24

Private study 1-5 - - 52

Assessment

Assessment Type Weight % ILOs Exam Exam/


Assessed Semester Written
Coursework
Length
Two in-lab tests 50 2-5 1 90 minutes
each
Unseen written exam 50 1-4 1 120 minutes

Methods of Feedback
In response to assessed work:
 Specific feedback will be provided after lab tests through marking criteria and in written form
as appropriate for each student. If students require additional feedback, they are welcome to
speak with the TA, or module leader.
 Generic feedback for unseen exam on e-learning.

Developmental feedback generated through teaching activities:

Page 14 of 13
 Dialogue between students and staff in workshops and Labs.

Indicative Reading List


 Tony Gaddis, Starting out with C++, with My Programming lab, 7th edition. Pearson
Publications, 2013.
 Nyhoff, L., ADTs Data Structures, and Problem Solving with C++, 2nd Edition. Prentice Hall,
2005.
 Nance, D. and Naps, L. “Introduction to Computer Science with C++”, 2nd Edition ,
Brooks/Cole, ISBN/ISSN: 0-534-36893-X.

Page 15 of 13

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy