RUVIDEO
Поделитесь видео 🙏

BFS -4 - Easy - Binary Tree Average Level order traversal - Java

📁 Обучение 👁️ 17 📅 02.12.2023

Coding Interviews - Binary Tree Average Level order traversal (LeetCode)
This interview question is commonly asked by companies like Meta, Amazon, Snap.
This problem follows the Binary Tree Level Order Traversal pattern. We can follow the same BFS approach and use a queue to efficiently traverse in BFS fashion. The only difference will be that instead of keeping track of all nodes of a level, we will only track the running sum of the values of all nodes in each level. In the end, we will append the average of the current level to the result array.

Link to previous problem
Binary Tree Level order traversal - BFS - https://youtu.be/OlEnmYOEIjM
Binary Tree Level order traversal 2 - BFS - https://youtu.be/QaJ322crQIY
Binary Tree Zigzag Level Order Traversal - BFS -3 - https://youtu.be/zIPTg8hyt04


Time Complexity -
The time complexity of the above algorithm is O(N), where ‘N’ is the total number of nodes in the tree. This is due to the fact that we traverse each node once.

Space Complexity -
The space complexity of the above algorithm will be O(N) as we need to return a list containing the level order traversal. We will also need O(N) space for the queue. Since we can have a maximum of N/2 nodes at any level (this could happen only at the lowest level), therefore we will need O(N) space to store them in the queue.

Know more about me
LinkedIn - https://www.linkedin.com/in/umang-mavani/

Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «BFS -4 - Easy - Binary Tree Average Level order traversal - Java», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.

Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.

Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!

Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.