MongoDB overView with Installation_procEss: SQL – Where all to UsE ?


MongoDB (from humongous) is a free and open-source cross-platform document-oriented database program. Classified as a NoSQL database program, MongoDB uses JSON-like documents with schemas. MongoDB is developed by MongoDB Inc. and is free and open-source, published under a combination of the GNU Affero General Public License and the Apache License. Any relational database has a typical schema design that shows number of tables and the relationship between these tables. While in MongoDB, there is no concept of relationship.

Document Database

A record in MongoDB is a document, which is a data structure composed of field and value pairs. MongoDB documents are similar to JSON objects. The values of fields may include other documents, arrays, and arrays of documents. Following is the example of MongoDB document 

MongoDB database document

Following are some advantages of using document database

  • Documents correspond to native data types in many programming languages.
  • Embedded documents and arrays reduce need for expensive joins.
  • Dynamic schema supports fluent Polymorphism.
Following are the features of MongoDB
  • MongoDB provides high performance data persistence.
  • MongoDB supports a rich query language to support read and write operations.
  • Extremely faster than RDBMS
  • It is easy to use and lightweight.
Lets see advantages of MongoDB over RDBMS
In recent days, MongoDB is a new and popularly used database. It is a document based, non relational database provider.
  • MongoDB is schema less. It is a document database in which one collection holds different documents.
  • Structure of a single object is clear in MongoDB.
  • There are no complex joins in MongoDB.
  • Uses internal memory for storing the (windowed) working set, enabling faster access of data.
  • MongoDB is easy to scale.
  • Conversion/mapping of application objects to database objects not needed.
Where MongoDB should be used?
  • Big and complex data
  • Mobile and social infrastructure
  • Content management and delivery
  • User data management
  • Data hub
Lets see how to install MongoDB on windows
Setp 1: Download MongoDB for Windows
Download the latest production release of MongoDB.
To find which version of Windows you are running, enter the following commands in the Command Prompt or Powershell:

Step 2: Install MongoDB
In Window explorer, locate the downloaded MongoDB msi file, double click on that file and follow the instructions appears on the screen. These instructions will guide you to complete the installation process.

Step3: Setup MongoDB Environment
MongoDB requires a data folder to store its files. The default location for the MongoDB data directory is c:datadb. So you need to create this folder using the Command Prompt.

Start If you want to start MongoDB, run mongod.exe or You can do it from command prompt by using following command
C:Program FilesMongoDBServer3.4binmongod.exe

This will start the mongoDB database process. If you get a message “waiting for connection” in the console output, it indicates that the mongodb.exe process is running successfully.
If you will get following error 
mongod error
then click here and follow the steps.

When you connect to the MongoDB through the mongo.exe shell, you should follow these steps:
1. Open another command prompt.
2. At the time of connecting, specify the data directory if necessary.

If you use the default data directory while MongoDB installation, there is no need to specify the data directory.
For example:
If you use the different data directory while MongoDB installation, specify the directory when connecting.
For example:
C:mongodbbinmongod.exe– dbpath d:testmongodbdata  

If you have spaces in your path, enclose the entire path in double space.
For example:
C:mongodbbinmongod.exe– dbpath  “d: testmongodbdata”
This will show that MongoDB is installed and run successfully.

MongoDB Help
To get a list of commands, type in MongoDB client. This will give you a list of commands.

MongoDB Statistics
To get stats about MongoDB server, type the command db.stats() in MongoDB client. This will show the database name, number of collection and documents in the database.

Learn Database Programming

Overhangs and supports in my 3D prints

Typical home 3D printers use the fused filament fabrication technology, which consists of melting a thread of plastic in a nozzle and building up the printed object with the molten plastic from the bottom up, layer by layer. As a consequence you can’t just print any shape you want: Everything needs to be connected to the bottom layer with an angle of no more than 45°. For my particular application, printing figurines of heroes and monsters for Dungeons & Dragons, that is certainly a problem. Think of a hero with his arm stretched out, holding a sword, or a dragon with spread wings: These parts are “overhangs”, which when seen from the bottom up start up in the air, and thus can’t be printed like that.

