0% found this document useful (0 votes)
11 views1 page

Case Analysis & Stable Matching Algorithms

The document is a tutorial on algorithms and stable matching, covering topics such as best, worst, and average case analysis for various sorting algorithms. It includes questions on Insertion Sort input design, the Gale-Shapley algorithm for stable matching, and preference lists for men and women in matching scenarios. The tutorial aims to provide derivations, proofs, and comparisons of different matching models and their efficiencies.

Uploaded by

nigh20fury
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views1 page

Case Analysis & Stable Matching Algorithms

The document is a tutorial on algorithms and stable matching, covering topics such as best, worst, and average case analysis for various sorting algorithms. It includes questions on Insertion Sort input design, the Gale-Shapley algorithm for stable matching, and preference lists for men and women in matching scenarios. The tutorial aims to provide derivations, proofs, and comparisons of different matching models and their efficiencies.

Uploaded by

nigh20fury
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

(Best/Worst/Avg) Case Analysis &

Stable Matching
DAA - Tutorial 03
Dr. A. Tiwari & Dr. G. Mishra

Q. 1 For the Algorithms: (1) Linear Search, (2) Binary Search, (3) Selection Sort, (4) Bubble
Sort, (5) Insertion Sort.
Find the following for an array of size n:
(a) What is number of comparison in Best / Worst / Average case? Give the derivations.
(b) What is number of data swap in Best / Worst / Average case? Give the derivations.
(c) What is the time complexity for Best / Worst / Average case?
Q. 2 Insertion Sort Input Design Insertion Sort is O(n) in the best case and O(n2 in the worst
case.
(a) For an array of integers 1 to n, design inputs that achieve best, worst, and exactly halfway
performance between the two.
(b) Prove your halfway input case runs in θ(n2 /2)
(c) Explain whether this input is unique.
Q. 3 Use the Gale-Shapley algorithm to find a stable matching for the following set of four colleges,
four students, and their preferences.
College Preference List Student Preference List
A 1>3>4>2 1 B>C>D>A
B 1>2>3>4 2 A>B>C>D
C 3>1>2>4 3 C>D>A>B
D 2>1>4>3 4 B>D>A>C

(a) What matching do you get, if you use the students propose model?
(b) What matching do you get, if you use the colleges propose model?
(c) Which of (a) and (b) do you think makes more sense in this situation?
Q. 4 In a stable matching problem, consider a group of 4 men, M = {A, B, C, D} and a group of 4
women, W = {1, 2, 3, 4}, who have the following matching preferences

A 4, 1, 3, 2 1 A, B, C, D
B 1, 2, 4, 3 2 D, B, A, C
C 1, 2, 4, 3 3 D, C, A, B
D 2, 4, 1, 3 4 D, C, B, A

Men’s preferences Women’s preferences

Find the stable matching between all men and women, assuming
(a) Men propose women and the algorithm chooses free men in a round-robin fashion (i.e.,
A, B, C, D, A, B, ...).
(b) In the above question, if all men have different preference, what is the average number of
steps for each man to achieve a stable match?
(c) If all men have same preference, what is the average number of steps for each man to
achieve a stable match?

1 DAA - Tutorial 03

Common questions

Powered by AI

For selection sort, the number of swaps is always n-1 as exactly one swap per pass is needed to put the minimum element at its correct place . In bubble sort, for the best case, when the array is already sorted, no swaps occur, while worst and average cases require n(n-1)/2 swaps particularly when every pair must be swapped (reversed array).

For insertion sort, a sorted array gives best-case performance of O(n), a descending array gives worst-case performance O(n²) where every element needs to be rearranged . A half-way input can be an array sorted up to a certain point, requiring quadratic shifts for half the elements, proving a θ(n²/2) time complexity. This configuration isn't unique as different partial ordering can yield same time complexity .

For linear search, best case is 1 comparison, worst and average are n comparisons analyzed from searching the entire array . Binary search in best case requires 1 comparison, worst case is log(n), and average case involves log(n) comparisons as it divides the array each time . Selection sort performs n-1 + n-2 + ... + 1 = n(n-1)/2 comparisons in all cases . Bubble sort in best case makes no swaps (array is sorted), otherwise n(n-1)/2 comparisons as it checks adjacent elements iteratively . Insertion sort requires n-1 comparisons in best case and n(n-1)/2 in the worst case, as elements are compared and shifted .

When students propose: Student 1 pairs with College B, 2 with A, 3 with C, and 4 with D provides student-optimal pairing . With colleges proposing: College preferences lead to 1 with A, 2 with B, 3 with C, 4 with D, favoring colleges' first choice . The models highlight different aspect priorities where the proposing entity dictates result favorability .

Student-propose generates student-advantageous matches through students' top schools, often consulting overall compatibility improved. College-propose favors institutions owning choice leverage favoring institutional interest . The outcomes differ by yielding contrasting optimality arguably adhering to match stability with societal roles fullfilled distinctly .

Obtaining best, worst, and average analysis unveils comprehensive efficiencies, illuminating edge-case robustness and task-specific adaptability . Understanding these aspects underpins algorithm choice validity in practical deployment optimizing opex and throughput under various scenarios . This predictive power roots reliability assessments crucial to robust software engineering frameworks .

Bubble sort's best case is O(n), as a sorted array only once confirms no swaps needed . Worst-case and average both are O(n²) as every pair is sequentially checked and swapped over complete passes especially in an inverted list . Its simplistic adjacent check drives repetitive crosswise comparisons explaining poorer complexity metrics .

Men proposing yields a matching where each man gets his highest preference among the available women sequentially . The accepted proposal prioritizes men, iterating over unengaged women optimally per round-robin selection ensuring a male-optimal stable matching with all women accommodated .

With identical preferences among men, each man targets the same top woman, causing multiple rejections until each moves down their list. The repeated rejection results in O(n²) proposals . Such preference clashes extend the process significantly as no man secures a match until forced down their list substantively .

You might also like