Skip to content

Fix: avoid greedy selection in parsons line grader LIS calculation#1304

Open
ascholerChemeketa wants to merge 4 commits into
RunestoneInteractive:mainfrom
ascholerChemeketa:parsons-lis-bugfix
Open

Fix: avoid greedy selection in parsons line grader LIS calculation#1304
ascholerChemeketa wants to merge 4 commits into
RunestoneInteractive:mainfrom
ascholerChemeketa:parsons-lis-bugfix

Conversation

@ascholerChemeketa

Copy link
Copy Markdown
Contributor

Jan Pearce introduced me to Lori Postner this morning. Lori identified inconsistencies and confusing behavior with block highlighting for solutions with incorrect ordering. I took a look at the longest increasing sequence generation code and it does appear there is an issue.

Given [5, 1, 6, 2, 3, 4], it would identify [2, 3, 4] as the LIS sequence instead of [1, 2, 3, 4]. The algorithm is greedy - when starting at 1, once it identifies [1, 6] as a possibility, it rejects considering [1, 2, ....] as 2 doesn't continue the first possible sequence discovered. Thus the longest sequence if finds for 1 is [1, 6] and the final LSI identified is [2, 3, 4].

Copilot AI review requested due to automatic review settings July 14, 2026 07:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes the longest-increasing-subsequence (LIS) computation used by the Parsons line grader to avoid greedy subsequence selection, improving correctness of “out-of-order” block highlighting for certain answer permutations.

Changes:

  • Replaces the previous greedy subsequence builder with a dynamic-programming LIS construction (build LIS ending at each position, then select the longest).
  • Improves consistency of identified “in-order” blocks for grading/highlighting in incorrect-order submissions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +11 to +17
var subsequenceForCurrent = [arr[i]];
for (var j = 0; j < i; j++) {
if (
arr[j] < arr[i] &&
allSubsequences[j].length + 1 > subsequenceForCurrent.length
) {
subsequenceForCurrent = allSubsequences[j].concat(arr[i]);
Comment on lines +11 to 20
var subsequenceForCurrent = [arr[i]];
for (var j = 0; j < i; j++) {
if (
arr[j] < arr[i] &&
allSubsequences[j].length + 1 > subsequenceForCurrent.length
) {
subsequenceForCurrent = allSubsequences[j].concat(arr[i]);
}
}
allSubsequences.push(subsequenceForCurrent);
Copilot AI review requested due to automatic review settings July 14, 2026 13:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

});

it("linegrader reports correct LIS for incorrect order", async () => {
const p = await makeParsons();
Copilot AI review requested due to automatic review settings July 15, 2026 14:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.

Files not reviewed (1)
  • bases/rsptx/interactives/package-lock.json: Generated file

Comment on lines 45 to 48
"btm-expressions": "^0.1.12",
"byte-base64": "^1.1.0",
"canvas": "^3.2.3",
"codemirror": "^5.59.4",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense to me @ascholerChemeketa as I do not have to install canvas to run the tests on my mac.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants