Reflection logo

Reflect

3

Algorithm Explanation 📖

  1. 1️⃣ The app receives an array with at least three positive integers.
  2. 2️⃣ The idea is that you enter an array with a mirror! A number at some part of the array that separates it.
  3. 3️⃣ Mirror's left side must sum the same amount as mirror's right side.
  4. 4️⃣ The computer will establish two pointers, one for the left side, and the other for the right side.
  5. 5️⃣ Each pointer will advance to the center of the array, taking into consideration the current sum of each side until each pointer.
  6. 6️⃣ The algorithm will iterate n - 3 times, and n is the length of your array.
  7. 7️⃣ Why n - 3? Because both pointers are initialized before the loop begins... And, do you remember the mirror? Well, that's the third.
  8. 8️⃣ Big O is a notation to measure an algorithm's performance, taking into consideration space and time consumption.
  9. 9️⃣ As you read, this algorithm is going to iterate n - 3 times... However, for big arrays, the 3 doesn't produce a significant difference, so it is discarded.
  10. 🔟 But... What about the space? Well, the algorithm only uses a few variables. Doesn't matter how long your array is, the algorithm will use the same space to reach the solution.
  11. 🌟 Concluding... the algorithm of this web app performs with a time Big O of O(n) regarding time complexity... And O(1) regarding space complexity. It's awesome! Isn't it?