public static <E extends Comparable<E>> boolean searchSortedMatrix(E[][] matrix, E element) {
		if (matrix == null)
			return false;
		
		for (int i = 0; i < matrix.length; i++) {
			if (matrix[i] == null)
				return false;
		}
		
		int rowLength = matrix.length;
		int row = 0;
		int col = matrix[0].length - 1; // column index, initially at last column
		
		// stepwise search from upper right corner going left and down only
		while (true) {
			if (matrix[row][col].compareTo(element) == 0)
				return true;
			if (matrix[row][col].compareTo(element) > 0)
				col--;
			else
				row++;
			if (row == rowLength || col == -1)
				return false;
		}
	}