The solution to the problem is supports, temporary parts of the model for printing which are removed after the print is finished. Most printers even have software to automatically create such supports. Unfortunately for my particular printer, the XYZ Da Vinci jr. 1.0w, the automatically created supports don’t work very well. The software simply creates supports straight up from the bottom under every minor overhang. That creates far more supports than actually needed, wasting material and producing lots of ugly connection spots on the underside of the model.

For some time I created supports manually, using Tinkercad. That is somewhat fiddly, and also far from optimized. Again the supports I design are mostly straight up from the bottom. Choosing the right number of support points is somewhat hit and miss, so sometimes I print a model, see where my design didn’t really cover an overhang, and then have to add more supports.

But recently I found a much better solution. The free Autodesk Meshmixer software has the possibility to generate supports in the Analysis – Overhangs menu. There are even tons of parameters you can set to optimize those supports. And instead of simple straight up supports, the software produces angled and branched supports, which use much less material. You can also optimize the thickness of the support and the width of the tip to create supports that are stable to print but minimize the size of the connection points.

This software has quite opened up my possibilities of printing miniatures for my game. For example the Princes of the Apocalypse cover art shows a winged female with a spear. Between the wings and the spear she would have been nearly impossible for me to print. But now I printed her with the Meshmixer generated supports and even managed to make her “fly”, her feet not touching the ground. Now I’m only limited by the fragility of the wings and spear when printed at 1:60 scale.

Learn ABC of “A/B testing”

What is A/B Testing?

A/B Testing is one of the best way to compare two or more versions of an application or a web page.It enables you to determine which one of them performs better and can generate better conversion rates. You compare two web pages or applications by showing the two variants (let’s call them A and B) to similar visitors at the same time. The one that gives a better conversion rate, wins!

All websites on the web have a goal – a reason for them to exist

  • eCommerce websites want visitors buying products
  • SaaS web apps(Software as a service) want visitors signing up for a trial and converting to paid visitors
  • News and media websites want readers to click on ads or sign up for paid subscriptions

Every business website wants visitors converting from just visitors to something else. The rate at which a website is able to do this is its “conversion rate”. Measuring the performance of a variation (A or B) means measuring the rate at which it converts visitors to goal achievers.


Let us assume that there is a web page and all the traffic is directed to this page. Now as a part of A/B Testing, you have made some minor changes like headlines, numbering, etc. on the same page and half of its traffic is directed to the modified version of this web page. Now you have version A and version B of the same web page and you can monitor the visitor’s actions using statistics and analysis to determine the version that yields a higher conversion rate.

A conversion rate is defined as the instance, when any visitor on your website performs a desired action. A/B Testing enables you to determine the best online marketing strategy for your business. Take a look at the following illustration. It shows that version A yields a conversion rate of 15% and version B yields a conversion rate of 22%.

Why Should You do A/B Test?

A/B testing allows you to make more out of your existing traffic. While the cost of acquiring paid traffic can be huge, the cost of increasing your conversions is minimal. To compare, a Small Business Plan  whose cost is equivalent to 5 to 10 Google Adwords clicks. The Return On Investment of A/B testing can be massive, as even small changes on a landing page or website can result in significant increases in leads generated, sales and revenue.

Traffic vs Conversion rate

What Can You Test?

Almost anything on your website that affects visitor behavior can be A/B tested.

  1. Headlines
  2. Sub headlines
  3. Paragraph Text
  4. Testimonials
  5. Call to Action text
  6. Call to Action Button
  7. Links
  8. Images
  9. Content near the fold
  10. Social proof
  11. Media mentions
  12. Awards and badges
Advanced tests can include pricing structures, sales promotions, free trial lengths, navigation and UX experiences, free or paid delivery, and more.

