高级农民
- 积分
- 4640
- 大米
- 颗
- 鳄梨
- 个
- 水井
- 尺
- 蓝莓
- 颗
- 萝卜
- 根
- 小米
- 粒
- 学分
- 个
- 注册时间
- 2014-12-19
- 最后登录
- 1970-1-1
|
本帖最后由 俘虏你的心 于 2017-3-12 06:41 编辑
昨晚Hw9,再差一次Hw10就完咯~~~~
贴上Part II- 1. Mark all hWalls and vHalls as true (unbroken).
- 2. Randomly choose a starting cell.
- DFS:
- 3. Mark this cell as visited.
- 4. Randomly choose a direction, above, below, left, or right. Mark the wall
- as false (broken) and recursively perfrom DFS (step 3 and 4) on the cell
- across the wall.
- (a) How would your algorithm ensure that there is a path between every pair of
- cells, but no more than one path between any pair of cells (i.e., no
- cycles)?
- Every wall represents an edge and initially it is false, meaning that every
- cell is connected, i.e., the graph is connected. Therefore, DFS is able to
- traverse the whole graph. By marking this cell as visited, there will not be
- a loop.
- (b) How does your algorithm use random numbers to generate a different maze
- each time? Specifically, what decision should be made by random numbers
- at each recursive invocation of the depth-first search method?
- - Randomly choose a cell as the starting cell.
- - Randomly generate a number (direction) in step 4.
复制代码 |
-
1.png
(18.03 KB, 下载次数: 0)
|