O(n2) and O(n(n - 1)) is the same in terms of big O notation. Are you sure you need set in your programs? Your slower program is because you add O(n2) elements to set. Maybe list or vector will be enough? Or iterating over elements instead of a new structure?
O(n2) and O(n(n - 1)) is the same in terms of big O notation. Are you sure you need
set
in your programs? Your slower program is because you add O(n2) elements toset
. Maybelist
orvector
will be enough? Or iterating over elements instead of a new structure?