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

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.
Algorithm
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.
Algorithm
Node * Insert(Node * root, int data)
{
if(root == nullptr)
{
Node * NN = new Node();
root = NN;
root->data = data;
root->left = root ->right = NULL;
}
else
{
if(data < root->data)
{
root->left = Insert(root->left, data);
}
else
{
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?

Civilization VI

I haven’t played Civilization VI yet. I am a fan of the series. But I have too many games and too little time, and I didn’t want to pay full price for yet another iteration of the same game. I was still waiting for the price to come down below $30 when I got the news that the full Civ 6 game has been ported to iOS. Yes, you need a newer iPad to play and it is battery-hungry, but it is the *full* Civ 6, not a toned down mobile version. That is pretty remarkable. So I downloaded the game for free, which lets you play 60 turns with the Chinese empire to see how it works. And then I balked at buying the full version for $60. I didn’t even want to pay that for the PC version, and for an iOS game that is very expensive.

So while I was still pondering what to do, I got another piece of news: You can this month get Civilization VI (PC version) plus 2 expansions plus a collection of other games in the Humble Bundle Monthly for $12. That is basically a subscription service where you pay $12 per month to get a bundle of games every month. But if you only want Civ 6 you can of course unsubscribe after 1 month. As this is the lowest I have ever seen Civ 6 go for, I ended up buying the game that way.

Not sure when I will get around to actually play it, I am still very busy with Zelda – Breath of the Wild. But as an opportunity to get Civ 6 cheap this is certainly worth mentioning. The offer is available until the end of the month.

Installing Adobe After Effects

Adobe After Effects Installation
About Adobe After Effects :

Adobe After Effects is a digital visual effects, motion graphics, and compositing application developed by Adobe Systems and used in the post-production process of film making and television production. Among other things, After Effects can be used for keying, tracking, compositing and animation. It also functions as a very basic non-linear editor, audio editor and media transcoder.


After Effects CC (2015) system requirements :


Windows :


Intel Core2 Duo or AMD Phenom II processor with 64-bit support
Microsoft Windows 7 with Service Pack 1, Windows 8, or Windows 8.1
8 GB of RAM (16 GB recommended)
5 GB of available hard-disk space; additional free space required during installation (cannot install on removable flash storage devices)
Additional disk space for disk cache (10 GB recommended)
1280 x 1080 display
OpenGL 2.0-capable system
QuickTime 7.6.6 software required for QuickTime features
Optional: Adobe-certified GPU card for GPU-accelerated ray-traced 3D renderer
Internet connection and registration are necessary for required software activation, validation of subscriptions, and access to online services.

Mac OS :

Multicore Intel processor with 64-bit support
macOS v10.9 (Mavericks), or v10.10 (Yosemite)
8 GB of RAM (16 GB recommended)
5 GB of available hard-disk space for installation; additional free space required during installation (cannot install on a volume that uses a case-sensitive file system or on removable flash storage devices)
Additional disk space for disk cache (10 GB recommended)
1440 x 900 display
OpenGL 2.0-capable system
QuickTime 7.6.6 software required for QuickTime features
Optional: Adobe-certified GPU card for GPU-accelerated ray-traced 3D renderer
Internet connection and registration are necessary for required software activation, validation of subscriptions, and access to online services.

Installing a render-only instance of Adobe After Effects CC
Before you start:
1. If you have installed Creative Cloud applications on two computers, sign out of one of them by opening any of the applications and choosing Sign Out from the Help menu.

2. You can sign back into Creative Cloud on this computer after the render-only instances of After Effects are installed.

To install a render-only instance of After Effects CC, do the following:
1. Go to the product page to download and install After Effects CC.
2. Download Adobe After Effects CC Trial from :
    https://www.adobe.com/products/aftereffects/free-trial-download.html
3. Install as Try.
4. When the installation is complete, start After Effects.
5. Quit After Effects install Application.
6. To start the application browse to Start Menu > All Programs > Adobe After Effects CC 2015.exe
Limitations of the trial version
The trial version of After Effects includes all of the codecs that are included with the full version of After Effects. This means that you can import and export to all of the supported file formats using the trial version. 
The trial version of After Effects also includes the Keylight plug-in, mocha-AE, mocha shape, Cycore (CC) effects, and Color Finesse. 
Activate the software

A single-user retail license activation supports two computers. For example, you can install the software on a desktop computer at work and on a laptop computer at home.

For more information on product licensing and activation, go to the Adobe website.

Want to Learn Brand Marketing of your Company ?

Former CIA Official Suggests Trump Campaign Team May Have ‘Welcomed’ Russian Election Interference

No one bothered to report an obviously relevant Trump Tower meeting.

Former CIA and U.S. Defense Department official Jeremy Bash told MSNBC host Nicolle Wallace that President Donald Trump’s actions after being cautioned by the FBI about Russia raise serious red flags.

Bash specifically noted that the Trump team’s disinterest in informing the FBI about a Trump Tower meeting with Russians following the bureau’s alert is suspicious.

“I think the fact that the campaign, the candidate was warned and that the candidate and the campaign did not then go back to the FBI after the Trump Tower meeting is a huge red flag that, not only were they unconcerned with this Russian overture,  but they welcomed it and in some ways want to conceal it,” he said. 

“To have warned the FBI would have been to expose their own conduct, the campaign’s own conduct, and that is something that Bob Mueller will be very, very interested in.”

Watch the segment below.

 

Related Stories

  • If Trump Fires Mueller, Is a Watergate Rerun Coming?
  • Robert Mueller Has the Trump Team Panicked, No Matter What the President Says
  • Intelligence Analyst Malcolm Nance Compares Fox News Rhetoric to ‘Psychological Warfare’

First impressions Zortrax M200 Plus 3D Printer

I am going to post a full review with comparison of things I printed later, but I already wanted to write about my first impressions with my new 3D printer. Unboxing the printer, installing, calibration, and starting to print took me about 1 hour, which is about a “plug & play” as it gets in 3D printing. Most of the printer is pre-assembled, but you need to assemble the cable to the print head and the cable to the heated bed yourself, as well as the spool holder and the guide tube from the spool to the print head. Then you need to install the latest firmware via an USB key, and calibrate the bed to be even. That is done with the help of 3 screws, with the printer telling you which one to turn by how much. Apart from a ridiculous degree of precision in the instructions (“turn the screw by 86.02°”), that went smoothly.

The printer comes with one model for a test print on the provided USB key. In a disappointing display of lack of professionalism Zortrax managed to forget to include supports in that test print model, which results in it being actually impossible to print. Of course I didn’t know that and went back to the shop to ask why after installation the test print wasn’t working, and it was just by chance that there was a technician present who was aware of that issue and told me not to worry and print something else instead.

Both the firmware and the Z-Suite 3D printing software can only be downloaded after entering the serial number of the printer, but then the software worked on the first try. So I printed a 3D Benchy as test print, and it came out very nice. Much better detail on the fine parts, and smoother walls. However after printing some other models I have to say that not everything is perfect, and some prints that I succeeded with on the old printer failed to print on the new one; right now it is hard to say how much of that is due to the change in material from PLA to ABS, how much is related to finding the best settings, and how much is due to the printer.

What I really disliked about my old XYZ printer was that he would only take spools of PLA from the company that made the printer, with an RFID chip in the spool making sure you didn’t use other material. That system also resulted in the spool physically still having several meters of material on it at the end, while the RFID chip claimed the spool was empty and refused to use it any more. The new Zortrax printer is better in that respect, you can print with spools from any supplier. However the software has the optimum parameters for the Zortrax spools, while for external materials you need to find the best settings yourself. That curiously means that if you want to print the Zortrax ABS at a different temperature for some reason, you need to unload it, and reload it as external material, claiming it was ABS from a different supplier.

I notice a real change printing in ABS rather than in PLA. I will need to explore that further, and for example try to print PLA on the new printer. The previous model Zortrax M200 was famous for not doing PLA well, but the M200 Plus has an additional cooling fan on the print head and is supposed to have solved that problem. From a scientific point of view, PLA is more crystalline, which makes it more shiny, but also more brittle. ABS is more matte, more flexible, and sturdier. Lego bricks are made from ABS, and those usually don’t break easily. However when printed with a 3D printer, the layers create a preferred axis of breakage, so if I would print a Lego brick it would be less sturdy than the original. And it would be less glossy and smooth on the surface. However ABS, unlike PLA, is soluble in acetone, so there are methods of making ABS printed parts smooth and glossy by exposing them to acetone vapors. I haven’t tried that yet. The disadvantage I noticed with ABS is that you need to print it at higher temperature to make it stick to the previous layer, and then there is a bit of possible “sagging”, making the printed part a bit broader than the model. I had some prints of figurines with supports where the side of the support stuck to the side of the model, and then left a mark when I removed it. That can probably be fixed by the settings of the software making the supports.

Talking of supports, I still have the same problem with the supports generated by the Z-Suite software than I had with the supports generated by the XYZWare software: The supports are far too massive for small 28mm scale figurines. You can’t use them to print a support for something which is only a millimeter or two thick, like a weapon or arm of a miniature. They seem to be designed for large objects. Having said that, the Z-Suite software has at least some degree of manual editing of support structures, so that is good. Just for my main application I’ll keep using Meshmixer for building support structures for small figurines.

Finally there is one point where the new Zortrax printer is far worse than the old XYZ printer: The XYZ printer automatically shut down the light after a few minutes, and shut down the fans when the print head was cold. Thus I could start a print in the morning and go to work, or in the evening and go to bed, and when I came back the XYZ printer was on standby. The Zortrax printer doesn’t have that, when you come back hours later the light is still on (presumably to allow the internal camera to work) and the fans are still blowing, although the machine is cold. That adds unnecessary wear and tear to the fans, and also consumes more electricity when not in use. I think I will have to buy an electronic time switch or something.

Overall I am happy with the new printer, and I’ll show some photos of the improved results in a future post. But there remains a lot of fiddling and optimizing to be done, and the new printer didn’t miraculously and immediately solve all my printing problems. But then that would have been boring anyway! 🙂 

New Wall Street Journal Report Might Totally Destroy Republicans’ Favorite Anti-FBI Talking Point

The GOP still won’t shut up about a “Deep State” conspiracy though.

A new report from the Wall Street Journal adds some needed context to FBI Agent Peter Strzok’s text message about the Russia investigation being an “insurance policy” in the event that Donald Trump won last year’s presidential election.

According to the Journal’s sources, Strzok’s talk of an “insurance policy” against Trump’s electoral victory “was meant to convey that the bureau needed to aggressively investigate allegations of collusion between Donald Trump’s campaign and Russia,” and was not intended to “suggest a secret plan to harm the candidate but rather address a colleague who believed the [FBI] could take its time because Democratic presidential nominee Hillary Clinton was certain to win the election.”

In the original text message, which was sent to FBI lawyer Lisa Page, Strzok wrote of Trump that, “I want to believe the path you threw out for consideration in Andy’s office — that there’s no way he gets elected — but I’m afraid we can’t take that risk. It’s like an insurance policy in the unlikely event you die before you’re 40.”

The text message had been seized upon by Republicans who suggested it revealed an agency-wide conspiracy to bring down Trump in the event of his election. According to the Journal’s account, however, it seems that Strzok was sincerely concerned about contacts between the Trump campaign and Russian agents, and wanted to pursue an investigation regardless of who won the 2016 presidential election.

Strzok was originally part of special counsel Robert Mueller’s investigative team, but he was removed by Mueller this past summer after the special counsel discovered that the FBI agent had disparaged Trump as an “idiot” in text messages.

 

Related Stories

  • If Trump Fires Mueller, Is a Watergate Rerun Coming?
  • Robert Mueller Has the Trump Team Panicked, No Matter What the President Says
  • The One Scenario in Which Trump Would Risk Impeachment and Fire Robert Mueller

Test Your PL/SQL Fundamentals

In Oracle database management, PL/SQL is a procedural language extension to Structured Query Language (SQL). The purpose of PL/SQL is to combine database language and procedural programming language. The basic unit in PL/SQL is called a block, which is made up of three parts: a declarative part, an executable part, and an exception-building part.
Test your PL/SQL knowledge by solving following 49 MCQ’S

Loading…