QDBordtoshred / WEni

MIT License
0 stars 0 forks source link

FRQ #3 #20

Open QDBordtoshred opened 7 months ago

QDBordtoshred commented 7 months ago

(a) SparseArray Method getValueAt:

public int getValueAt(int row, int col) {
    for (SparseArrayEntry entry : entries) {
        if (entry.getCol() == col && entry.getRow() == row) {
            return entry.getValue();
        }
    }
    return 0;
}

This method iterates through the entries in the sparse array. If it finds an entry with the specified row and column, it returns the associated value. If no matching entry is found, it returns 0.

(b) SparseArray Method removeColumn:

public void removeColumn(int col) {
    List<SparseArrayEntry> newEntries = new ArrayList<>();
    for (SparseArrayEntry entry : entries) {
        if (entry.getCol() == col) {
            // Skip this entry as it belongs to the column to be removed
            continue;
        }
        if (entry.getCol() > col) {
            // Decrement the column index for entries to the right of the removed column
            newEntries.add(new SparseArrayEntry(entry.getRow(), entry.getCol() - 1, entry.getValue()));
        } else {
            // Keep entries from columns to the left of the removed column unchanged
            newEntries.add(entry);
        }
    }
    // Update the entries list with the modified entries
    entries = newEntries;
    // Decrement the number of columns in the sparse array
    numCols--;
}

This method creates a new list newEntries to store the modified entries. It iterates through the existing entries, skipping the ones in the column to be removed and adjusting the column indexes for entries to the right. Finally, it updates the entries list with the modified entries and decrements the number of columns in the sparse array.

aidenhuynh commented 7 months ago

Comments:

The requirement for assignment is a Jupyter Notebook that runs the code, correctly identifying the FRQ type, and a reflection for the problem.

Score:

0.6/0.9

VINERAJ commented 7 months ago

Your code should be in a Jupyter Notebook, and you show have an issue with the connection between the FRQ and PBL. For this FRQ, I will give you a score of 0.63/0.9