Skip to content

Commit

Permalink
Merge branch 'main' of github.com:IUDataStructuresCourse/course-web-p…
Browse files Browse the repository at this point in the history
…age-fall-2023
  • Loading branch information
cty12 committed Sep 21, 2023
2 parents f4cc593 + 859893d commit 2f55415
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lectures/Sep-20.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ property.)
1 3 7 12
\
4

Solution:
* Step 1: replace node 8 with node 9

Expand Down Expand Up @@ -238,7 +239,8 @@ O(h) = O(log n)
Tile[][] tiles,
Integer board_size) {
for (int i = 0; i < flooded_list.size(); i++) {
checkNeighbor(flooded_list.get(i), board_size, flooded_list, color, tiles);
checkNeighbor(flooded_list.get(i), // get is O(n), solution: use an arraylist
board_size, flooded_list, color, tiles);
}
}

Expand All @@ -250,7 +252,7 @@ O(h) = O(log n)
List<Coord> neighborsList = currentTile.neighbors(board_size);
for (int i = 0; i < neighborsList.size(); i++) {
Coord neighbor = neighborsList.get(i);
if(!flooded_list.contains(neighbor)) {
if(!flooded_list.contains(neighbor)) { // contains is O(n)! solution: use a hashset
int x = neighbor.getX();
int y = neighbor.getY();
if(tiles[y][x].getColor() == color){
Expand All @@ -277,9 +279,10 @@ O(h) = O(log n)
Coord c = queue.remove(0);
for (Coord n : c.neighbors(board_size)) {
if (!visited[n.getY()][n.getX()] && tiles[n.getY()][n.getX()].getColor() == color) {
queue.add(n);
if (is_flooded.add(n))
if (is_flooded.add(n)) {
queue.add(n);
flooded_list.add(n);
}
}
visited[n.getY()][n.getX()] = true;
}
Expand Down

0 comments on commit 2f55415

Please sign in to comment.