Giter VIP home page Giter VIP logo

binary-trees's Introduction

πŸ‘‹ Hey!

I am Rishabh this side!

πŸ‘¨β€πŸ’» Code Lover Β Β  🌏 OSS @webpack Β Β  πŸ‘¨πŸ½β€πŸ’» Product Engineer at Sprinklr Β Β  ❀ JS, C++, Python

Let's connect!

LinkedInΒ Β  gmailΒ Β  Twitter

icons from https://simpleicons.org/

binary-trees's People

Contributors

rishabh3112 avatar

Watchers

 avatar  avatar  avatar

binary-trees's Issues

Diameter of Binary Tree (without using pair)

Question

Given a binary tree, find it's diameter which is the largest distance possible between any two nodes

Input Format

A binary tree in level order format

Output
diameter

Preorder Binary Tree

Question

Given a binary tree, print the preorder traversal of given tree.

Pre-order traversal: Root -> Left -> Right

Input Format

Elements in level order form (separated by space)
(If any node does not have left or right child, take -1 in its place)

Output Format

Pre-order traversal, elements separated by space

Sum Of Nodes

Question

Given a binary tree, find and return the sum of all nodes.

Input format

Elements in level order form (separated by space). 
If any node does not have left or right child, take -1 in its place.

Construct Tree from Preorder and Inorder

Question

Given Preorder and Inorder traversal of a binary tree, create the binary tree associated with the traversals.You just need to construct the tree and return the root.

Note: Assume binary tree contains only unique elements.

Input format

Line 1 : n (Total number of nodes in binary tree)
Line 2 : Pre order traversal
Line 3 : Inorder Traversal

Output Format
Elements are printed level wise, each level in new line (separated by space).

Print ZigZag

Question

Given a binary tree, print the zig zag order i.e print level 1 from left to right, level 2 from right to left and so on. This means odd levels should get printed from left to right and even level right to left.

Input format

Elements in level order form (separated by space)
(If any node does not have left or right child, take -1 in its place)

Output Format

Elements are printed level wise, each level in new line (separated by space).

Height of Binary tree

Question

Given a binary tree, find and return the height of given tree.
Input format

Nodes in the level order form (separated by space).
If any node does not have left or right child, take -1 in its place

Output format
Height
Constraints
1 <= N <= 10^5

Find Node

Question

Given a Binary Tree and an integer x, check if node with data x is present in the input binary tree or not. Return true or false.
Input format

Line 1 : Elements in level order form (separated by space)
(If any node does not have left or right child, take -1 in its place)
Line 2 : Integer x

Output format
True or False

Level wise linkedlist

Question

Given a binary tree, write code to create a separate linked list for each level. You need to return the array which contains head of each level linked list.

Input format

Elements in level order form (separated by space).
If any node does not have left or right child, take -1 in its place.

Output format

Each level linked list is printed in new line (elements separated by space).

Mirror of Binary tree

Question

Mirror the given binary tree. That is, right child of every nodes should become left and left should become right.
Reference Image

Note : You don't need to print or return the tree, just mirror it.

Input format

Line 1 : Elements in level order form (separated by space)
(If any node does not have left or right child, take -1 in its place)

Output format
Elements in level order form (Every level in new line)

Diameter and height of Binary tree (using pair)

Question

Given a binary tree, find it's diameter which is the largest distance possible between any two nodes and height.

Input Format

A binary tree in level order format

Output
diameter and height

Remove Leaf Nodes

Question

Remove all leaf nodes from a given Binary Tree. Leaf nodes are those nodes, which don't have any children.

Note : Root will also be a leaf node if it doesn't have left and right child. You don't need to print the tree, just remove all leaf nodes and return the updated root.

Input format

Elements in level order form (separated by space)
(If any node does not have left or right child, take -1 in its place)

Output Format

Elements are printed level wise, each level in new line (separated by space).

Each level Print

Question

Given a binary tree, print the level order traversal. Make sure each level start in new line.
Input format

Elements in level order form (separated by space).
If any node does not have left or right child, take -1 in its place.

Output Format

Elements are printed level wise, each level in new line (separated by space).

Nodes without Sibling

Question

Given a binary tree, print all nodes that don’t have a sibling.

Edit : Print the elements in different lines. And order of elements doesn't matter.
Input format

Elements in level order form (separated by space).
If any node does not have left or right child, take -1 in its place.

Output format

Print nodes separated by new line.

is Balanced

Question

Given a binary tree, check if its balanced i.e. depth of left and right subtrees of every node differ by at max 1. Return true if given binary tree is balanced, false otherwise.

Input format

Elements in level order form (separated by space). 
If any node does not have left or right child, take -1 in its place.

Output format
boolean

Construct Tree from Postorder and Inorder

Question

Given Postorder and Inorder traversal of a binary tree, create the binary tree associated with the traversals.You just need to construct the tree and return the root.

Note: Assume binary tree contains only unique elements.

Input format

Line 1 : n (Total number of nodes in binary tree)
Line 2 : Post order traversal
Line 3 : Inorder Traversal

Output Format
Elements are printed level wise, each level in new line (separated by space).

Inorder traversal

Question

Given a binary tree, print the Inorder traversal of given tree.

In-order traversal: Left -> Root -> Right

Input Format

Elements in level order form (separated by space)
(If any node does not have left or right child, take -1 in its place)

Output Format

In-order traversal, elements separated by space

Postorder Binary Tree

Question

Given a binary tree, print the postorder traversal of given tree.

Post-order traversal: Left -> Right -> Root

Input Format

Elements in level order form (separated by space)
(If any node does not have left or right child, take -1 in its place)

Output Format

Post-order traversal, elements separated by space

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.