Question: How was the assumption made?
Jose Ross Barredo

Jose Ross Barredo @iamjoross

About: 25. Coder. Noob. INTP-T

Location:
Philippines
Joined:
Sep 7, 2017

Question: How was the assumption made?

Publish Date: Feb 20 '20
4 0

Hi guys! I have been reading "Cracking the Coding Interview 6th Edition".. On Chapter 0 - Big O, I have problem understanding an assumption made to a problem on Example 3.

void printUnorderedPairs(int[] array){
  for(int i = 0; i < array.length; i++){
    for(int j = i + 1; j < array.length; j++){
      ...
    }
  }
}

Under What It Means section, it assumed that:

There are N^2 total pairs. Roughly half of those will have i < j and the remaining half will have i > j. This code goes through roughly n^2/2 pairs so it does O(N^2) work.

My question is, how was the assumption made on Roughly half of those will have i < j and the remaining half will have i > j done? Can someone explain it to me please?

Thanks!

Comments 0 total

    Add comment