Premier University, Department of CSE
Fall 2024, 1st Semester, Assignment
Course Title: Programming Fundamental, Course Code: CSE 1113
Course Outcome: CO3, Total Marks: 10
Problem Scenario: Automate Train Swapper
At an old railway station, you may still encounter one of the last remaining “train swappers”. A
train swapper is an employee of the railroad, whose sole job is to rearrange the carriages of
trains. Once the carriages are arranged in the optimal order, all the train driver has to do is drop
the carriages off, one by one, at the stations for which the load is meant. Now that almost all train
swappers have died out, the railway company would like to automate their operation. Part of the
program to be developed is a routine that decides for a given train the least number of swaps of
two adjacent carriages necessary to order the train. Your assignment is to create that routine.
Problem Description:
The input contains on the first line the number of test cases (N). Each test case consists of two
input lines. The first line of a test case contains an integer L, determining the length of the train
(0 ≤ L ≤ 50). The second line of a test case contains a permutation of the numbers 1 through L,
indicating the current order of the carriages. The carriages should be ordered such that carriage 1
comes first, then 2, etc. with carriage L coming last, and answer the following questions:
1. Find the least number of swaps of two adjacent carriages necessary to order the train using
function.
Sample Input Sample Output
3 Optimal train swapping takes 1 swaps.
3 Optimal train swapping takes 6 swaps.
132 Optimal train swapping takes 1 swaps.
4
4321
2
21
Objectives:
● Write down the Pseudo code for the problem.
● Implement loop and condition statements to rearrange the order of the train.
● Find the least number of swaps of two adjacent carriages necessary to order the train.
Evaluation:
● Provide step-by-step explanations of the problem and illustrate the results with
appropriate diagrams or visualizations.
Design:
Students’ solution design must achieve the given objectives.
Deliverables:
A printed assignment reporting the following tasks:
(i) Provide clear explanations of your work, implementation details, test results, and analysis
addressing the given assignment tasks.
(ii) Briefly address the complex problem-solving questions:
a. Does the solution need in-depth engineering knowledge?
b. Does the solution involve wide-ranging or conflicting technical, engineering, and other
issues?
c. Is the solution well-known, or does it require abstract thinking and analysis to formulate?
d. Does the solution involve infrequently encountered issues?
e. Does the solution need adherence to standards and codes of practice?
f. Does the solution involve stakeholders with conflicting technical requirements?
g. Does the solution involve interdependence between sub-problems or parts?
Rubrics for Assignment marking:
Task Criteria Good (4-5) Moderate (2-3) Poor (1)
i. Problem Properly or near Appropriate solution Inappropriate or no
solution appropriately reasoned for some cases solution
solution
ii. Problem In-depth analysis Shallow analysis Incomplete analysis
analysis