Solve the prefix sum puzzle in Java with Arrays, Vectors and even SIMD operations

  Рет қаралды 171

Cameron McKenzie

6 ай бұрын

The prefix sum problem is a common computer programming puzzle given on university exams and seen in online challenges like LeetCode and the programmer's advent calendar.
Here we take two approaches to solving the Prefix Sum array problem.
The first approach to the prefix sum problem is the traditional approach which uses two arrays and a loop. This approach will score you 10/10 on a college exam.
The second approach is inspired by an article written by Maxim Zaks named "Faster prefix sum computation with SIMD and Mojo." It's on Medium.
In that tutorial on how to do the prefix sum in the Mojo programming language by Modular, Maxim uses SIMD operations to speed up the logic.
In this tutorial I piggy-back off that example to see if I can do the same thing in Java with the new Java Vector API that is currently an incubating feature in Java 21.
It's a fun and fascinating approach, and if you're into AI, ML and modern computing APIs, this second approach to solving the prefix sum array problem will give you something to think about.
The second prefix sum solution in Java isn't 100% complete, so anyone interested in finishing off the Java Vector API based solution is encouraged to submit their ideas. I'd love to hear them!
(Image credit William R.J Ribeiro CC Sharealike
creativecommons.org/licenses/by-sa/4.0/deed.en)

Пікірлер
Vivaan  Tanya once again pranked Papa 🤣😇🤣
00:10
seema lamba
Рет қаралды 31 МЛН
MEU IRMÃO FICOU FAMOSO
00:52
Matheus Kriwat
Рет қаралды 45 МЛН
Vivaan  Tanya once again pranked Papa 🤣😇🤣
00:10
seema lamba
Рет қаралды 31 МЛН