Professional Documents
Culture Documents
Set 1 - Design
Set 1 - Design
read_students(A, n)
1. for i = 1 to n
read the zone code entered by student i and store it in A[i]
print_students(A, n)
1. for i = 1 to n
print the value stored in A[i]
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]
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
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
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
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
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