
I first entered Temasek Polytechnic in 2004. In school, the design tool of choice being taught was Macromedia Fireworks, due to licensing. I went along and learn that just fine, but one day, I saw my web designer friend, Lionel, using Photoshop. That’s when I learnt how Photoshop was becoming the tool of choice in the industry. I reflect upon that and started getting annoyed that I was learning a tool in class that wouldn’t be practical and useful in the real world (back then, Macromedia licenses were used mostly in larger organisations and it’s more expensive. You could also purchase a Photoshop license standalone).
Feeling frustrated, I downloaded a copy of Photoshop (KaZaa, Limewire, anyone?) and installed it on my PC at home. Every weekday for 3 months, I would go home, Google for Photoshop tutorials, picked one I’d like, and just follow through by doing exercises for an hour or two. Nobody taught me how to use it. I just learned by playing along and creating things like chrome-looking text and a bunch of textured/grunge wallpapers. I definitely jumped to have a little more mastery of the tool thereafter. I knew the common functions, shortcuts, and tools within Photoshop. That was the start of my journey in learning how to learn on my own.
In my previous post, one of my goals in 2020 for self-learning is to pick up a little more of programming on Python, and I thought I’d try that using the same method. I no longer have the luxury of doing a tutorial for an hour or so daily, but during nights which I have more free time, I’ll be watching YouTube videos and working on examples. I know the basics of programming, and have my development environment set up fine, so getting started is the easy part. The difficult part is to integrate more thinking into the logic and solution behind some of these sorting algorithms. I’m looking for more exercises on binary trees and search, recursion and iterations, string manipulation, trees and data structures, graphs, sorting, hashmaps and set, stacks and queues. I think these fun logic exercises will be able to hone my skills more, and provide me with a better foundational skillset for Data Science and Data Visualisation.
Today, I learned about Binary trees, and specifically the problem here was to check whether the Binary Search Tree is valid. In computer science, a binary search tree, also called an ordered or sorted binary tree, is a rooted binary tree whose internal nodes each store a key greater than all the keys in the node’s left subtree and less than those in its right subtree.
Here’s the sample code I worked on:
class Node(object): def __init__(self, val, left=None, right=None): self.val = val self.left = left self.right = right class Solution(object): def _isValidBSTHelper(self, n, low, high): if not n: return True val = n.val if((val > low and val < high) and self._isValidBSTHelper(n.left, low, n.val) and self._isValidBSTHelper(n.right, n.val, high)): return True return False def isValidBST(self, n): return self._isValidBSTHelper(n, float('-inf'), float('inf')) node = Node(4) node.left = Node(1) node.right = Node(9) print(Solution().isValidBST(node)) node = Node(6) node.left = Node(2) node.right = Node(9) node.right.left = Node(8) print(Solution().isValidBST(node))
It’s fun. It’s late. Really missing my coding days. This is also inspired by a couple of “learning to learn”, and “always keep learning” videos that I’ve watched recently.