运行截图
1
运行并选择我们已经写好的网格的存储方法,然后输入我们想要的即可
2
These methods could be used without change:
public ArrayList<Location> getOccupiedLocations()
public E get(Location loc)
public E put(Location loc, E obj)
public E remove(Location loc)
Fill in the following chart to compare the expected Big-Oh efficiencies for each implementation of the SparseBoundedGrid.
Let r = number of rows, c = number of columns, and n = number of occupied locations
Methods | SparseGridNode version | LinkedList<OccupantInCol> version | HashMap version | TreeMap version |
---|---|---|---|---|
getNeighbors | O(c) | O(c) | O(1) | O(logn) |
getEmptyAdjacentLocations | O(c) | O(c) | O(1) | O(logn) |
getOccupiedAdjacentLocations | O(c) | O(c) | O(1) | O(logn) |
getOccupiedLocations | O(c+n) | O(r+n) | O(n) | O(n) |
get | O(c) | O(c) | O(1) | O(logn) |
put | O(c) | O(c) | O(1) | O(logn) |
remove | O(c) | O(c) | O(1) | O(logn) |
操作同1
3
- the Big-Oh efficiency of the
get
method is :O(1)
- the efficiency of the put method when the row and column index values are within the current array bounds is
O(1)
- the efficiency when the array needs to be resized :
O(n^2)
, n is the size of the array
运行并选择UnboundedGrid2即可