Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Final: 3-8-2016 ALLAMA IQBAL OPEN UNIVERSITY, ISLAMABAD (Department of Computer Science) WARNING 1. 2. PLAGIARISM OR HIRING OF GHOST WRITER(S) FOR SOLVING THE ASSIGNMENT(S) WILL DEBAR THE STUDENT FROM AWARD OF DEGREE/CERTIFICATE, IF FOUND AT ANY STAGE. SUBMITTING ASSIGNMENT(S) BORROWED OR STOLEN FROM OTHER(S) AS ONE’S OWN WILL BE PENALIZED AS DEFINED IN “AIOU PLAGIARISM POLICY”. Course: Analysis & Design of Algorithms (3466) Level: BS (CS) Semester: Autumn 2016 Total Marks: 100 Pass Marks: 50 ASSIGNMENT No. 1 Note: All questions are compulsory. Each question carries equal marks. Q. 1 (a) (b) What is the measure of efficiency in algorithm analysis and design? State your answer with the help of suitable examples. prove that: i. ii. iii. Q. 2 Consider sorting n numbers stored in array A by first finding the smallest element of A and exchanging it with the element in A[1]. Then find the second smallest element of A, and exchange it with A [2]. Continue in this manner for the first n-1 elements of A. (a) Write pseudo code for this algorithm. What loop invariant does this algorithm maintain? Why does it need to run for only the first n - 1 element, rather than for all n elements? (b) Give the best-case, average case and worst-case running times of this algorithm. Q. 3 (a) What is recursion tree method? How this method is helpful in solving the problem? Solve the following recurrence T (n) = 2 T (n/2) + cn, n >1 (b) T (1) = c Q. 4 (a) (b) Q. 5 (a) (b) Given an array of 7 elements: [15, 20, 10,5, 17, 19, 22] sort it in ascending order using heap sort. What is the running time of heap sort on an array A of length n that is already sorted in increasing order? Illustrate the operation of quick sort on the array A = [6, 11, 2, 18, 1, 19, 25, 6, 49, 33, 2, 9, 77, 12, 61]. Show that the running time of QUICKSORT is Θ(n2) when the array A contains distinct elements and is sorted in decreasing order. ASSIGNMENT No. 2 Total Marks: 100 Pass Marks: 50 Note: All questions are compulsory. Each question carries equal marks. Q. 1 (a) (b) Write algorithm for counting sort algorithm. Discuss efficiency of algorithm. Illustrate the operation of counting sort on the array A = [6, 0, 2, 0, 1, 3, 4, 6, 1, 3, 2] Q. 2 (a) Which of the following sorting algorithms are stable? Insertion sort, merge sort, heap sort, and quicksort Give a simple scheme that makes any sorting algorithm stable. How much additional time and space does this scheme entail? (b) Q. 3 (a) (b) Find the optimal sequence and minimum number of operations required for the following chain matrix multiplication using dynamic programming. A (30, 40) B (40, 5) C (5, 15) D (15, 6) Given a Convex Polygon (P= v0, v1, ... ,vn-1) and a eight function on triangles, find a triangulation minimizing the total weight. Q. 4 Trace the following algorithms with the help of an example. Analyze the difference between the order of nodes or edges visited for the two algorithms. a) Prim’s algorithm b) Kruskal’s algorithm Q. 5 Give and explain each step with graph example for the trace of following graph traversal algorithms. a) Breadth first search b) Depth first search 2 3466-Analysis and Design of Algorithm Credit Hours: 3 (3 + 0) Recommended Book: Introduction to Algorithms by Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest Course Outline: Unit–1 Introduction Introduction to Algorithm Analysis and Design Growth of Functions, Summations formulas and properties Unit–2 Recurrences and Sets Substitution, Iteration and Master Methods Sets, Relations, Functions, Graph and trees, Counting and Probability Unit–3 Sorting Algorithms Heaps, Maintaining the heap property, Heap Sort algorithm, Quick Sort, Performance and analysis of Quick Sort Unit–4 Sorting in Linear Time and Order Statistics Lower bounds for sorting, Counting sort, Radix and Bucket Sort, Medians and order Statistics Unit–5 Elementary Data Structures Analysis of Stack, Queues and Linked List Algorithms, Hash Table and Functions, Binary Search Trees Unit–6 Dynamic Programming Matrix Chain Multiplication, Longest Common Subsequence, Optimal Polygon Triangulation Unit–7 Greedy Algorithms An activity selection problem, Huffman Codes, A task scheduling problem, Amortized Analysis Unit–8 Graph Algorithms Elementary Graph Algorithms, Breadth first search, Depth first search, Minimum Spanning Trees Unit–9 Single Source Shortest Paths Shortest paths and relaxation, Dijkstra’s algorithm, The Bellman-Ford algorithm, Introduction to NP-Completeness 3