## Time Complexity help for Hashmaps using AVL Trees and separate chaining

Cheers, I am implementing a hashmap using separate chaining and AVL Trees as buckets but I am having some trouble proving some time complexities. I have to find the worst and average time complexities and also amortized vs real time complexities. So basically I have 4 different complexities combinations (average time amortized, average time real, worst case amortized, worst case real time). My main problem is that I don’t know in which combination I should count the rehashing that I do.
I am now gonna explain some more things about my approach:

When inserting an item I first hash its key and insert in the tree at the hashed position. That insertion should probably take O(log(k)) complexity where k <= n, because k is the number of values inside that bucket, but that makes that O(logn). Now my problem is with the rehash. I set the max load factor for the hash map to 0.9, which is the optimal for the separate chaining approach.

In the rehash:

First I allocate a new hash map with double capacity, I then create the trees for each position of that new capacity hash map, so I make one iteration for the hashmap capacity. I then traverse the old hashmap, I visit every tree and every node inside it and I re-add it into the hashmap using insertion ( so I call hashmap_insert again) , so it hashes to the correct position. However, when traversing the trees, I first get the first node of that tree, and for every node in that tree I call a function called tree_next, which given a node returns the next node in that tree, taking O(logn) time, where n is the number of elements in that tree. However, because we keep the trees relatively “short”, then we can suppose that it’s O(1). When is that though ? When we study the amortized time, or the average ? Or when studying their combination (average time-amortized)?

I would love some help! Thanks!

## javascript – Sudoku Solver with hashmaps

is there a way to change the board using hashmaps?
There’s this project I have where I have to implement both recursion to solve the board which is already done and solve the board but I need hashmaps to make the board and I’m not sure how to do so.
If anyone can make it and show me it that would be great.

``````    public static int()() GRID_TO_SOLVE = {
{9,0,0,1,0,0,0,0,5},
{0,0,5,0,9,0,2,0,1},
{8,0,0,0,4,0,0,0,0},
{0,0,0,0,8,0,0,0,0},
{0,0,0,7,0,0,0,0,0},
{0,0,0,0,2,6,0,0,9},
{2,0,0,3,0,0,0,0,6},
{0,0,0,2,0,0,9,0,0},
{0,0,1,9,0,4,5,7,0},
};

private int()() board;
public static final int EMPTY = 0;
public static final int SIZE = 9;

public Sudoku(int()() board) {
this.board = new int(SIZE)(SIZE);

for (int i = 0; i < SIZE; i++) {
for (int j = 0; j < SIZE; j++) {
this.board(i)(j) = board(i)(j);
}
}
}

private boolean isInRow(int row, int number) {
for (int i = 0; i < SIZE; i++)
if (board(row)(i) == number)
return true;

return false;
}

private boolean isInCol(int col, int number) {
for (int i = 0; i < SIZE; i++)
if (board(i)(col) == number)
return true;

return false;
}

private boolean isInBox(int row, int col, int number) {
int r = row - row % 3;
int c = col - col % 3;

for (int i = r; i < r + 3; i++)
for (int j = c; j < c + 3; j++)
if (board(i)(j) == number)
return true;

return false;
}

private boolean isOk(int row, int col, int number) {
return !isInRow(row, number)  &&  !isInCol(col, number)  &&  !isInBox(row, col, number);
}

public boolean solve() {
for (int row = 0; row < SIZE; row++) {
for (int col = 0; col < SIZE; col++) {
if (board(row)(col) == EMPTY) {
for (int number = 1; number <= SIZE; number++) {
if (isOk(row, col, number)) {
board(row)(col) = number;

if (solve()) {
return true;
} else {
board(row)(col) = EMPTY;
}
}
}

return false;
}
}
}

return true;
}

public void display() {
for (int i = 0; i < SIZE; i++) {
for (int j = 0; j < SIZE; j++) {
System.out.print(" " + board(i)(j));
}

System.out.println();
}

System.out.println();
}

public static void main(String() args) {
Sudoku sudoku = new Sudoku(GRID_TO_SOLVE);
System.out.println("Sudoku Grid to Solve");
sudoku.display();

if (sudoku.solve()) {
System.out.println("Solved Grid");
sudoku.display();
} else {
System.out.println("No Solution");
}
}

}
``````