## What’s a quick test to see if an $n \times n$ matrix is diagonal and/or proporitional to the identity matrix?

As the title indicates, I want to test whether an $$n \times n$$ matrix (numeric, symbolic,..) is diagonal and/or proportional to the $$n \times n$$ identity matrix. I, of course, can test whether the $$n^2-n$$ individual off-diagonal entries are zero–but that’s, it would seem, is inefficient.

## Analysing worst case time complexity of quick sort for various cases

I am trying to understand worst case time complexity of quick sort for various pivots. Here is what I came across:

1. When array is already sorted in either ascending order or descending order and we select either leftmost or rightmost element as pivot, then it results in worst case $$O(n^2)$$ time complexity.

2. When array is not already sorted and we select random element as pivot, then it gives worst case “expected” time complexity as $$O(n log n)$$. But worst case time complexity is still $$O(n^2)$$. [1]

3. When we select median of [2] first, last and middle element as pivot, then it results in worst case time complexity of $$O(n log n)$$ [1]

I have following doubts

D1. Link 2 says, if all elements in array are same then both random pivot and median pivot will lead to $$O(n^2)$$ time complexity. However link 1 says median pivot yields $$O(n log n)$$ worst case time complexity. What is correct?

D2. How median of first, last and middle element can be median of all elements?

D3. What we do when random pivot is ith element? Do we always have to swap it with either leftmost or rightmost element before partitioning? Or is there any algorithm which does not require such swap?

## Quick Clarification Question about Time Complexity in CLRS

Interviewing has a low cost, say $$c_i$$, whereas hiring is expensive, costing $$c_h$$. Letting $$m$$ be the number of people hired, the total cost associated with this algorithm is $$O(c_in+c_hm)$$.

For clarification, this is the algorithm being referred to

HIRE-ASSISTANT(n)     best = 0 // candidate 0 is a least-qualified dummy candidate      for i = 1 to n     interview candidate i     if candidate i is better than candidate best         best = i         hire candidate i 

My question is, why does the book say the total cost is $$O(c_in+c_hm)$$ and not $$\Theta(c_in+c_hm)$$? For any input, since we must iterate over all $$n$$ candidates and given that $$m$$ are hired, couldn’t we also say that the asymptotic lower bound is $$\Omega(c_in+c_hm)$$ therefore saying the cost for any input is $$\Theta(c_in+c_hm)$$?

## Quick Sale / Specific Niche / Perfect for Car Dealership Owners

Hey guys,

Selling my website: Reselling / selling Carfax reports.

This is best for those who own a car dealership in the US or EU and who get Carfax unlimited reports.

Or you can always find someone who sells Carfax for cheap and re-sell it.

#10 Position in Google – Keyword "Cheap Carfax"