Case Analysis & Stable Matching Algorithms
Case Analysis & Stable Matching Algorithms
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 .