MCSL 216
MCSL 216
M
AA and Web Design Lab Assignment
D
Section-1
Ans 1.The task scheduling problem provided indicates four jobs with specific service times:
● ob 1: Service Time = 3
J
● Job 2: Service Time = 7
● Job 3: Service Time = 4
● Job 4: Service Time = 8
ince the goal is to minimize the total amount of time spent in the system, we should use the
S
Shortest Job First (SJF)algorithm, where the jobwith the shortest service time is processed
first.
Explanation:
● ob 1finishes at time 3.
J
● Job 3finishes at time 7.
● Job 2finishes at time 14.
● Job 4finishes at time 22.
he total time spent in the system for all jobs is22 time units, as calculated by the SJF
T
algorithm.
Ques 2 Implement a recursive binary search algorithm …………………………………..
10 35 40 45 50 55 60 65 70 100
rray: [10, 35, 40, 45, 50, 55, 60, 65, 70, 100]
A
Target: 100
Code:
return -1
# Calculate middle index
# Step-by-step process
if arr[mid] == target:
return mid
else:
arr = [10, 35, 40, 45, 50, 55, 60, 65, 70, 100]
target = 100
# Perform binary search
if result != -1:
else:
he recursive binary search successfully finds the target value 100 at index 9. The recursive call
T
tree clearly illustrates how the algorithm splits the array and narrows down the search at each
step.
Section-2
Q1: Design a form for booking a room in the Hostel through an institutional website
ns.Here’s a design for a hostel room booking form, with JavaScript for field validation, submit
A
functionality, and reset functionality. I'll include the HTML, JavaScript, and an explanation of how
each requirement is addressed.
.payment-options
label
{
margin-left
:
5px
;
}
</
style
>
</
head
>
<
body
>
<
h2
>
Hostel Room Booking Form
</
h2
>
<
form
id
=
"bookingForm"
onsubmit
=
"
return
validateForm
()"
>
</
style
>
</
head
>
<
body
>
<
h2
>
Hostel Room Booking Form
</
h2
>
<
form
id
=
"bookingForm"
onsubmit
=
"
return
validateForm
()"
>
</
div
>
<
div
>
<
label
for
=
"credit"
>
Credit Card
</
label
>
<
input
type
=
"radio"
id
=
"credit"
name
=
"paymentMode"
value
=
"Credit Card"
>
</
div
>
</
div
>
<
s
pan
id
=
"paymentModeError"
class
=
"error"
></
span
>
</
form
>
document
.
getElementById
(
"firstNameError"
).
innerText
=
"First
name is required"
;
isValid
=
false
;
}
else
{
document
.
getElementById
(
"firstNameError"
).
innerText
=
""
;
}
// Email Validation
const
email
=
document
.
getElementById
(
"email"
).
value
;
if
(
email
===
""
) {
document
.
getElementById
(
"emailError"
).
innerText
=
"Email is required"
;
isValid
=
false
;
}
else
{
document
.
getElementById
(
"emailError"
).
innerText
=
""
;
}
document
.
getElementById
(
"arrivalDateError"
).
innerText
=
"Arrival date is required"
;
isValid
=
false
;
}
else
{
document
.
getElementById
(
"arrivalDateError"
).
innerText
=
""
;
}
document
.
getElementById
(
"departureDateError"
).
innerText
=
"Departure date is required"
;
isValid
=
false
;
}
else
{
document
.
getElementById
(
"departureDateError"
).
innerText
=
""
;
}
// Country Validation
const
country
=
document
.
getElementById
(
"country"
).
value
;
if
(
country
===
""
) {
document
.
getElementById
(
"countryError"
).
innerText
=
"Country is required"
;
isValid
=
false
;
}
else
{
document
.
getElementById
(
"countryError"
).
innerText
=
""
;
}
document
.
getElementById
(
"paymentModeError"
).
innerText
=
"Payment mode is required"
;
isValid
=
false
;
}
else
{
document
.
getElementById
(
"paymentModeError"
).
innerText
=
""
;
}
document
.
getElementById
(
"departureDateError"
).
innerText
=
""
;
document
.
getElementById
(
"countryError"
).
innerText
=
""
;
document
.
getElementById
(
"paymentModeError"
).
innerText
=
""
;
}
</
script
>
</
body
>
</
html
>
Key Points:
his form structure is designed to meet the criteria of validating the fields, error handling, and
T
reset functionality using JavaScript.