Тёмный

2D Prefix Sum and Submatrix Sum Queries 

Profound Academy
Подписаться 359
Просмотров 3,9 тыс.
50% 1

A 2-dimensional prefix sum is a powerful algorithmic technique used in computer science and mathematics to preprocess a given 2D grid or matrix, enabling efficient querying of summed values over rectangular subregions. In essence, it is an extension of the 1-dimensional prefix sum to two dimensions. This method involves constructing an auxiliary matrix of the same dimensions as the original, where each cell (i, j) contains the sum of all elements in the rectangular region formed by the top-left corner (0, 0) and the current position (i, j). Once this preprocessing is complete, the sum of any rectangular subregion can be calculated with only four array lookups and three arithmetic operations, significantly reducing the time complexity of repeated queries.
💻 Practice: profound.academy/algorithms-d...
📚 Full DSA Course: profound.academy/algorithms-d...
🎓 Teach with Profound Academy: profound.academy/teach
profound.academy
/ profound.academy.inc
/ profound.academy.inc
/ profound-academy-inc
Chapters:
0:00 2D Prefix Sum and Submatrix Sum Queries Problem Statement
0:19 Example Matrix
0:39 2D Prefix Sum
0:57 Submatrix Sum Query
2:05 Trick of Padding the Array With Zeros
2:29 2D Prefix Sum Array Calculation
3:26 Hands-on Practice on Profound Academy
3:37 Algorithm in Action
4:41 Time and Memory Complexity
#PrefixSum #Algorithm #DataStructures #2dPrefixSum #Algorithms #ProblemSolving #AlgorithmicInterview #InterviewPreparation #DataStructuresInterview #InterviewQuestions #TechInterview #TechInterviews #DSA #GoogleInterview #FAANG #Algorithms

Опубликовано:

 

11 июл 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 7   
@helloomkar
@helloomkar Месяц назад
Perfect explanation and viz needed for this concept. Glad i came to your video🎉🎉
@user-vz7wd9fh3c
@user-vz7wd9fh3c 2 месяца назад
Perfect illustration
@karenmirakyan1610
@karenmirakyan1610 Год назад
Well explained, waiting for other videos 👍
@florinseiler3764
@florinseiler3764 Год назад
Awesome video! Helped a lot
@HaykTarkhanyan
@HaykTarkhanyan Год назад
Awesome, keep it up
@DK-ox7ze
@DK-ox7ze Год назад
What's the logic behind calculating prefix sum for each cell? What's the intuition behind the formula you used?
@shashankbj3804
@shashankbj3804 5 месяцев назад
You should watch it again its in the video..
Далее