A/B Testing Process

The correct way to run an A/B testing experiment is to follow a scientific process. It includes the following steps:

Study your Website Data: Use a website analytics tool such as Google Analytics, and find the problem areas in your conversion funnel. For example, you can identify the pages with the highest bounce rate. Let’s say, your homepage has an unusually high bounce rate.

Observe User Behavior: Utilize visitor behavior analysis tools such as Heatmaps, Visitor Recordings, Form Analysis and On-page Surveys, and find what is stopping the visitors from converting. For example, “The CTA button is not prominent on the home page.”

Construct a Hypothesis: Per the insights from visitor behavior analysis tools, build a hypothesis aimed at increasing conversions. For example, “Increasing the size of the CTA button will make it more prominent and will increase conversions.”

Test your Hypothesis: Create a variation per your hypothesis, and A/B test it against the original page. For example, “A/B test your original home page against a version that has a larger CTA button.” Calculate the test duration with respect to the number of your monthly visitors, current conversion rate, and the expected change in the conversion rate.

Analyze Test Data and Draw Conclusions: Analyze the A/B test results, and see which variation delivered the highest conversions. If there is a clear winner among the variations, go ahead with its implementation. If the test remains inconclusive, go back to step number three and rework your hypothesis.

Report results to all concerned: Let others in Marketing, IT, and UI/UX know of the test results and the insights generated.

A/B Testing – Tools

There are various tools that can be used to generate hypothesis and to run the variations, these include:

  • Visual Website optimizer (VWO)
  • Google Content Experiments
  • Optimizely

All these tools are capable to run A/B Tests and to find the winner, but to perform post analysis these tools should be integrated with Google Analytics.

A/B Testing – Google Analytics

Google Analytics has two options for analyzing the data −

  • Universal Analytics
  • Classic Google Analytics

New Universal Analytics feature allow you to use 20 concurrent A/B Tests sending data to Google Analytics, however the Classic version allows only up to five.

Integrating Optimizely with Google Universal Analytics

To integrate Optimizely in to Universal Google Analytics, first select the ON button on its side panel. Then you must have an available Custom to populate with Optimizely experiment data. Then the tracking code must be placed at the bottom of the  head section of your pages. Google Analytics integration will not function properly unless the Optimizely snippet is above this Analytics snippet.

Configuration Steps

Optimizely uses Universal Google Analytics’ “Custom Dimensions” to tag your visitors with the experiments and variations to which they’ve been added. Configuring Optimizely to begin sending this information to Universal Analytics requires four steps −

Step 1

Add the following JavaScript code to your site wherever the Universal Analytics code exists after the ga(‘create’…) function fires and before the Universal Analytics ga(‘send’,’pageview’) function fires and the tracking call is made (see details in the next section) −

// Optimizely Universal Analytics Integration
window.optimizely = window.optimizely || [];

Step 2

In the Optimizely Editor, go to Options → Integrations then click on the Universal Analytics checkbox to enable the integration.

Step 3

Select the custom dimension you would like Optimizely to use. You have to ensure that the Custom Dimension should not be in use already by any other part of your site, or by another currently-running Optimizely experiment.

Step 4

Select a Custom Tracker if you are using a custom event tracker other than the default. This will change Optimizely’s integration call to use the custom tracker rather than the default.

Creating a Custom Report using Google Analytics

First step is to log into your Universal Analytics account and click the Customization tab at the top. You should see a Custom Reports list.

Next is to set up a Custom Report for each experiment that you have integrated Universal Analytics with.

  • Click on the New Custom Report → Enter the report title and add the metric groups you wish to view in the report.
  • To filter this report for only your Optimizely experiment, choose the Custom Dimension you set up previously as one of the Dimension Drilldowns.
  • Add this dimension in the Filters section and use a Regex match on the experiment ID for the experiment you want to filter.
  • Click on Save.

Want to learn Digital Marketing?

