Description: Solution: In the recursion, we set the root and mid, and then divide two portion: right & left. root is always the first value of preorder[] mid is always the index of root of inorder[] left portion: preorder[1: mid+1] and inorder[:mid]. right portion: preorder[mid+1:] and inorder[mid+1:].
Description: Solution: Brute force method is not adapted as a solution. We are gonna make the pointer end of both array. Shift l if height[l] is smaller than height[r]. Else: shift r to right.
Gradient Derivatives We can also interpret the slope as: If I nudge x, how does y change? Pretend that multivariable funciton is univariate, then take derivative as normal. This is a partial derivative. The gradient extends the derivative to multiple variables. Vector-valued function (always outputs a vector). The gradient of f(θ) w.r.t. θ is a vector. Each element is the partial derivative for ..
Modeling Making Predition To make a prediction, we choose a model, Constant Model: Prediction: fθ(x) = θ (Recipe to compute the prediction) Simple Linear Model: fθ(x) = θ1x + θ0 ( Two model weights) The Constant Model Start simple: if constant model, how do we pick θ? Intuition: pick θ to be close to most of the values in data Model Loss Use x to denote what we use to make predictions Use y to d..
Description: Solution: We need to nums.sort() before moving pointer. i is a count, a is the value (enumerate) if i > 0 and a == nums[i-1] => if i is bigger than 0, we make sure not using same value l, r pointers to find the two sum for 0 of three sum. Since we sort the values, if threeSum is bigger than 0, we should move r pointer to left. elif threeSum is smaller than 0, we should move l pointe..
Schemas Schema describes all relations and their attribute names & types. Granularity (what does one record in each table represent?) Primary and Foreign keys Representation CREATE TABLE users( id INTEGER PRIMARY KEY, name TEXT ) CREATE TABLE orders( item TEXT PRIMARY KEY, price NUMERIC, name TEXT ) GROUP BY and HAVING # SQL SELECT max(name), legs, weight FROM animals GROUP BY legs, weight HAVIN..
Goals of EDA Data Types: What kinds of data do we have? Granularity: How fine/coarse is each datum? Scope: How (in)complete are the data? Temporality: How are the data situated in time? Faithfulness: How accurately do the data describe the world? Data Type: Nominal Data: categories without natural ordering Ordinal Data: categories with natural ordering Numerical Data: amounts or quantities Compu..
Description: Solution: We are gonna set l, r, m pointers to find in O(logn). If l pointer value is less than m pointer value: target should be between l and m or between m and r. if target is more than m value or target is less than l value, we are gonna see right portion, except left portion. else we are gonna see left portion, except right portion. If r value is less than m value: target can b..
Description: Solution: I set the right and left pointers to the end of the array. m is the pivot(first set the middle of the array). If m is more than l, then we can throw out the left portion. Now, the new l is the next value of m. Else, we can throw out the right portion, so the new r is the previous value of m. When we get the nums[l] is less than nums[r], we return the res.