0% found this document useful (0 votes)
20 views2 pages

Final 23-24-1

Uploaded by

Youssef ETV
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)
20 views2 pages

Final 23-24-1

Uploaded by

Youssef ETV
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

Dept/Division : Communications and Information Engineering

Academic level: Credit hours system Semester: First


Course code & title: Data structures and algorithms
Instructor: Dr Hossam Eldin Ibrahim Ali
‫كلية الهندسة بحلوان‬
Total mark: 50 marks Time allowed: 3 hrs

Answer the following questions


Question 1: (10 marks)
a) Construct binary search tree by the insertions of the following sequence of numbers: 77, 88, 99, 11, 22, 33, 31, 56,
76, 93
b) Complete the following according to the binary search tree constructed in part a.
1) The root node is…………
2) The direct left child of the root node is ………
3) Number of nodes in the left subtree ………
4) How many children for node 33? ………
c) Write pseudo codes for counting sort algorithm

Question 2: (10 marks)


a) Consider a hash table which has 11 slots. The hash function is h(k) = K mod 11. The collisions are resolved by
chaining. The following 11 keys are inserted in the order: 40,44,65, 68, 79, 75, 70, 83, 22, 37, 17.
1) Find the maximum, minimum and average chain lengths in the hash table. (show your procedures)
2) What is the total number of collisions?

b) Consider a hash table of size 11 implemented using an array A[0… 9]. A modulo hash function (mod 11) is used to
map the keys, and open addressing (Quadratic probing where, h(k) = primary hash + i + i 2 ) is used to handle collisions. If
53, 32, 43, 51, 99, 33, 44, 83, 22 are inserted into the hash table,
1) Show the contents of array A. (show your procedures)
2) What is the total number of collisions?

c) Consider a hash table of size 11 implemented using an array A[0… 10]. Double probing is used to map the keys, where,
h(k) =[ k mod 11 + i (1+k mod 97) ] mod 11) is used to handle collisions. If 53, 45, 35, 32, 43, 51, 99, 75, 33 are inserted
into the hash table,
1) show the contents of array A. (show your procedures)

Question 3: (10 marks)


a) Write pseudo code for:
1) The function: push(item , stack s) to push an item into a stack s.
2) The function: isEmpty(queue Q) to check if a queue is empty or not.
3) The function: dequeue (queue Q) to return an element from a queue.
4) The function: look_up(int x, Node *L) to search for an int x inside a linked list.

Page 1 of 2
b) Deduce the time complexity for the following function in terms of variable n.
int myFunction (int A[], int n)
int x=1;
int y=1;
for (int i=0; i<n; i=i+1)
if(i % 2==0 )
x=x*A[i];
else
y=y*A[i];
return x+y;

Question 4: (10 marks)


a) Choose the correct answer
1) ……………………….: A graph in which the edges have no direction.
a. Directed graph b. Undirected graph c. None of the above
2) A path is ……………. if all its vertices are distinct but the last one.
a. Simple b. A cycle c. Acyclic d. DAG
3) A graph that does not contain cycles is called …………….
a. Simple b. A cycle c. Acyclic d. DAG
4) A directed graph G is …………………… there exists a path from any vertex to any other vertex.
a. Connected b. Strongly connected c. unconnected

b) Write pseudo code for Dijkstra’s shortest path algorithm.


c) Hand run Dijkstra’s algorithm to find the shortest paths from node A .
d) Hand run prim’s algorithm to find the minimum spanning tree starting from node ‘a’. Find the total cost.

part c part d

Question 5: (10 marks)


a) True or false
1) A complete graph is a graph with an edge between any pair of vertices.( )
2) Adjacency matrix for directed graph is symmetric. ( )
3) Adjacency matrix requires storage O(|V|^2) . ( )
4) Adjacency matrix is convenient for sparse graphs. ( )

b) Write pseudo codes showing how to modify DFS to add temporal labels to graph
nodes; (d[u], f[u]).
c) Hand run the algorithm in part (b) with Stacks for the given graph starting from
node A. Tabulate your answer and show the resulting search tree with added
labels.

Page 2 of 2

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