Last active
December 22, 2015 12:28
-
-
Save alcedo/6472550 to your computer and use it in GitHub Desktop.
Recursive Backtracking:
This file contains 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
Recursive Backtracking: | |
usually involves a for loop + a recursion. (the for loop acts as a backtracking mechanism) | |
The requirements for a recursive solution are met in these ways. | |
.The problem is made smaller by taking one step in the space - by making one move. | |
.The base case occurs when the property has been fully satisfied and we arrive at the exit. | |
.The partial results are combined by putting the steps together in a way that is appropriate (perhaps printing them, or returning them as a list to some other program). | |
*important things to note: The base case is *usually* the solution to the problem. | |
*Each recursive call would spawn another For-loop. <-- this part here is critical in understanding how recursive backtracking works. | |
*usually involves some-form of undo operation before going to the next iteration in a loop | |
Domain specific language: language specific to the problem domain that you wish to solve. | |
eg: its better to code intuitively in Notes, Bars, Octave in music, as compared to coding in Hz, Frequency, Sine Waves. So you use a language that is great for DSL creation (functional programming languages usually comes to mind here) | |
Think of it as a wrapper language. | |
========= | |
NOSQL's selling point is that adding a new server is easy. | |
SQL scaling requires planning: | |
can you move tables to a new DB | |
Can you divide your table across multiple DBs. | |
Will you divide your data by time, random id, etc? | |
This will make you hate SQL | |
Downtime or: | |
create table new_Schema | |
Script to move from old_schema to new schema | |
Modify code to use new_schema, with a backup to old_schema | |
re-run script | |
DROP table old_schema | |
Analogy: JS vs Java | |
Key/value is very fast to implement | |
RDMS is slow to implement | |
======== | |
sghack and tell | |
project nimbus : SG data set | |
=== | |
tools: http://kapeli.com/dash | |
png express | |
dev rocket | |
Qxxxxxxxx | |
xxxxxxxxx | |
xQxxxxxxx | |
xxxxxxxxx | |
xxxxxxxxx | |
xxxxxxxxx | |
//place 8 queens in 8x8 board , or NxN board, where N > 3 | |
//row x col | |
int[][] board = new int[8][8] | |
var success = true; | |
var fail = false; | |
//IDEA: go thru each column, and try row by row to place queen. | |
function placeQueen(col) { | |
var status = success; | |
//loop thru rows | |
for(var row=0; row<board.length; row++){ | |
if(!threat(row, col)) { //check diagonals / rows / columns, make sure queens are not being attacked | |
markBoard(row, col); //mark board to place queen, change x => Q | |
// go to next column and try to place queen. | |
if(col+1 < board.size) | |
status = placeQueen(col + 1); //recursive call. | |
if(status == success) { | |
return success; | |
}else { | |
unMarkBoard(row, col) // remove queen, and try again for next row. | |
} | |
} | |
} | |
// cant place queen for ALL rows in this column, so return fail | |
return fail; | |
} | |
// Start placing queen from column 0 | |
placeQueen(0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment