Roll No:____ Name:__________________ Sem:_______Section______ Design & Analysis of Algorithms Prof. Saima Ansari / Prof. Azra Shireen/ Dr.Manish Assudani/Prof. Naveed Zeeshan Page 1 Design & Analysis of Algorithms CERTIFICATE Certified that this file is submitted by Shri/Ku.___________________________________________________________ Roll No.________a student of ________ year of the course __________________ ______________________________________ as a part of PRACTICAL/ORAL as prescribed by the Rashtrasant Tukadoji Maharaj Nagpur University for the subject_____________________________________ in the laboratory of ___________________________________during the academic year _________________________ and that I have instructed him/her for the said work, from time to time and I found him/her to be satisfactory progressive. And that I have accessed the said work and I am satisfied that the same is up to that standard envisaged for the course. Date:- Signature Signature Prof. Saima Ansari Prof. Nazish Khan Prof. Azra Shireen HOD, CS&E Dr. Manish Assudani Prof. Naveed Zeeshan Prof. Saima Ansari / Prof. Azra Shireen/ Dr.Manish Assudani/Prof. Naveed Zeeshan Page 2 Design & Analysis of Algorithms Anjuman College of Engineering and Technology Vision To be a centre of excellence for developing quality technocrats with moral and social ethics, to face the global challenges for the sustainable development of society. Mission To create conducive academic culture for learning and identifying career goals. To provide quality technical education, research opportunities and imbibe entrepreneurship skills contributing to the socio-economic growth of the Nation. To inculcate values and skills, that will empower our students towards development through technology. Vision and Mission of the Department Vision: To achieve excellent standards of quality education in the field of computer science and engineering, aiming towards development of ethically strong technical experts contributing to the profession in the global society. Mission: To create outcome based education environment for learning and identifying career goals. Provide latest tools in a learning ambience to enhance innovations, problem solving skills, leadership qualities team spirit and ethical responsibilities. Inculcating awareness through innovative activities in the emerging areas of technology. Prof. Saima Ansari / Prof. Azra Shireen/ Dr.Manish Assudani/Prof. Naveed Zeeshan Page 3 Design & Analysis of Algorithms Program Educational Objectives (PEOs) The graduates will have a strong foundation in mathematical, scientific and engineering fundamentals necessary to formulate, solve and analyze engineering problem in their career. Graduates will be able to create and design computer support systems and impart knowledge and skills to analyze, design, test and implement various software applications. Graduates will work productively as computer science engineers towards betterment of society exhibiting ethical qualities. Program Specific Outcomes (PSOs) Foundation of mathematical concepts: To use mathematical methodologies and techniques for computing and solving problem using suitable mathematical analysis, data structures, database and algorithms as per the requirement. Foundation of Computer System: The capability and ability to interpret and understand the fundamental concepts and methodology of computer systems and programming. Students can understand the functionality of hardware and software aspects of computer systems, networks and security. Foundations of Software development: The ability to grasp the software development lifecycle and methodologies of software system and project development. Prof. Saima Ansari / Prof. Azra Shireen/ Dr.Manish Assudani/Prof. Naveed Zeeshan Page 4 Design & Analysis of Algorithms PROGRAM: CS & E DEGREE: B.TECH COURSE: Design & Analysis of Algorithms SEMESTER: V CREDITS: 2 COURSE CODE: BTECH CSE 503 T COURSE TYPE: REGULAR COURSE AREA/DOMAIN: CSE CONTACT HOURS: 2 hours/Week CORRESPONDING LAB COURSE CODE : B TECHCSE503 P L AB COURSE NAME : Design & Analysis of Algorithms Lab COURSE PRE-REQUISITES: C.CODE COURSE NAME DESCRIPTION SEM BSE2 - 4T Computational Skills C Programming for Implementation of Data Structure I I BECSE40 2 T Data Structures & Program Design Study of various Data Structures and their implementation design IV COURSE OBJECTIVES: 1 To learn the importance of Designing an algorithm in an efficient way by considering time and space complexity. 2 To learn g raph search algorithm. 3 To study network flow and linear programming problem. 4 To learn dynamic programming design techniques. 5 To develop recursive backtracking algorithm. COURSE OUTCOMES: Design & Analysis of Algorithms After completion of this course the students will be able – SNO DESCRIPTION BLOOM’S TAXONOMY LEVEL CO.1 Solve time complexity of algorithm. 3 CO.2 Categorize numbers using various sorting algorithm. 4 CO.3 Develop programs for the problems using Divide & Conquer and Greedy method. 6 CO.4 Develop programs for the problem using Dynamic programming. 6 CO.5 Create programs for the problems using Backtracking. 6 Prof. Saima Ansari / Prof. Azra Shireen/ Dr.Manish Assudani/Prof. Naveed Zeeshan Page 5 Design & Analysis of Algorithms Lab Instructions: Make entry in the Log Book as soon as you enter the Laboratory. All the students should sit according to their Roll Numbers. All the students are supposed to enter the terminal number in the Log Book. Do not change the terminal on which you are working. Strictly observe the instructions given by the Faculty / Lab. Instructor. Take permission before entering in the lab and keep your belongings in the racks. NO FOOD, DRINK, IN ANY FORM is allowed in the lab. TURN OFF CELL PHONES! If you need to use it, please keep it in bags. Avoid all horseplay in the laboratory. Do not misbehave in the computer laboratory. Work quietly. Save often and keep your files organized. Don’t change settings and surf safely. Do not reboot, turn off, or move any workstation or PC. Do not load any software on any lab computer (without prior permission of Faculty and Technical Support Personnel). Only Lab Operators and Technical Support Personnel are authorized to carry out these tasks. Do not reconfigure the cabling/equipment without prior permission. Do not play games on systems. Turn off the machine once you are done using it. Violation of the above rules and etiquette guidelines will result in disciplinary action. Prof. Saima Ansari / Prof. Azra Shireen/ Dr.Manish Assudani/Prof. Naveed Zeeshan Page 6 Design & Analysis of Algorithms Continuous Assessment Practical Exp No NAME OF EXPERIMENT CO Date Remark Sign 1 Write a program to implement and analyze Mast er method for dividing function CO1 2 Write a program to implement Bubble sort. (Virtual Lab) CO1 3 Write a program to implement Huffman Code using Greedy approach. CO2 4 Write a program to implement Merge sort. CO2 5 Write a program to implement LCS problem using Dynamic Programming. CO3 6 Code to find chain matrix multiplication problem using dynamic programming. CO3 7 Write a program to implement Depth First Search (Virtual Lab) CO4 8 Code and analyze n - queen problem using backtracking. CO4 9 Study of NP - Hard and NP - Complete problem basic concepts. CO5 10 Study of Cook’s theorem. CO5 Content Beyond Syllabus: 11 Code and analyze to find HCF and LCM of two numbers. 12 To implement Linear Programming Problem. Prof. Saima Ansari / Prof. Azra Shireen/ Dr.Manish Assudani/Prof. Naveed Zeeshan Page 7 Design & Analysis of Algorithms CONTENTS Exp No NA ME OF EXPERIMENT PAGE NO. 1 Write a program to implement and analyze Mast er method for dividing function 2 Write a program to implement Bubble sort. (Virtual Lab) 3 Write a program to implement Huffman Code using Greedy approach. 4 Write a program t o implement Merge sort. 5 Write a program to implement LCS problem using Dynamic Programming. 6 Code to find chain matrix multiplication problem using dynamic programming. 7 Write a program to implement Depth First Search (Virtual Lab) 8 Code and a nalyze n - queen problem using backtracking. 9 Study of NP - Hard and NP - Complete problem basic concepts. 10 Study of Cook’s theorem. Content Beyond Syllabus: 11 Code and analyze to find HCF and LCM of two numbers. 12 To implement Linear Programming Problem. Prof. Saima Ansari / Prof. Azra Shireen/ Dr.Manish Assudani/Prof. Naveed Zeeshan Page 8 Design & Analysis of Algorithms Practical No. – 1 Prof. Saima Ansari / Prof. Azra Shireen/ Dr.Manish Assudani/Prof. Naveed Zeeshan Page 9 Design & Analysis of Algorithms Aim : Write a program to implement and analyze Master method for dividing function. Theory : Master method/theorem which is framework and formulae using which solutions to many recurrence relations can be obtained very easily. Almost all recurrences of type T(n) = aT(n - b) + f(n) and T(n) = aT(n/b) + f(n) can be solved easily by doing a simple check and identifying one of the many cases mentioned in the following theorem. Decreasing functions : The master theorem is a formula for solving recurrences of the form T(n) = aT(n - b) + f(n), where a ≥ 1 and b > 0 and f(n) is asymptotically positive (Asymptotically positive means that the function is positive for all sufficiently large n.) This recurrence describes an algorithm that divides a problem of size n into sub problems, each of size n- b, and solves them recursively. The theorem is as follows: If T(n) = a T(n-b) + f(n), where a ≥ 1, b > 0, & f(n) = O(n k ), a nd k ≥ 0 Prof. Saima Ansari / Prof. Azra Shireen/ Dr.Manish Assudani/Prof. Naveed Zeeshan Page 10 Design & Analysis of Algorithms Dividing functions: The master theorem is a formula for solving recurrences of the form T(n) = aT(n/b)+f(n), where a ≥ 1 and b > 1 and f(n) is asymptotically positive. This recurrence describes an algorithm that divides a problem of size n into sub problems, each of size n/b, and solves them recursively. (Note that n/b might not be an integer, but replacing T(n/b) with 𝑇 ( ⌊𝑛 / 𝑏⌋ ) or 𝑇 ( ⌈𝑛 / 𝑏⌉ ) does not affect the asymptotic behavior of the recurrence. Prof. Saima Ansari / Prof. Azra Shireen/ Dr.Manish Assudani/Prof. Naveed Zeeshan Page 11 Design & Analysis of Algorithms Program : Output: Prof. Saima Ansari / Prof. Azra Shireen/ Dr.Manish Assudani/Prof. Naveed Zeeshan Page 12 Design & Analysis of Algorithms Conclusion: Hence we have studied, implemented and analyze Master method for dividing function. Viva Voce Question 1. What is Master method? Explain. ________________________________________________________________ ________________________________________________________________ ________________________________________________________________ ________________________________________________________________ ____________________________________________________________ 2. What is recurrence relation? ________________________________________________________________ ________________________________________________________________ ________________________________________________________________ ________________________________________________________________ _________________________________________________________ 3. What are the different types of recurrence relation? ________________________________________________________________ ________________________________________________________________ ________________________________________________________________ ________________________________________________________________ ________________________________________________________________ Signature of Course Teacher Prof. Saima Ansari / Prof. Azra Shireen/ Dr.Manish Assudani/Prof. Naveed Zeeshan Page 13 Design & Analysis of Algorithms Practical No. – 2 Prof. Saima Ansari / Prof. Azra Shireen/ Dr.Manish Assudani/Prof. Naveed Zeeshan Page 14 Design & Analysis of Algorithms Aim: Write a program to implement Bubble sort(Virtual Lab). Theory : Bubble Sort is a simple sorting algorithm that repeatedly steps through the list, compares adjacent elements, and swaps them if they are in the wrong order. Its average and worst-case complexity is O(n 2 ). Program: Prof. Saima Ansari / Prof. Azra Shireen/ Dr.Manish Assudani/Prof. Naveed Zeeshan Page 15 Design & Analysis of Algorithms Output: Conclusion: Hence we have implemented Bubble sort algorithm Viva Voce Question 1. Explain Divide and Conquer strategy of Problem Solving? ________________________________________________________________ ________________________________________________________________ ________________________________________________________________ ________________________________________________________________ ____________________________________________________________ 2. Which types of problem can be solved using Divide and Conquer strategy, explain with example? ________________________________________________________________ ________________________________________________________________ ________________________________________________________________ ________________________________________________________________ ____________________________________________________________ 3. Explain best case, worst case and average case complexity with a suitable example ________________________________________________________________ ________________________________________________________________ ________________________________________________________________ ________________________________________________________________ ________________________________________________________________ Signature of Course Teacher Prof. Saima Ansari / Prof. Azra Shireen/ Dr.Manish Assudani/Prof. Naveed Zeeshan Page 16 Design & Analysis of Algorithms Practical No. – 3 Prof. Saima Ansari / Prof. Azra Shireen/ Dr.Manish Assudani/Prof. Naveed Zeeshan Page 17 Design & Analysis of Algorithms Aim: Write a program to implement Huffman Code using Greedy approach. Theory : Huffman coding is a lossless data compression algorithm. The idea is to assign variable-length codes to input characters; lengths of the assigned codes are based on the frequencies of corresponding characters. The most frequent character gets the smallest code and the least frequent character gets the largest code. The variable-length codes assigned to input characters are Prefix Codes, means the codes (bit sequences) are assigned in such a way that the code assigned to one character is not the prefix of code assigned to any other character. This is how Huffman Coding makes sure that there is no ambiguity when decoding the generated bit stream. Let us understand prefix codes with a counter example. Let there be four characters a, b, c and d, and their corresponding variable length codes be 00, 01, 0 and 1. This coding leads to ambiguity because code assigned to c is the prefix of codes assigned to a and b. If the compressed bit stream is 0001, the de- compressed output may be “cccd” or “ccb” or “acd” or “ab”. See this for applications of Huffman Coding. There are mainly two major parts in Huffman Coding 1. Build a Huffman Tree from input characters. 2. Traverse the Huffman Tree and assign codes to characters. Program: Prof. Saima Ansari / Prof. Azra Shireen/ Dr.Manish Assudani/Prof. Naveed Zeeshan Page 18 Design & Analysis of Algorithms Output: Conclusion: Thus we have implemented and executed Huffman Code using Greedy approach successfully. Viva Voce Question 1. Define and explain Greedy Approach? ________________________________________________________________ ________________________________________________________________ ________________________________________________________________ ________________________________________________________________ ____________________________________________________________ Prof. Saima Ansari / Prof. Azra Shireen/ Dr.Manish Assudani/Prof. Naveed Zeeshan Page 19 Design & Analysis of Algorithms 2. Where Huffman coding is primarily used, explain? ________________________________________________________________ ________________________________________________________________ ________________________________________________________________ ________________________________________________________________ ____________________________________________________________ 3. What is the time complexity of Huffman Code? ________________________________________________________________ ________________________________________________________________ ________________________________________________________________ ________________________________________________________________ ________________________________________________________________ Signature of Course Teacher