Is the MMO Blogosphere still alive?

Back in the days when I was still blogging about MMORPGs and had thousands of visitors per day, I would get regularly pestered by various sites who made their living just aggregating content from blogs and other sites. Two days ago one of those sites contacted me again, telling me that I had been awarded a (virtual) medal as one of the Top 75 MMO Blogs on the web. Given how I haven’t blogged about MMOs for a long time, that made me wonder about the state of the MMO Blogosphere. If my dead blog is one of the top 75, then how does the rest look?

I surfed to a selection of those “top 75” MMO blogs, as well as other links I knew, and found they more or less all fell into two categories: Either they were dead, or they had changed to report on all sorts of multiplayer games, up to and including Pokemon Go. I didn’t see a single site still exclusively discussing the type of MMORPG that I would recognize under that term. Even right now as I check has the latest article being about Animal Crossing Pocket Camp, which really doesn’t fall into the definition of MMORPG for me.

Now obviously there are still millions of people playing MMORPGs. But blogging about them doesn’t appear to be a thing any more. Unlike other trends we know the exact date where MMO blogging peaked: The decline started on September 18, 2008, the day WAR was released, as the expectation had swelled the ranks of the MMO bloggers, and the reality let the air out of that bubble rather quickly. But as far as I can see that decline has continued over the last decade, powered both by the general decline of blogging as a form of expression on the internet in favor of tweeting, and by the decline of MMORPGs as a form of gaming in favor of other multiplayer games.

Am I wrong? Have I just overlooked a thriving MMO Blogosphere somewhere on the internet with thousands of daily readers? Or is this all a thing of a past that won’t come back?

Xiaomi’s Mi A1 Special Edition in Red is coming to India (updated)

Update (12/19/17): The gorgeous Xiaomi Mi A1 Special Edition is officially coming to India. Beginning December 20, customers will have the chance to order the Red version of the Mi A1 from and Flipkart’s online store. Additionally, the device will be available from Mi Home stores, Mi preferred partner stores, and other retail partners. The device will run customers Rs. 13,999.

December 20 is also the start of Xiaomi’s “No. 1 Fan Sale” in the country. Xiaomi is celebrating its fans with sales on phones like the Xiaomi Mi MIX 2, Mi Max 2, Redmi 4, Redmi Note 4, and Redmi Y1 Lite. The Mi MIX 2 will see a price drop from Rs. 35,999 to Rs. 32,999, while the Mi Max 2 will drop from Rs. 14,999 to Rs. 12,999. The Redmi 4 gets a Rs. 1,000 discount, while pricing details for the Redmi Note 4 and Redmi Y1 Lite have yet to be released yet.

You can get check out all of the deals on starting December 20.

Original article (12/14/17): It seems like red has caught on as a color of choice for smartphones, since OnePlus and Samsung have red versions of their flagship smartphones. Whether it’s because of that, or whether it’s because it’s the season for such a color, Xiaomi has joined the fray with the Mi A1 Special Edition.

Don’t let the name fool you; the only thing special about the Mi A1 Special Edition is the red color it comes in. That being said, the shade of red looks much less like Samsung’s Burgundy Red and more like OnePlus’ Lava Red, with the color choice meant to stand out than be more subtle.

Either way, it comes across as vibrant and stunning, with the added red color meaning that the Mi A1 is now available in four colors.

Elsewhere, the Mi A1 Special Edition remains identical to the normal Mi A1. In other words, you’ll find a 5.5-inch Full HD display, with a 5 MP camera up front and dual 12 MP cameras around back. Under the hood, Qualcomm’s Snapdragon 625 chipset and 4 GB of RAM power the phone, and while the processor might be a bit long in the tooth at this point, it allows for greater battery efficiency.

Editor’s Pick

That efficiency is what helps give the Mi A1 very good battery life in our testing, regardless of the modest 3,080 mAh battery. If the 64 GB of internal storage is not enough for your needs, the microSD card slot allows for up to 128 GB of additional storage.

