Skip to content

Instantly share code, notes, and snippets.

@kaniket7209
Created October 26, 2021 12:25
Show Gist options
  • Save kaniket7209/7fb7488ea5a838eaaa1273815d8dff20 to your computer and use it in GitHub Desktop.
Save kaniket7209/7fb7488ea5a838eaaa1273815d8dff20 to your computer and use it in GitHub Desktop.
Level Order Traversal Of Binary Tree
1. Can we use hashmap functionality to travel linewise in binary tree?
Answer: Yes we can assign keys for different levels and store the values of childrens in levels and do so.
2. Can we use recursion to tarvel linewise in binary tree?
Answer: Yes we can but we have to use extra parameters for levels.
3. Can we use any other data structure despite queue to travel linewise in binary tree?
Answer: Yes we can use stack also.
1. Can we use queue to solve this.
2. Use RPA Algo(Remove, print and add)
3. Loop is iterated for all the children at a level.
4. Process is continued for all the elements of each level and then for the next level until the queue is empty.
1. The time complexity for Level Order Traversal Of Binary Tree is
a) O(1)
b) O(n)
c) O(log n)
d) O(nxn)
Answer: b) O(n)
2. The space complexity for Level Order Traversal Of Binary Tree is
a) O(1)
b) O(n)
c) O(log n)
d) O(nxn)
Answer: b) O(n)
3. The pre order traversal of a binary search tree is 15, 10, 12, 11, 20, 18, 16, 19.Which one of the following is the post order traversal of the tree?
a) 10, 11, 12, 15, 16, 18, 19, 20
b) 11, 12, 10, 16, 19, 18, 20, 15
c) 20, 19, 18, 16, 15, 12, 11, 10
d) 19, 16, 18, 20, 11, 12, 10, 15
Answer: b) 11, 12, 10, 16, 19, 18, 20, 15
4. The elements in pre order traversal of a binary search tree is always sorted. Is it True or false?
Answer: True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment