DPS909 0.2 Release – Pull Request 4

My fourth pull request was on another topic that I have not worked for some time. This time I was working with Javascript. Javascript is a high-level, interpreted programming language. It is a language which is also characterized as dynamic, weakly typed, prototype-based and multi-paradigm. I chose to work with Javascript because I had not made a pull request in Javascript for this assignment and Javascript is the language that has the most issues in the list for possible issues to work on. When I first started in my program I did a lot of work in Javascript in my earlier semesters but as the semesters went on, I was working with Javascript less compared to the earlier semesters.

But over the winter and summer semester, I did a lot of work in Visual Basic during my work term working at Environment and Climate Change Canada. At the government, a lot of old programming langauges are still being used like Visual Basic and PHP, which I worked with. While learning Visual Basic and before starting on the assigned work, I was able to quickly grasp the content because Visual Basic was similar to Javascript, so remembering the content for this issue was a bit easier for me.

The following is the issue that was posted that I decided to work on and hopefully make a pull request.

Find the height of binary tree – javascript #22

What was being asked from the issue was to add a new file where the user would be able to find the height of a binary tree. First I had to review binary trees and how they were programmed. I took a course during the Fall 2016 semester that was about Data Structures but in that course the language that we used was C++. For this issue, we are asked to program in Javascript. In my opinion, coding in Javascript is a lot simpler than coding in C++ but coding the binary tree would be different because I was used to doing it in C++.

After some research and refreshing my mind in the subject, the first step was to create a binary tree. I had to create functions to create the root of the tree, and functions to set the left and right nodes of the created root. Each function would be used every time a new node was inserted. In order to insert a new node I created a function called insertNode() which takes the root and the new node. Then to test if the tree was created properly I had to insert values into the tree. I created a function called insertValue() which inserts five values into the binary tree and then three function calls are made within the insertValue() function. The first two function calls are to display the values of the binary tree. The first function call displays the values in a preoder traversal. A preorder traversal displays the node values starting with the root. Then it works its way to the left-most node displaying the values on its way. Then it goes back to the root and goes to the right-most node displaying the values on its way. The second function call displays the values in an inorder traversal. A inorder traversal displays the node values starting with the left-most node. Then it works its way to the root displaying all the other nodes, then displays the nodes going to the right of the tree.

The last function call, height(), gets the height of the binary tree after the values have been inserted into the tree. The height of a binary tree would be the largest number of edges in a path from the root node to the leaf node. So after creating the binary tree and populating the tree with values, the height function is called which would add one every time a node was there and it would go through the function recursively.

The following image shows exactly the two traversals and the height of the binary tree.


After completing the code and testing it multiple times with different values, I made sure to make a pull request and reference the issue. The following is the link to the pull request that I made.

Fix 22 – Height of binary tree #49



Code Academy

Binary Tree

Published by

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s