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
6 pages
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
Save
Save Algorithm assignment For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
0 ratings
0% found this document useful (0 votes)
7 views
6 pages
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
Carousel Previous
Carousel Next
Download
Save
Save Algorithm assignment For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
Download
Save Algorithm assignment For Later
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
Dsu Notes (CH2)
PDF
No ratings yet
Dsu Notes (CH2)
15 pages
Sorting Algorithms - Presentation
PDF
0% (1)
Sorting Algorithms - Presentation
32 pages
Data Structures & Algorithm Analysis
PDF
No ratings yet
Data Structures & Algorithm Analysis
26 pages
Data Structures and Algorithms (COMP232)
PDF
No ratings yet
Data Structures and Algorithms (COMP232)
5 pages
Comparación de Los Algoritmos de Busqueda.
PDF
No ratings yet
Comparación de Los Algoritmos de Busqueda.
11 pages
Insertion Merge Sort
PDF
100% (2)
Insertion Merge Sort
25 pages
Algorithm & Data Structure Lec2 (BET)
PDF
No ratings yet
Algorithm & Data Structure Lec2 (BET)
49 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
Quick Sort Analysis
PDF
No ratings yet
Quick Sort Analysis
11 pages
T9 Ans
PDF
No ratings yet
T9 Ans
5 pages
5.1.sorting Theory
PDF
No ratings yet
5.1.sorting Theory
3 pages
Analysis & Design of Algorithms
PDF
No ratings yet
Analysis & Design of Algorithms
8 pages
DS Reassessment of PLO 2
PDF
No ratings yet
DS Reassessment of PLO 2
5 pages
Sorting Algorithms
PDF
No ratings yet
Sorting Algorithms
19 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
04 Sorting
PDF
No ratings yet
04 Sorting
13 pages
SR 211114140358
PDF
No ratings yet
SR 211114140358
9 pages
Sorting Search New
PDF
No ratings yet
Sorting Search New
15 pages
Sorting
PDF
No ratings yet
Sorting
47 pages
221 Ch10
PDF
No ratings yet
221 Ch10
32 pages
DSD Unit 3 Sorting and Searching
PDF
No ratings yet
DSD Unit 3 Sorting and Searching
36 pages
Unit 1 DSA
PDF
No ratings yet
Unit 1 DSA
50 pages
Sorting Algorithm
PDF
No ratings yet
Sorting Algorithm
4 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
36 BigO Sort
PDF
No ratings yet
36 BigO Sort
17 pages
Practice Quiz Sort
PDF
No ratings yet
Practice Quiz Sort
7 pages
Chapter 2
PDF
No ratings yet
Chapter 2
12 pages
Sorting and Searching Algorithms
PDF
No ratings yet
Sorting and Searching Algorithms
6 pages
UNIT IV - Searching and Sorting
PDF
No ratings yet
UNIT IV - Searching and Sorting
21 pages
Sorting Alorithms
PDF
No ratings yet
Sorting Alorithms
45 pages
Sorting and Searching
PDF
No ratings yet
Sorting and Searching
45 pages
1010043316-Ada - Ce-Lab Manual Final Version
PDF
No ratings yet
1010043316-Ada - Ce-Lab Manual Final Version
68 pages
Al102 - M6-M8 - Reviewer
PDF
No ratings yet
Al102 - M6-M8 - Reviewer
5 pages
LEARNING MATERIALS-Algorithm-UNIT2 (MODIFIED)
PDF
No ratings yet
LEARNING MATERIALS-Algorithm-UNIT2 (MODIFIED)
63 pages
DS Unit - 5
PDF
No ratings yet
DS Unit - 5
18 pages
Bubble Sort
PDF
No ratings yet
Bubble Sort
16 pages
Algo 2
PDF
No ratings yet
Algo 2
9 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
04 Sorting
PDF
No ratings yet
04 Sorting
13 pages
Tutorial 4 Set 1
PDF
No ratings yet
Tutorial 4 Set 1
3 pages
Sorting Final
PDF
No ratings yet
Sorting Final
34 pages
CS205 Lab01 ReportA
PDF
No ratings yet
CS205 Lab01 ReportA
9 pages
Sorting 2
PDF
No ratings yet
Sorting 2
26 pages
Sorting
PDF
No ratings yet
Sorting
43 pages
Data Structures Unit 2 SPJ Sorting
PDF
No ratings yet
Data Structures Unit 2 SPJ Sorting
57 pages
Sorting Algorithm
PDF
No ratings yet
Sorting Algorithm
34 pages
Sorting Lecture-5 DAA
PDF
No ratings yet
Sorting Lecture-5 DAA
68 pages
L9 Sorting
PDF
No ratings yet
L9 Sorting
50 pages
Sort
PDF
No ratings yet
Sort
3 pages
General Sorting Algorithm Note
PDF
No ratings yet
General Sorting Algorithm Note
8 pages
LEC 9 Sorting
PDF
No ratings yet
LEC 9 Sorting
87 pages
Unit 1
PDF
No ratings yet
Unit 1
116 pages
Sorting
PDF
No ratings yet
Sorting
5 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
(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