Wednesday, 27 November 2013

Test 2 Retrospective

Test 2 was quite fun, as it was essentially an exercise on recursion on abstract data types. Although I don't feel like I've mastered recursion, I felt like my logic was sound when writing my answers. I did alright, but I feel like I still need practice "programming" on paper. Mostly because I just wish I could "run" my code to see if it would work. Guess I gotta stop using my IDE as a crutch, and just work on visualizing the logic in my code.

Sunday, 3 November 2013

Exercise 6

Exercise 6 was really easy for me, though I'm not sure I solved it the "intended" way.

For Part A, I used a while loop to append the item of each node to a temporary list, and then iterated over the list to see if there were any matches.

Part B was also quite straightforward, I tried to do the same thing except I ran into a problem. Initially, I thought that we were to return the ITEM of the maximum value of all nodes, i.e. in a BST([1,2,44,3]), I had mistakenly assumed the output to be 44. However,we were actually supposed to return a reference to the object that held the value of the item. This was an unfamiliar problem to me. How was I supposed to find the reference to the object after finding the max value?

I ended up brute forcing the problem, and just appended all the objects of the tree into a list and sorted it by the item; then I returned index 0 of that list.