This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <stdbool.h> | |
typedef struct list List; | |
typedef struct node Node; | |
struct node { | |
int data; | |
Node* next; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
int findCircleNum(vector<vector<int>>& M) { | |
int n = M.size(); | |
int partitions = 0; | |
if(!n) return partitions; | |
for(int i = 0; i < n; i++){ | |
if(M[i][i]==1){ | |
M[i][i] = 0; //instead of using extra mem. to store visited, I alter the matrix. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.Point; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.Collections; | |
import java.util.Comparator; | |
import java.util.HashMap; | |
import java.util.HashSet; | |
import java.util.Map; | |
import java.util.Set; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Gets the value of a tile. | |
/** | |
* Given an X and Y coordinate, returns the value of the tile at that position. | |
* This function also marks that location as visited. Part of your grade on this | |
* assignment will be determined by how many tiles your solution visits. | |
* | |
* @param x The X coordinate. | |
* @param y The Y coordinate. | |
* @return The value of the tile at that location. | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ostream& operator<<(ostream& os, const vector<int>& v){ | |
os << "[ "; | |
for(int i = 0; i<=v.size()-1; i++){ | |
os << "'" << v.at(i) << "'"; | |
if(i != v.size()-1) os << ','; | |
} | |
os << " ]"; | |
return os; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fn = intcompare(x, f, a, b) | |
hp = build_hermite(x, hermitecalc(x, f)); | |
sp = build_spline( x,splinecalc(x,f) ); | |
i_f = integral(f,a,b); | |
sp_i = spline_integral(x, a, b, sp); | |
hp_i = integral( matlabFunction(hp),a,b ); | |
first_row = [i_f,sp_i,hp_i]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# **DP SOLUTION** | |
def longest_inc_subseq_dp a | |
n = a.length | |
r = [1] | |
s = Array.new(n) {[]} | |
s[0] << a[0] | |
for i in 1..(n-1) | |
res = get_max(a, r, i) | |
r[i] = res[0] + 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# **PROBLEM STATEMENT** | |
# Assembly line scheduling w/ 2 lines. | |
# **OPTIMAL SUBSTRUCTURE** | |
# Claim: A candidate solution is a finite sequence of entries of A | |
# and the last element in S is either A[0][n-1] or A[1][n-1]. | |
# If S is the opt. solution for A, then S' = S[:-1] is optimal to | |
# the subproblem with force S[-1]. | |
# **RECURRENCE RELATION** |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# **PROBLEM STATEMENT** | |
#Given an mxn matrix A of non-negative integers, | |
# find the finite sequence S of adjacent entries of | |
# A (starting from top left and moving right, or bottom) | |
# s.t Σ(S) is minimum. | |
# **OPTIMAL SUBSTRUCTURE** | |
# Claim: If S is the opt. solution for A, then S' = S[:-1] is optimal to | |
# the subproblem with force S[-1]. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# **PROBLEM STATEMENT** | |
#Given a finite sequence of integers A, | |
# find the finite contiguous subsequence S s.t. the Σ(S) := "sum of the elements of S", is maximum. | |
# **OPTIMAL SUBSTRUCTURE** | |
# Claim: Consider the problem of obtaining the contig. subsequence w/ max sum | |
# up to and including the ith element of A. Suppose S = S(k) is the optimal solution | |
# of the sequence A, where k is the index in A of the last element in the solution. | |
# That is, among all candidate solutions, Σ(S) is maximum and A[k] is the last element in S. | |
# Let F = S[-1] be a focring factor. Then, S' = S[:-1] is the contig. subsequence |
NewerOlder