SE250:lab-7:klod004

From Marks Wiki
Jump to navigation Jump to search

Lab 7

  • Work in progress

This lab was to help us understand Binary Search Trees and how the traversals and balancing of trees work. The source code was provided for this, all we had to do was to simply run the program. The Visual Studio could not run it, and some people told me that the reason for this is that it does not support some syntax or something. But otherwise, the GCC compiler worked perfectly. I personally don't prefer this as it means to work from the command line, but I guess it ain't that much of a buzz kill. But anyways, so the program was saved to a location and then the command prompt was opened from that location. The command to compile this was:

gcc lab7.c

I don't really know the shortcut to compile and run at the same time, so I ran it with:

a.exe

a.exe, because I did not specify an output name, so that was the .exe that the compiler spat out for me to run. Now I have the program running, which it starts off without notice. After a bit of entering bogus values, the line came that tells me to enter ""help"" to find more instructions. And this is how I found my way around the program most of the time.

First task dealt with getting used to the program and exploring our way around it. Basically making a tree, and navigating through each node which proved rather easy.

The next task dealt with making a perfectly balanced tree, and then inserting the same elements in different order to try to see if they still line up as balanced. The following numbers were used:

1,2,3,4,5,6,7 in the order 4,6,7,5,2,3,1

But other orders also made balanced trees.

4,2,3,1,6,5,7 etc

Just as long as the median of the binary tree came first.

Task 3 was to skew the tree, I didn't know what this meant until I did it. It makes the tree lopsided to whichever side you specify. And when the root is rotated left, it basically shifts the root to the left, and makes the element on the right of the root, the new root.

Since I cannot run the lab on my laptop, I cannot provide any output nor give the exact results, but I can say that manuvering through the tree was not that difficult after like 2 minutes of using the program.

Starting with a right skewed tree, all that was needed to do to obtain a left skewed tree was to call rotate left on the root.

Starting with a right skewed tree, it was rather easy to get to a balanced tree, as far as I can remember, I used rotate on the root till I reached 4 as the root, then i went to the right side, and used rotate left on the second parent, and went back to the left tree and used the same command.