You are on page 1of 8

Set 1 - Question 1

read_students(A, n)
1. for i = 1 to n
read the zone code entered by student i and store it in A[i]

Evaluation criteria : [1 mark]

print_students(A, n)
1. for i = 1 to n
print the value stored in A[i]

Evaluation criteria : [1 mark]

arrange_students(A, n)

//Students can use any of the stable sorting techniques for arrange_students() -
bubble/insertion/selection/merge sort.
Insertion sort is given below.
arrange_students(A, n)
1. for i = 2 to n
a. key = A[i]
b. j = i - 1
c. while j > 0 and risk_value(A[j]) > risk_value(key)
A[j+1] = A[j]
j =j-1
d. A[j + 1] = key

risk_value(code) //function to find the risk value of the zone code (Students can also do
this inside the arrange_students() function.).

1. r_value[26] = [Z,Y,X,W,V,U,T,S,R,Q,P,O,N,M,L,K,J,I,H,G,F,E,D,C,B,A]
2. if code > 96 //change the case to upper
code = code - 32
3. for i = 1 to 26
if r_value[i] == code
return i

OR

risk_value(code) //function to find the risk value of the zone code (Students can also do
this inside the arrange_students() function.).
1. if code < 91 //if the code is capital
code =code + 32 // or return c[91 - code]
2. return 123 - code

OR

risk_value(code) //function to find the risk value of the zone code (Students can also do
this inside the arrange_students() function.).
1. c[26] = [26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
2, 1]
2. if code < 91 //if the code is capital
code = code + 32 // or return c[code - 65]
3. return c[code - 97]

Evaluation criteria : [1 mark]


Division:
1. Sorting method - 0.5 marks
2. Proper mapping between zone code and risk values- 0.5 marks

list_students(A, n, rval)
1. student_present = 0
2. for i = 1 to n
if risk_value(A[i]) == rval
print i
student_present = 1
3. if student_present == 0
print -1

Evaluation criteria : [1 mark]


Division:
1. Proper mapping to the risk values(0.5 marks)
2. If student not present with zone code risk value rval print -1 (0.5 marks)
Set 1 - Question 2
divide_students(A, n, rval)
//find the first student from zone with rval and swap it with the last element in A
1. for i = 1 to n
if risk_value(A[i]) == rval
temp = A[i]
A[i] = A[n]
A[n] = temp
break
2. return partition(A, 1, n)

partition(A, p, r)
//partition the elements in the array A into two
1. i = p-1
2. pivot = risk_value(A[r])
3. for j = p to r - 1
if risk_value(A[j]) <= pivot
i = i +1
temp = A[i]
A[i] = A[j]
A[j] = temp
4. temp = A[i+1]
5. A[i+1] = A[r]
6. A[r] = temp
7. return i+1

Evaluation criteria : [3 marks]


Division:
1. Find pivot and swap it with last element - 1 mark
2. Finding the risk value and using it in the condition check for partition
- 1 mark
3. Design of partition() function - 1 mark
arrange_students(A, n, pos)
//merge the students in group 1 and group 2 and return resulting array

1. create an array T of size n 1. create an array T of size n


2. i = 1 2. i = 1
3. j = pos+1 3. j = pos + 1
4. k = 1 4. k = 1
5. while i <= pos
5. while i <= pos and j <= n
T[k] = A[i]
T [k] = A[i]
k=k+1
i=i+1 k=k+1
if j <= n T[k] = A[j]
T[k] = A[j] k=k+1
k=k+1 i=i+1
j=j+1
j=j+1
6. while j <= n
6. while i <= pos
T[k] = A[j]
T[k] = A[i]
k=k+1
j=j+1 k=k+1
7. for i = 1 to n i=i+1
A[i] = T[i] 7. while j <= n
T[k] = A[j]
k=k+1
j=j+1
8. for i = 1 to n
A[i] = T[i]

Evaluation criteria : [1 mark]


list_students(A, n, c)
//print the admission number of students with zone code c
1. flag = 0
2. for i = 1 to n
if A[i] = c
then print i
flag = 1
3. if flag = 0
then print -1

Evaluation criteria : [1 mark]


Set 1 - Question 3
Structure Definition as follows
struct student{
char reg_no[10];
int ad_no;
int time_req;
};

read_details(A, n)
1. for i = 1 to n
a. read the register number of student i and store it in A[i].reg_no
b. read the admission number of student i and store it in A[i].ad_no
c. read the time required per day for student i and store it in A[i].time_req

Evaluation criteria : [1 mark]

print_students(A, n)
1. for i = 1 to n
print A[i].reg_no, A[i].ad_no and A[i].time_req // separated by space

Evaluation criteria : [1 mark]


allocate_CCC(A,n,tslot)

1. Sort the student details in the increasing order of their admission number and
store in array A. (Students can use any of the stable sorting algorithms, but the
design is not necessary here.)
2. slot_start = 0
3. finished_students = 0 //number of students whose required time finished at ccc
4. while finished_students != n
for i = 1 to n
a. if A[i].time_req != 0
i. if A[i].time_req <= tslot
slot_end = slot_start + A[i].time_req
A[i].time_req = 0
finished_students = finished_students + 1
ii. else
slot_end = slot_start + tslot
A[i].time_req = A[i].time_req - tslot
iii. print slot_start, slot_end and A[i].reg_no // separated by space
iv. slot_start = slot_end

Evaluation criteria : [2 mark]


Division:
1. Sort the student details in the increasing order of their admission number
- 0.5 marks
2. Step 4 - 1.5 marks

You might also like