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

BFS 2 - Easy - Binary Search Level Order Traversal 2 - Java смотреть онлайн

📁 Обучение 👁️ 16 📅 05.12.2023

Coding Interviews - Binary Search Level Order Traversal 2 (LeetCode)
This interview question is commonly asked by companies like Facebook, Amazon, Google.
We can use a Queue to efficiently traverse in BFS fashion. Here are the steps of our algorithm:

1.Start by pushing the root node to the queue.
2.Keep iterating until the queue is empty.
3.In each iteration, first count the elements in the queue (let’s call it levelSize). We will have these many nodes in the current level.
4.Next, remove levelSize nodes from the queue and push their value in an array to represent the current level.
5.After removing each node from the queue, insert both of its children into the queue.
6.If the queue is not empty, repeat from step 3 for the next level.

Link to previous problem
Binary Tree Level order traversal - BFS - https://youtu.be/OlEnmYOEIjM

In this problem, we will use a LinkedList instead of an ArrayList for our result list. As in the case of ArrayList, appending an element at the beginning means shifting all the existing elements. Since we need to append the level array at the beginning of the result list, a LinkedList will be better, as this shifting of elements is not required in a LinkedList.

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 2 - Easy - Binary Search Level Order Traversal 2 - Java» бесплатно и без регистрации, вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.

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

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

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