Sunday, May 29, 2016

Leetcode 126: Word Ladder II - warm up practice (II)

May 29, 2016

 Share one tweet from profession tennis play Angelique Kerber (2016 Australian Grand Slam champion):
https://twitter.com/AngeliqueKerber/status/734019444868059136

"Everyone asks me what's next. I'm here to stay, taking it one game at a time."


 One algorithm at a time. Still work on Leetcode 126: word ladder II,

 Here is the practice version on May 28, 2016, less than 15 hours ago.
http://juliachencoding.blogspot.ca/2016/05/leetcode-126-word-ladder-ii-warm-up.html

 And then, she spent over 2 hour to make changes on the code, here is the new version:

https://gist.github.com/jianminchen/90075ee13a6ad0d9d59c8843d17e3a18

 Here are the list of things she made the change:
1. line 21, class member variable is commented out. ladders.
    It is replaced by an argument in the function:
line 189 getLadders_DFS_Backtracking, 8th argument - ladderHelper

2. line 27, comment out member variable ladderHelper, pass an argument in
function getLadders_DFS_Backtracking line 189, last argument: List<string> ladderHelper

3. line 60, change function name to getLadders_DFS_Backtracking, remind myself two things:
1. it is a DFS algorithm
2. Do not forget to do backtracking

4. line 102, change function name to getLadderLengthAndDictionary_BFS. BFS stands for 
breadth first search.

5. line 203, line 204, add two more explanation variable, make code more readable.
isEndWord, 
isBeforeEndWord

6. line 220, add explanation variable, backtracking_char, helps user to understand 
the backtracking process.

7. line 221, add explanation variable replace, the char will be replaced by any one of from 'a' to 'z'.

8. line 225, 226
if(j == replace)
  continue;

Make the code more flat, no nested two if statements, only one if statement.

9. line 229, ij_word, ij prefix helps to track index i and index j.
10. line 245, line 249, line 251 3 backtracking statements.





No comments:

Post a Comment