Finally, the Mi A1’s story revolves around its status as one of the handful of Android One devices out there, which means that the phone runs stock Android 7.1.2 Nougat. That makes the phone the only Xiaomi smartphone that runs stock Android out of the box, something that slightly disoriented us at first but that we eventually got used to.

According to GizmoChina, which spotted the phone, the Mi A1 Special Edition is currently available in Indonesia for 3.099.000 rupiahs, which translate to roughly $228. There is no word if the phone will be available in other markets, though we’ll keep an eye out if it does.

Elemental Evil: Session 8

In the previous session the group had located the tower of the elemental cult of air and gained new allies in the form of a group of Aarakocra. They had decided to approach the tower through the Sighing Valley and try to sneak in from below with their allies helping them up the pillar the tower stands on. But first they needed to get there.

The Aarakocra informed them that basically they could go either left or right of the river dividing the valley. To the left was gnoll territory; not the most fearsome of adversaries, but many of them. To the right was the lair of a manticore, which was a much more dangerous beast, but alone. They went for the manticore. Now 6 adventurers hitting a single monster can make for short and boring fights. To avoid that I had placed the manticore out in the open, in plain view, so the fight started with the monster and the group 200 feet apart. Which just happened to be the maximum range of the manticore’s spike-slinging tail attack. 🙂 This ended up being a rather interesting fight, with the group using ranged attacks while closing in, and being under fire themselves. They won, but two group members went down during the fight and had to be saved by their team mates. In most rounds I decided to let the manticore fire its spikes on the closest enemy. However at one point the closest enemy was the druid who just had changed into bear form. So at that point I let the manticore make an intelligence check, which it failed, leading it to believe that this was an actual bear who had somehow wandered in and would be scared off easily by a threatening roar. At least the druid liked that idea; the halfling monk who got shot instead maybe not so much.

That fight got the group to level 4, so they took a long rest and leveled up. Then they continued up the valley, to the point where the stream was easy to cross. There the stream came out of a cave, and the Aarakocra had told them that air cultists had been seen hanging around that area. So they explored the cave and found three air cultist spellcasters praying in front of a great door. As the cave was only as broad as the stream, the air cultists did get good use out of otherwise rather useless gust of wind spells (I ruled that a gust of wind gives disadvantage to non-magical missiles like arrows, because I was so surprised that in rules as written the spell doesn’t even do that). But they weren’t very strong and the party easily beat them.

The portal was showing a symbol they knew from the book on fighting elemental evil: It was the runes of the 4 elemental cults posed around the elder elemental eye. The door was clearly magical, and it appeared as if one needed the 4 runes of the 4 elemental cults to open the door. As they didn’t have any yet, they went on towards Feathergale Spire. They found some corpses at the base which suggested that sometimes people were thrown off the spire. At this point we ended the session.

[DM’s note: The magical portal isn’t in the Princes of the Apocalypse book. In the book as written you can go right down into the underground elemental dungeons. Only that of course the first dungeon downstairs is level 7, and would be quite deadly for a group of level 3 or 4 characters. And there would be no reason to visit the above-ground 4 elemental keeps, thus skipping a lot of the content of the adventure. A magical door on every entrance, with the 4 keys being held in the 4 keeps, seemed the logical solution for this design flaw to me.]

Understanding Out of the Abyss

*Spoiler Warning*: This post contains spoilers about the Dungeons & Dragons adventure “Out of the Abyss” (OotA).

My first contact with Out of the Abyss wasn’t great. I was a player in a campaign based on that book, but the DM was a) inexperienced and b) had removed the starting chapter and removed it by a series of other adventures before leading us down into the Underdark. Now I can see the motivation for that: OotA starts the players as slaves of the Drow, in shackles, without gear; a start that is both somewhat cliche for the genre, and not the most pleasant one for the players. However after preparing the adventure now for another group I see how this start is absolutely essential to the adventure. Removing it leads to exactly the problem we had, that is wandering through the Underdark with no motivation, being unclear of the goal and purpose of the adventure.

The whole first half of Out of the Abyss is motivated by that start: The players escape and are pursued by the Drow. They are looking for a way back to the surface, while having to survive a harsh and strange environment, and having to find means to equip themselves. It is dark fantasy, it is a game of survival. And it doesn’t work without that start in slavery. If you ever want to play this, ask your players first if they are okay with a dark survival campaign instead of the more generic heroic fantasy.

To understand Out of the Abyss one needs to see how it inverses the sandbox approach of certain other D&D adventures, for example Princes of the Apocalypse. In Princes of the Apocalypse the dungeons and encounters are described in much detail, but it is left to the DM and players to figure out how to get from one dungeon to the next. That doesn’t work very well, because the dungeons have different levels, and playing them through in an order other than by level results in problems. Out of the Abyss takes a very different approach: The main story from the start to at least the mid-point, escaping from the Underdark, is linear. You best play chapter 1 first, then chapter 2, then chapter 3, etc., because it makes sense geographically and story-wise. But what exactly happens in each of the chapters is left open and is to be created by the interactive storytelling between DM and player. Chapter 1 is very clear about this being about a prisoner escape, but how exactly the players escape from prison is left to them. If they don’t do anything the DM has some events that will push them in the right direction, but ideally the DM first lets the players try their own ideas, and allows any half reasonable plan to succeed. The goal is for the DM and the players to both drive the story forward. D&D should never be adversarial, and for OotA it wouldn’t work at all if the DM didn’t “help” the players to escape.

One of the early highlights of that approach is chapter 4, Gracklstugh. There you get a complete description of a Duergar city in the Underdark, complete with who the different power factions are and what their interaction is. But you are left to play that city as a sandbox, the adventure doesn’t tell you where to start or which faction to support. Played right this might be a great short city adventure on its own. The obvious disadvantage of the approach, and thus of all of Out of the Abyss, is that it requires a great amount of preparation and/or improvisation from the Dungeon Master. This is very much a campaign for expert DMs. And I’ll find out in how far it works with newbie players, because that is who I am going to play it with.

The 7th Continent

I received a parcel yesterday which contained the board game The 7th Continent. I had backed the production of that game on Kickstarter. I don’t often do that, it is only the 5th Kickstarter project I backed. But I am happy to report that with that parcel I am now at 100% success rate, every single Kickstarter project I backed actually delivered. Of course they all delivered late, The 7th Continent had an “expected” delivery in October 2016, and so is nearly a year late. I think a year late is about average of the projects I backed.

Kickstarter claims that only 9% of Kickstarter projects fail to deliver if successfully backed. But curiously they don’t back up that claim with hard data to which they should have access, but rather cite an opinion survey. Other sources claim much higher failure rates. And if you follow games media, stories about Kickstarter failures like this one aren’t all that uncommon. Furthermore as long as the developers deliver *anything*, that isn’t counted as a failure. That doesn’t mean that every delivered product lives up to the hype.

I think that only a very small part of Kickstarter failures are actual scams. I always apply Hanlon’s razor and easily explain failures with incompetence without having to imply malice. Some people are simply good at having bright ideas and marketing those ideas in an enthusiastic way, but are just plain bad at project management. Which both explains many of the total failures as well as the 75% to 84% late delivery rate of Kickstarter.

Of course I don’t back Kickstarter projects that are predictable failures, like people promising a large MMORPG for under $1 million. In general I would also advise to stay away from all Kickstarter projects for computer games: If the project is an actual success, you will be able to buy it later. So I rather back projects like The 7th Continent, which is so niche that it isn’t obvious that one can get the product outside of a Kickstarter campaign. If you want a copy of that board game, you’d actually have to back the Kickstarter for the second print run, it won’t be available in your neighborhood games store. I also sometimes back Kickstarter projects that are basically donations for a good cause, like rebuilding EN World.

