Posts

Android Dependencies: KT

// ksp id("com.google.devtools.ksp") version "1.9.22-1.0.16" apply false //dragger hilt implementation("com.google.dagger:hilt-android:2.50") ksp("com.google.dagger:hilt-compiler:2.50") id("com.google.dagger.hilt.android") version "2.50" apply false // Retrofit implementation ("com.squareup.retrofit2:retrofit:2.9.0") implementation("com.squareup.retrofit2:converter-gson:2.9.0") Github: https://github.com/square/retrofit/releases/tag/2.9.0

Segment Tree Data Structure Program in Java

 Segment Tree is a data structure that facilitates fast range queries such as finding the sum across a range of numbers.

N-Queen Arrangement Problem [Backtracking]

 Programming Language - Java public static boolean saveTheQueen( int [][] board , int col) { if (col>= board.length) return true; for ( int row= 0 ; row< board.length ; row++) { /* Constrains */ if (diagonals(board , row , col)) { board[row][col] = 1 ; /* Recursion */ if (saveTheQueen(board , col+ 1 )) return true; /* Backtracking */ board[row][col] = 0 ; } } return false; } static boolean diagonals( int [][] board , int row , int col) { for ( int i= 0 ; i<col ; i++) if (board[row][i] == 1 ) return false; for ( int x=row , y=col ; x>= 0 && y>= 0 ; x-- , y--) if (board[x][y] == 1 ) return false; for ( int x=row , y=col ; y>= 0 && x<board.length ; x++ , y--) if (board[x][y] == 1 ) return false; return true; }

Clone Graph Problem : Recursive Approach - Java

 Programming Language - Java Algorithm Design - Recursion  public Vertex cloneGraph(Vertex vertex) { if(vertex == null) return null; return cloneGraph(vertex,new HashMap<>()); } private Vertex cloneGraph(Vertex begin, Map<Integer,Vertex> map) { if(map.containsKey(begin.weight)) return map.get(begin.weight); Vertex vertex = new Vertex(begin.weight); map.put(begin.weight,vertex); for (Vertex it : begin.neighbors) vertex.neighbors.add(cloneGraph(it,map)); return vertex; }

Rat In A Maze Problem - Solution in Java [Recursion and Backtracking]

 Problem - Rat In A Maze Algorithm - Recursion and Backtracking Programming Language - Java import java.util.Arrays; class Main { static int[][] maze = { {1, 1, 0, 1}, {1, 1, 1, 1}, {0, 1, 0, 0}, {0, 1, 1, 1} }; static int[][] path = { {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0} }; public static void main(String[] args) { move(0, 0); for (int[] i : path) { System.out.println(Arrays.toString(i)); } } public static boolean move(int x, int y) { /* End of the maze? */ if (x == (maze.length - 1) && y == (maze.length-1)) { path[x][y] = 1; return true; } if (isValidPath(x, y)) { path[x][y] = 1; /* x-direction */ if (move(x + 1, y)) return true; /* y-direction */ if (move(x, y + 1)) return tr...