The brute force algorithm has a worst-case efficiency of $O(n^2)$
A better approach to this would be to find the uniqueness of the element by pre-sorting (instance simplification)
ALGORITHM PresortElementUniqueness(A[0...n-1])
sort array A
for i <- 0 to n-2 do:
if A[i] = A[i+1] return false
return true
Time complexity → $T(n) = T_{sort}(n) + T_{scan} n = O(n \space log n)$
Heap → Partially ordered data structure that is suitable for implementing priority queues. It is a binary tree with keys assigned to its nodes, one key per node.
Conditions for heap:
Properties of heap:
Algorithm HeapBottomUp(H[1...n])
// Constructs a heap from the elements of a given array
for i <- floor(n/2) downto 1 do:
k <- i; v <- H[k]
heap <- false
while not heap and 2k <= n do:
j <- 2k
if j < n // there are 2 children
if H[j] < H[j+1]:
j <- j+1
if v >= H[j]:
heap <- true
else H[k] <- H[j]; k <- j
H[k] <- v
Heap sort is a 2-stage algorithm:
Arrays are eliminated in decreasing order

Complexity of Heap sort ≤ $2n \space log_2n$
Heap sort can be used to implement priority queues and Dijkstra’s algorithm.