In short, as long as you are aware of likelihood of failure, and the near certainty of late delivery, backing a Kickstarter project can be a good idea. Just don’t fall for the hype and get overly enthusiastic. Or you might still be waiting for Star Citizen 3 years later.

The NBA 2K franchise back with NBA 2K18 now in the Play Store

2K, Inc

  • NBA 2K18, the newest entry in the iconic franchise, is now on the Play Store
  • The game includes updated mechanics, an expanded script in career mode, and a new game mode
  • The soundtrack features artists like Kendrick Lamar, Naughty by Nature, and Nas

It’s never been a better time to be a sports fan with a smartphone. Not only are there an endless amount of apps like theScore and 365 Sports that keep you up to date on your teams, but sports games are getting better and better. Most of the important sports franchises are available as mobile versions now. The list includes ultra-popular titles like Madden, Fifa, NBA 2K18 and more.

The latest version of NBA 2K just hit the Play Store with a ton of improvements over last year’s version. New features like an improved MyCAREER mode and “The Association” mode join an improved soundtrack. In the updated career mode, the script has been expanded and more interactions are available for your player. Association Mode is a new multi-season mode that reminds us a lot of Dynasty Mode from other games. 

See also

Music has always been a staple of sports games and it’s no different for NBA 2K18. 2K promises an “eclectic mix” of music with artists like Future, Kendrick Lamar, Shakira, Nas and more. Gameplay controls are now improved and new gameplay mechanics like sprinting on defense are now included in the game. 

2K came under fire earlier this year for the console version of NBA 2K. The game is packed with microtransactions for everything from improving your career mode player to giving your player a new haircut. Sadly, it looks like the mobile version is no different. On top of the $7.99 price tag, NBA 2K18 features in-app purchases that range all the way up to $49.99. Ouch.

People don’t seem to mind, though, because the game currently sits at a 4.0 rating on the Play Store. There are only about 250 reviews so that may change, but we’ll have to wait to find out. If you want to check out NBA 2K18, hit the button below.

get it at google play

About Trees, different Traversals and BST

A tree is a data structure made up of nodes or vertices and edges without having any cycle. The tree with no nodes is called the null or empty tree. A tree that is not empty consists of a root node and potentially many levels of additional nodes that form a hierarchy.


Tree Terminology

Lets see some tree terminologies:-
Root: The top node in a tree.
Child: A node directly connected to another node when moving away from the Root.
Parent: The converse notion of a child.
Siblings: A group of nodes with the same parent.
Descendant: A node reachable by repeated proceeding from parent to child.
Ancestor: A node reachable by repeated proceeding from child to parent.
Leaf: A node with no children.
Internal node: A node with at least one child.
Degree: The number of sub trees of a node.
Edge: The connection between one node and another.
Path: A sequence of nodes and edges connecting a node with a descendant.
Level: The level of a node is defined by 1 + (the number of connections between the node and the root).
Height of node: The height of a node is the number of edges on the longest path between that node and a leaf.
Height of tree: The height of a tree is the height of its root node.
Depth: The depth of a node is the number of edges from the tree’s root node to the node.
Forest: A forest is a set of n ≥ 0 disjoint trees.

Tree Node

Tree Node has a data part and references to its left and right child nodes.

struct node {
int data;
struct node *leftChild;
struct node *rightChild;
In a tree, all nodes share common construct.

Tree Traversals

Traversal is a process to visit all the nodes of a tree and may print their values too. Because, all nodes are connected via edges (links) we always start from the root (head) node. That is, we cannot randomly access a node in a tree. Unlike linear data structures (Array, Linked List, Queues, Stacks, etc) which have only one logical way to traverse them, trees can be traversed in different ways. Following are the generally used ways for traversing trees.

