Skip to content

jieun-dev1/java-algorithm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

110 Commits
 
 
 
 

Repository files navigation

Below is an English translation of the notes:

When analyzing only the inner while (excluding the outer for loop):

  • Starting from both ends (left = i + 1, right = n - 1): left only increases and right only decreases, so each pointer moves at most n times, giving O(n) for the inner loop. (They never "chase" each other; movement is strictly one direction.)
  • Starting with right = left + 1: To adjust the sum, right must be pushed far, and every time left changes, right needs to move a lot again. So even the inner part tends toward O(n^2)-level movement.

Therefore, looking only at the inner loop:

  • Both-ends start: O(n)
  • right = left + 1: near O(n^2) of unnecessary movement

Notes on sorting:

Arrays.sort for int[] uses Dual-Pivot Quicksort, with average/worst-case O(n log n). Overall time complexity is O(n^2), and including sorting it becomes O(n log n + n^2) = O(n^2).

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors