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

BCSL-045 (2023-24) Solved Assignment

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

BCSL-045 (2023-24) Solved Assignment

IGNOU BCA Sem 4 assignment
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 14
Course Code BCSL-045 Course Title Introduction to Algorithm design Lab Assignment Number BCA(V)/L-045/Assignment/2023-24 Maximum Marks 50 Weightage 25% Last date of Submission: 31 October, 2023 (For July Session) : 30" April, 2024 (For January Session) Note: Answer all the questions which carry 40 marks. All questions are of equal marks. ‘The rest 10 marks are for viva voce. You are required to write programs in C-language for all the problems , execute and show the results. You may use illustrations and diagrams to enhance the explanations. Please go through the guidelines regarding assignments given in the Programme Guide for the format of presentation, Make suitable assumption if necessary. Qi. Q. Implement the Bubble Sort algorithm for sorting the following list of numbers, showing the list obtained at each step: 17, 25,32, 4,7, 19,81, 45, 1,33 Also calculate the total number of exchange operations and how many times the loop will execute in this algorithm Implement Quick Sort algorithm to sort the following array: eee and calculate number of comparisons and exchange operations in the program Write a program to implement to reverse the following string * ABCDEFGHI” and calculate (i) Total number of exchange operations ii) Total number of comparison operations (i) Total number of times the loop will execute Implement the Binary Search Algorithm to search for a number 29 in the following array i4 7 p2 pa 9 20 f° 10 is 6 and calculate how many comparison and division operations will be required for searching the number. Apply Kruskal’s algorithm to find a minimum cost spanning tree for the following graph: 7Copyright with Kunj Publication only Not for resale Ph, 8006184581 (Call Us) Course Code: BCSL-045 Course Title: Introduction to Algorithm design Lab Assignment Number: BCA (IV)/ L-045/Assignment/2023-24 DistaimetSpecel Hote: These are athe sample ofthe AnewerSons sme othe Question sven in ihe Assignments, These Sapte anwersobans ae pepe by Prive TeocherTuaeAutors for open gudance othe adeno get an ia of me hefthe con sve he Qestons pen he Aigner Wed ot cli 10% accra of ese sample answers a tee ar asd on te Inowledge and capably of rate Teacher ator Same anoners maybe ton the Cale for te reference fo prepare he ‘oovers of he question ge inthe esi. As es solution nd ensers re prepared by he private Teacher or othe cancer ‘pero or musa canna be denied Any Omission or Errors ih regreted ough every cae as heen hen whe preparing ee Sole Answer altos Please cont your nen TecherPutor before you prepare apartcwar Answer and for ida ae es? infomation, doa aed solution Se shed st ed ond eer he ota sly marl provided By he ania Note: Answer all the questions which carry 40 marks. All questions are of equal marks, The rest 10 marks are for viva voce. You are required to write programs in C-language for all the problems, execute and show the results. You may use lustrations and diagrams to enhance the explanations. Please go through the guidelines regarding assignments given:in the Programme Guide for the format of presentation. Make suitable assumption if necessary. QI. Implement the Bubble Sort algorithm for sorting the following list of numbers, showing'the list obtained at each step: 17, 25,132,147, 19, 81, 45991933) Also calculate the total number of exehiange operations and how many times the loop willexecute in this algorithm Ais: Sure, let's implement the Bubble Sort algorithm step by step to sort the given list of numbers: 17, 25,32, 4,7, 19, 81, 45, 1, 33. Bubble Sort Algorithm: . Compare the first two elements. . Ifthe first element is greater than the second element, swap them, . Move to the next pair of elements and repeat steps 1 and 2 until the end of the list. . Repeat the above steps for each element in the list. Step-by-step execution: Original list: 17, 25, 32, 4, 7, 19, 81, 45, 1, 33Copyright with Kunj Publication only Not for resale Ph. 8006184581 (Call Us) Pass 1: 17, 25, 32, 4, 7, 19, 81, 45, 1, 33 (No swaps) 25, 32, 4, 7, 17, 19, 81, 45, 1, 33 (Swap 17 and 25) 25, 4, 7, 17, 19, 32, 81, 45, 1, 33 (Swap 25 and 32) 4,7, 17, 19, 25, 32, 81, 45, 1, 33 (Swap 25 and 32) Pass 2: 4,7, 17, 19, 25, 32, 81, 45, 1, 33 (No swaps) 7,4, 17, 19, 25, 32, 81, 45, 1, 33 (Swap 4 and 7) 7, 17, 4, 19, 25, 32, 81, 45, 1, 33 (Swap 7 and 17) 17,7, 19, 4, 25, 32, 81, 45, 1 17, 19, 7, 25, 32, 81,45, 1,33, 4 (Swap 4 and 1 KUNE PUBLICATION 7, 25, 19, 32, 81, 45, 1, 33,4 bh US:- 8006184581 Pass 4: 17, 7, 25, 32, 19, 81, 45, 1, 33, 4 (No swaps) 7, 17, 25, 19, 32, 81, 45, 1, 33, 4 (Swap 17 and 7) 7, 17, 19, 25, 32, 81, 45, 1, 33, 4 (Swap 25 and 19) Pass 5: 7, 17, 19, 25, 32, 81, 45, 1, 33, 4 (No swaps) 7, 17, 19, 25, 32, 45, 81, 1, 33, 4 (Swap 81 and 45)Copyright with Kunj Publication only Not for resale Ph. 8006184581 (Call Us) Pass 6: 7, 17, 19, 25, 32, 45, 81, 1, 33, 4 (No swaps) 7, 17, 19, 25, 32, 45, 1, 81, 33, 4 (Swap 81 and 1) Pass 7: 7, 17, 19, 25, 32, 45, 1, 81, 33, 4 (No swaps) 7, 17, 19, 25, 32, 1, 45, 81, 33, 4 (Swap 81 and 1) Pass 8: 7, 17, 19, 25, 32, 1, 45, 81, 33, 4 (No swaps) 7, 17, 19, 25, 32, 1, 45, 33, 8, RUNJ PUBLICATION ALL US:- 8006184581 fo swaps) Sorted list: 1, 4, 7, 17, 19, 25, 32, 33, 45, 81 To calculate the total number of exchange operations, we sum up the number of swaps performed during each pass: Total exchanges = 3+2+14+2+1+1=10 To calculate the number of times the loop executes in this algorithm, we count the number of passes performed: Number of passes = 10 Therefore, the Bubble Sort algorithm will execute the loop 10 times and perform 10 exchange operations to sort the given list.yright with Kunj Publication only Not for resale Ph. 8006184581 (Call Us) Q2. Implement Quick Sort algorithm to sort the following array: 5 7 [44 39 25 25 7 12 27 and calculate number of comparisons and exchange operations in the program Ans: Let’s implement the Quick Sort algorithm in Python to sort the given array and also count the number of comparisons and exchange operations. Quick Sort is a widely used sorting algorithm with an average-case time complexity of O(n log n). Here's the Python code for Quick Sort and the corresponding counters: def quick_sort(arr): comparisons = 0 exchanges = 0 RUNFPUBLICATION ALL US:- 8006184581 comparisons += I if arrfj]

You might also like