  • In-order Traversal
  • Pre-order Traversal
  • Post-order Traversal

In-Order Traversal

In this traversal method we first visit the left sub-tree, then the root and later the right sub-tree. If a binary tree is traversed in-order, the output will produce sorted key values in an ascending order.
For e.g.
Output of the In-Order traversal for above tree is
4 -> 2 -> 5 -> 1 -> 3
Algorithm Inorder(tree)
1. Recursively traverse the left subtree, i.e., call Inorder(left-subtree)
2. Visit the root
3. Recursively traverse the right subtree, i.e., call Inorder(right-subtree)

Pre-Order Traversal

In this traversal method we first visit the root node, then the left sub tree and finally the right sub-tree.
For e.g.
Output of the In-Order traversal for above tree is 
1-> 2 -> 4 -> 5 -> 3
Algorithm Preorder(tree)
1. Visit the root.
2. Recursively traverse the left subtree, i.e., call Preorder(left-subtree)
3. Recursively traverse the right subtree, i.e., call Preorder(right-subtree)

Post-Order Traversal

In this traversal method we first visit the left sub tree, then the right sub-tree and finally the root node.
For e.g.
Output of the In-Order traversal for above tree is 
4-> 5 -> 2 -> 3 -> 1
Algorithm Postorder(tree)
1. Recursively traverse the left subtree, i.e., call Postorder(left-subtree)
2. Recursively traverse the right subtree, i.e., call Postorder(right-subtree)
3. Visit the root

Binary Search Tree(BST)

In binary tree, every node can have maximum two children but there is no order of nodes based on their values. Binary search tree is a type of binary tree in which all the nodes in left subtree of any node contains smaller values and all the nodes in right sub-tree of that contains larger values as shown in following figure

Operations on a Binary Search Tree

Following Oprations performed on BST
1. Search
2. Insertion
3. Deletion

Search Operation

Whenever an element is to be searched, start searching from the root node. Then if the data is less than the key value, search for the element in the left subtree. Otherwise, search for the element in the right subtree. Follow the same algorithm for each node.
node* search(int data){
struct node *current = root;
printf("Visiting elements: ");
while(current->data != data){
if(current != NULL) {
printf("%d ",current->data);
//go to left tree
if(current->data > data){
current = current->leftChild;
}//else go to right tree
else {
current = current->rightChild;
//not found
if(current == NULL){
return NULL;
return current;

Insert Operation

Whenever an element is to be inserted, first locate its proper location. Start searching from the root node, then if the data is less than the key value, search for the empty location in the left subtree and insert the data. Otherwise, search for the empty location in the right subtree and insert the data.
Node * Insert(Node * root, int data)
if(root == nullptr)
Node * NN = new Node();
root = NN;
root->data = data;
root->left = root ->right = NULL;
if(data < root->data)
root->left = Insert(root->left, data);
root->right = Insert(root->right, data);
return root;

Deletion Operation in BST

In a binary search tree, the deletion operation is performed with O(log n) time complexity. Deleting a node from Binary search tree has following three cases:-
Case 1: Deleting a Leaf node (A node with no children)
Step 1: Find the node to be deleted using search operation
Step 2: Delete the node using free function (If it is a leaf) and terminate the function.
Case 2: Deleting a node with one child
Step 1: Find the node to be deleted using search operation
Step 2: If it has only one child, then create a link between its parent and child nodes.
Step 3: Delete the node using free function and terminate the function.
Case 3: Deleting a node with two children
Step 1: Find the node to be deleted using search operation
Step 2: If it has two children, then find the largest node in its left subtree (OR) the smallest node in its right subtree.
Step 3: Swap both deleting node and node which found in above step.
Step 4: Then, check whether deleting node came to case 1 or case 2 else goto steps 2
Step 5: If it comes to case 1, then delete using case 1 logic.
Step 6: If it comes to case 2, then delete using case 2 logic.
Step 7: Repeat the same process until node is deleted from the tree.

Do you want to learn Java Programming?