#throwback

Pdawg Entertainment
#throwback
I enjoyed reading Rebooting AI — building Artificial Intelligence We Can Trust (published in 2019). Gary and team survey progress in AI and some of the shortcomings with the latest approaches such as Deep Learning. For AI to make next leap, Gary and team argue that AI needs to have some basic common-sense built into it, which current approaches largely overlook. This book is an easy-read and will provide value to readers interested in artificial intelligence, shortcomings (which is somewhat contrarian given the hype that media continues to give to AI) and its impact to society.
Popular insertion sort algorithm written in Ruby.
sampleList = [12, 11, 13, 5, 6]
sortedSampleList = []
sampleList.each_with_index do |inputtedItem, inputtedItemIndex|
if sortedSampleList.length == 0
sortedSampleList.insert(0, inputtedItem)
next
end
sortedSampleList.each_with_index do |outputtedItem, outputtedItemIndex|
if inputtedItem < outputtedItem
sortedSampleList.insert(outputtedItemIndex, inputtedItem)
break
elsif outputtedItemIndex == sortedSampleList.length - 1
sortedSampleList.insert(sortedSampleList.length, inputtedItem)
break
end
end
end
p sampleList
p sortedSampleList
The output is the following.
% ruby insertionSort.rb
[12, 11, 13, 5, 6]
[5, 6, 11, 12, 13]
This is a great read. Reading regularly is one of the key ways to make sure that one continues to grow in whatever endeavor being pursued. In a matter of sitting down for a few hours, there is usually a wealth of insights that can be obtained by reading. I definitely recommend this one to engineering managers and those that may be curious about the role.
I am officially a Southern California resident.
I started this blog with a post having the picture of me moving out of the first apartment I moved to in Seattle. My time in that apartment formed the foundation of what was to come next in my life. From that micro-apartment, I moved into what would be my first purchased property in the US & used that as motivation & fuel in pushing myself further.
Now the time has come again for me to pack bags, and set my compass to a new location — only this time my bags will be little heavier from when I first moved to the states with barely a luggage full.
I am moving to Southern California. Stay tuned as I share more updates.
Even though this book was published in 2018, recommend buying & reading this book. I both listened to the audio book of ‘Prediction Machines’ from Audible and also read the physical copy purchased from Amazon. I still refer to my notes from the book from time to time. Overall it is a great book to ground your thinking in machine learning and how it may impact your strategy and/or company. Sharing the notes below that I’ve kept in my Evernote. Let me know your thoughts or any other books you recommend on this topic.
Chapters
Introduction: Machine Intelligence
Cheap Changes Everything
Prediction Machine Magic
Why It’s Called Intelligence
Data is the New Oil
The New Division of Labor
Unpacking Decisions
The Value of Judgement
Predicting Judgement
Taming Complexity
Fully Automated Decision Making
Deconstructing Work Flows
Decomposing Decisions
Job Redesign
AI in the C-Suite
When AI Transforms Your Business
Your Learning Strategy
Managing AI Risk
Beyond Business
Pure inspiration.
Saw this problem in LeetCode.
Problem statement:
Given the root
of a Binary Search Tree and a target number k
, return true
if there exist two elements in the BST such that their sum is equal to the given target.
Python based solution:
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def find(self, root: TreeNode, k: int, alreadyUsed: TreeNode) -> bool:
if root.val == k and root is not alreadyUsed:
return True
if k < root.val and root.left is not None:
return self.find(root.left, k, alreadyUsed)
if k >= root.val and root.right is not None:
return self.find(root.right, k, alreadyUsed)
return False
def findInPart(self, part: TreeNode, root : TreeNode, k: int) -> bool:
toFind = k - part.val;
if self.find(root, toFind, part):
return True
if part.left is not None and self.findInPart(part.left, root, k):
return True
if part.right is not None and self.findInPart(part.right, root, k):
return True
return False
def findTarget(self, root: TreeNode, k: int) -> bool:
toFind = k - root.val;
if self.find(root, toFind, root):
return True
if root.left is not None and self.findInPart(root.left, root, k):
return True
if root.right is not None and self.findInPart(root.right, root, k):
return True
return False
This is a very simple solution.
The solution given here has time complexity of O(n Log n) for average case assuming the binary search tree is somewhat balanced. Space complexity is O(1) as I don’t allocate any new data structure.
By keeping track of the the elements you have already seen in a Set as you are doing the traversal you can improve the time complexity here to O(n) with space complexity of O(n).