0% found this document useful (0 votes)
46 views9 pages

2019FINALEXAM

This document contains an exam for a course on algorithms analysis and design. The exam contains 7 questions worth a total of 60 marks. Question 1 asks about the running time of a k-way merge sort algorithm. Question 2 asks about amortized analysis of a dynamic hash table. Question 3 asks to color a red-black tree. Question 4 asks to write and analyze a recursive function to compute powers. Question 5 asks to find the minimum and maximum numbers in a list using at most 1.5n comparisons. Question 6 asks to solve a knapsack problem using greedy and dynamic programming algorithms. Question 7 asks to find shortest paths in a graph using Dijkstra's algorithm. The instructor's name and date are provided

Uploaded by

Ahmed Mabrok
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)
46 views9 pages

2019FINALEXAM

This document contains an exam for a course on algorithms analysis and design. The exam contains 7 questions worth a total of 60 marks. Question 1 asks about the running time of a k-way merge sort algorithm. Question 2 asks about amortized analysis of a dynamic hash table. Question 3 asks to color a red-black tree. Question 4 asks to write and analyze a recursive function to compute powers. Question 5 asks to find the minimum and maximum numbers in a list using at most 1.5n comparisons. Question 6 asks to solve a knapsack problem using greedy and dynamic programming algorithms. Question 7 asks to find shortest paths in a graph using Dijkstra's algorithm. The instructor's name and date are provided

Uploaded by

Ahmed Mabrok
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/ 9

Cairo University

Faculty of Computers and Information

Final Exam

Department: SWEP/NTP /BIOP

Course Title: Algorithms Analysis & Design


Course Code: NCS314 / CS316/ BCS316
Semester: 1
Instructor: Dr- Basheer Abdel Fattah Youssef
Date: 09/01/2019
Exam Duration: 2 Hours

Question Mark Signature


One 10
Two 10
Three 7.5
Four 7.5
Five 7.5
Six 10
Seven 10

60 Total Marks

Total Marks in Writing:


Question (1) k-way-Merge Sort. Suppose you are given k sorted arrays, each with
n elements, and you want to combine them into a single array of kn elements.
Consider the following approach. Using the merge subroutine taught in lecture, you
merge the first 2 arrays, then merge the 3rdgiven array with this merged version of
the first two arrays, then merge the 4th given array with the merged version of the
first three arrays, and so on until you merge in the final (kth) input array. What is the
running time taken by this successive merging algorithm, as a function of k and n,
show details of how to compute the running time. (10 points)

1
Question (2) show amortized analysis for dynamic hash table which start by one
size and extend 2 power i I in 0 1 ,2 4 8 ……. By aggregation methods (10 points)

2
Question (3) color the following red-blact tree

5 9

12

3
Question (4) write a recursion function that compute ab where a and b are
positive integers. and compute its time complexity using master method. (7.5 points)

T(n) =T(n/2) +1 = a=1 b = 2 c = 0 n0log n = log n

4
Question (5) Write an algorithm that finds both the smallest and largest numbers in
a list of n numbers. Try to find a method that does at most 1.5 n comparisons of
array items. Show the full analysis. (7.5 points)

First divide the n elements to two sub arrays n/2 according to compare the
two adjacent values big go to first one and the small go to the second
This take n/2 comparisons
After that you can search for min in the second one take n/2
And search for max in the first one take n/2
Total =3n/2 = 1.5n

Question (6) use the greedy Algorithm and dynamic programming to solve the
following Knapsack problem (10 points) and determine which one is the best
solution. W=5
id weight value
1 1 10
2 2 15
3 3 14
4 1 12

Item/W 0 1 2 3 4 5
0 0 0 0 0 0 0
1 0 10 10 10 10 10
2 0 10 15 25 25 25
3 0 10 15 25 25 29
4 0 12 22 27 37 37

Items 1 ,2,4

TIME DP = n*n optimum than greedy

Greedy if we chose max value first

15 + 14 = 29

DP best than Greedy

5
6
Question(7) Find the shotrest path for the following graph from node A to each
nodes using Dijkstra’s algorithm (10 points)

PARENT A A E G E B
# A B C D E F G
0 - - - - - -
5 3 - - - -
5 10 10 - -
10 8 - 6
10 7 -
9 8
9

ABG = 6
ABGEF = 8
ABGE =7
ABGED=9
AC = 3
AB = 5

7
Good Luck

Dr Basheer Youssef.

You might also like