Giter Club home page Giter Club logo

modified_avl_tree's Introduction

Author	:	Chirag R. Agarwal
Email	:	[email protected]
Problem	:	Implemeting a modified AVL tree in python
Site	:	http://agarwalchirag.wordpress.com

Idea :- To implement insert and delete operations for a modified AVL tree.

Statement :- You will be given 2 sequences of numbers. You have to insert the first sequence into a BST such that for every node, the difference between the left and right height is atmost 2. You have to use the second sequence to delete nodes from the BST. After each operation you must print the preorder traversal of the BST.

Input format :-
NI <Number of nodes to be inserted>
NI integers
ND <Number of nodes to be deleted>
ND integers

Sample Input :-
10
10 20 30 40 25 23 22 50 60 70
5
25 23 10 20 22

Sample Output :-
10
10 20
10 20 30
20 10 30 40
20 10 30 25 40
20 10 30 25 23 40
25 20 10 23 22 30 40
25 20 10 23 22 30 40 50
25 20 10 23 22 40 30 50 60
25 20 10 23 22 40 30 50 60 70
30 20 10 23 22 50 40 60 70
30 20 10 22 50 40 60 70
30 20 22 50 40 60 70
30 22 50 40 60 70
50 30 40 60 70

--- NOTE :

I print the tree after inserting all the nodes. Next, after every deletion, I print the tree in a formatted manner rather than the pre-order traversal for better understanding. The output is formatted as follows :

All the nodes at the same level in the tree are equidistant from the starting line i.e. same number of tabs from the start.
The root is at the start (0 tabs). The nodes at level 1 are at 1 tab space from the start.

For the above sample input, the inserted tree would be :

25
  20
    10
    23
      22
  40
    30
    50
      60
        70

At the end I print the preorder traversal of the final tree too.

modified_avl_tree's People

Contributors

chiragragarwal avatar

Watchers

James Cloos avatar

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.