Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
7 views
Algorithm Assignment
Uploaded by
I211381 Eeman Ijaz
AI-enhanced title
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
Download now
Download
Save Algorithm assignment For Later
Download
Save
Save Algorithm assignment For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
7 views
Algorithm Assignment
Uploaded by
I211381 Eeman Ijaz
AI-enhanced title
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
Download now
Download
Save Algorithm assignment For Later
Carousel Previous
Carousel Next
Save
Save Algorithm assignment For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 6
Search
Fullscreen
Designs and Analysis of Algorithms Assignment # 3 Fall 2023 Submitted By: Eeman ljaz 211-1381 DSM Submitted To: Dr. Ramoza AhsanQUESTION 1: [30 points] a) How can you improve the best case efficiency in bubble sort? (The input is already sorted) > Aboolean variable ‘swapped’ determines whether any swapping has happened in a particular iteration, if no swapping has occurred, then the given array is sorted and no more iterations are required. b) What is the best case efficiency of bubble sort in the improvised version? > Some iterations can be skipped if the list is sorted, hence efficiency improves to O(n). ©) The given array is input_array = {1,2,4,3}. Bubble sort is used to sort the array elements. How many iterations will be done to sort the array with an improvised version? > 4, Even though the first two elements are already sorted, bubble sort needs 4 iterations to sort the given array. d) Whatis the primary difference between merge sort and quicksort in terms of their stability as sorting algorithms? > Quicksort is an unstable sorting technique i.e. it might change the occurrence of two similar elements in the array while sorting. Whereas merge sort is a stable algorithm ie. it doesn't change the occurrence of similar elements(i.e. “equal” elements are ordered in the same order in the sorted list.) €) Define the concept of an “in-place” sorting algorithm and provide an example. Mention which sorting techniques are “in-place” > In-place means that the algorithm does not use extra space for manipulating the input but may require a small though non-constant extra space for its operation. Usually, this space is O(log n), though sometimes anything in O(n) (Smaller than linear) is allowed. Examples of in-place Sorting Algorithms:- Bubble Sort. Is the heap sort always better than the quick sort? Heapsort's runtime is always O(nlogn), but it is generally considered slower than quicksort. In practice, it is used in combination with quicksort: if quicksort picks a wrong pivot several times in sequence, the sorting switches to heapsort VwQUESTION 2 : [20 points] (Codes in notebook) In mergeSort() use count variable to store final answer ‘Add the answer returned from mergeSort() of the left half, mergeSort() of the right half, and merge() to the count. Retum count from mergeSort() © initialize count to 0 1 O(n’) © Innitialize array A 1 © Loop iO to N-1 nt © Inner Loop j=i+1 to N nx (nt) © if Ali] > Al] then 1x1nx/(n-1) © count++ 1 xnx(n-1) © print count 1xnx(n-1) 1 (n-1) + 4n(n-1) +3 n-1+4n?-4n+3 4n?-3n+2 © initialize count to 0 inside merge() mergeSort(): O(nlogn) © while comparing alleft] and alright] in| nLog.n the 3rd step of merge() © if afleft] > afright] then merge(): © count+= mid-left#1 4n2 © return this count from merge() to mergeSort() nLog,n + 4n/2QUESTION 3: [10 Points] (Code in notebook) © Initialize array A * Call heapSort(A): 200000000 For loop staring from end of array Call heapify(A, n) to maintain max-heap Create an empty "sorted" array for the sorted values. Start from the end of the array. Get max element from heap (root) Place in sorted_array and heapify. Repeat until all elements are sorted and stored in “sorted” array Duplicates remain in original order Retum © Display “sorted” arrayQuestion & - S /\ | © 6® i o8 ean m nf ON» f 3 BR rs © aD jh ah lex ee aE eeeQUESTION 5: [25 points] (In Notebook)
You might also like
Bubble Sort
PDF
No ratings yet
Bubble Sort
16 pages
Sorting: What Makes It Hard? Chapter 7 in DS&AA Chapter 8 in DS&PS
PDF
No ratings yet
Sorting: What Makes It Hard? Chapter 7 in DS&AA Chapter 8 in DS&PS
20 pages
Practice_Quiz_Sort
PDF
No ratings yet
Practice_Quiz_Sort
7 pages
AL102_M6-M8_ REVIEWER
PDF
No ratings yet
AL102_M6-M8_ REVIEWER
5 pages
Sorting Algorithms - Presentation
PDF
0% (1)
Sorting Algorithms - Presentation
32 pages
Sorting 2
PDF
No ratings yet
Sorting 2
26 pages
04 Sorting
PDF
No ratings yet
04 Sorting
13 pages
04 Sorting
PDF
No ratings yet
04 Sorting
13 pages
CSCE 3110 Data Structures & Algorithm Analysis: Rada Mihalcea Sorting (II) Reading: Chap.7, Weiss
PDF
No ratings yet
CSCE 3110 Data Structures & Algorithm Analysis: Rada Mihalcea Sorting (II) Reading: Chap.7, Weiss
26 pages
Data Structures and Algorithms (COMP232)
PDF
No ratings yet
Data Structures and Algorithms (COMP232)
5 pages
Case Study
PDF
No ratings yet
Case Study
6 pages
Comparison of Various Sorting Algorithms - A Review
PDF
No ratings yet
Comparison of Various Sorting Algorithms - A Review
4 pages
(A) What Is Randomized Quicksort? Analyse The Expected Running Time of Randomized Quicksort, With The Help of A Suitable Example. Answer
PDF
No ratings yet
(A) What Is Randomized Quicksort? Analyse The Expected Running Time of Randomized Quicksort, With The Help of A Suitable Example. Answer
14 pages
L9_sorting
PDF
No ratings yet
L9_sorting
50 pages
Algo 2
PDF
No ratings yet
Algo 2
9 pages
Insertion Merge Sort
PDF
100% (2)
Insertion Merge Sort
25 pages
5.1.sorting_Theory
PDF
No ratings yet
5.1.sorting_Theory
3 pages
Data Structures & Algorithm Analysis
PDF
No ratings yet
Data Structures & Algorithm Analysis
26 pages
sorting
PDF
No ratings yet
sorting
47 pages
Unit 1 DSA
PDF
No ratings yet
Unit 1 DSA
50 pages
Sorting
PDF
No ratings yet
Sorting
43 pages
Comparación de Los Algoritmos de Busqueda.
PDF
No ratings yet
Comparación de Los Algoritmos de Busqueda.
11 pages
DS Reassessment of PLO 2
PDF
No ratings yet
DS Reassessment of PLO 2
5 pages
Sorting Search New
PDF
No ratings yet
Sorting Search New
15 pages
Sorting Lecture-5 DAA
PDF
No ratings yet
Sorting Lecture-5 DAA
68 pages
1010043316-Ada - Ce-Lab Manual Final Version
PDF
No ratings yet
1010043316-Ada - Ce-Lab Manual Final Version
68 pages
Sorting Alorithms
PDF
No ratings yet
Sorting Alorithms
45 pages
Sorting Algorithms
PDF
No ratings yet
Sorting Algorithms
19 pages
LEARNING MATERIALS-Algorithm-UNIT2 [MODIFIED]
PDF
No ratings yet
LEARNING MATERIALS-Algorithm-UNIT2 [MODIFIED]
63 pages
UNIT IV - Searching and Sorting
PDF
No ratings yet
UNIT IV - Searching and Sorting
21 pages
Analysis & Design of Algorithms
PDF
No ratings yet
Analysis & Design of Algorithms
8 pages
Sorting and Searching
PDF
No ratings yet
Sorting and Searching
45 pages
36_BigO_Sort
PDF
No ratings yet
36_BigO_Sort
17 pages
SORTING ALGORITHM
PDF
No ratings yet
SORTING ALGORITHM
4 pages
221 Ch10
PDF
No ratings yet
221 Ch10
32 pages
Algorithm & Data Structure Lec2 (BET)
PDF
No ratings yet
Algorithm & Data Structure Lec2 (BET)
49 pages
DS Reassessment of PLO 2
PDF
No ratings yet
DS Reassessment of PLO 2
4 pages
Data Structures and Algorithms (CS F211) Sorting
PDF
No ratings yet
Data Structures and Algorithms (CS F211) Sorting
4 pages
Comparison of Sorting Algorithms Based On Input Sequences: Ashutosh Bharadwaj Shailendra Mishra
PDF
No ratings yet
Comparison of Sorting Algorithms Based On Input Sequences: Ashutosh Bharadwaj Shailendra Mishra
4 pages
General Sorting Algorithm Note (2)
PDF
No ratings yet
General Sorting Algorithm Note (2)
8 pages
Chapter 2
PDF
No ratings yet
Chapter 2
12 pages
Sorting Algorithms 2
PDF
No ratings yet
Sorting Algorithms 2
26 pages
Data Structures Unit 2 SPJ Sorting
PDF
No ratings yet
Data Structures Unit 2 SPJ Sorting
57 pages
DSD Unit 3 Sorting and Searching
PDF
No ratings yet
DSD Unit 3 Sorting and Searching
36 pages
T9_ans
PDF
No ratings yet
T9_ans
5 pages
Sorting Final
PDF
No ratings yet
Sorting Final
34 pages
CS205_Lab01_ReportA
PDF
No ratings yet
CS205_Lab01_ReportA
9 pages
Quick Sort Analysis
PDF
No ratings yet
Quick Sort Analysis
11 pages
07 SortingAlgorithms
PDF
No ratings yet
07 SortingAlgorithms
41 pages
CDS S3
PDF
No ratings yet
CDS S3
6 pages
Sorting
PDF
No ratings yet
Sorting
64 pages
Sorting Algorithms
PDF
No ratings yet
Sorting Algorithms
6 pages
Ch3. Sorting Techniques
PDF
No ratings yet
Ch3. Sorting Techniques
30 pages
dsa
PDF
No ratings yet
dsa
5 pages
DSA Chapter 8 - Advanced Sorting and Searching
PDF
No ratings yet
DSA Chapter 8 - Advanced Sorting and Searching
50 pages
Leftovers As Exercises in Class
PDF
No ratings yet
Leftovers As Exercises in Class
18 pages
Sorting Techniques
PDF
No ratings yet
Sorting Techniques
6 pages