Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

BAHRIA UNIVERSITY (KARACHI CAMPUS)

CSC 221 - Data Structures & Algorithms - Assignment 1


CLO-3 Deadline: 12th November, 21
Class: BSE-3A/B Total Marks 10

1. Design an algorithm to read a list of real numbers representing numeric scores, call functions
to calculate their mean and standard deviation, and then call a function to determine and
display the letter grade corresponding to each numeric score. Considering the following
equations and table for letter grade:

Here, m is the mean score and δ is the standard deviation; for a set of n numbers x1, x2, . . .,
xn, these are defined as follows:

x = Numeric Score Letter Grade

x<m- F

m- δ<=x<m- D

m- δ<=x <m+ C
m+1δ<=x<m
+ B
2

m- δ<=x A

SOLUTION:

function mean()

MUAZ SHAHZAD 02-131202-081


{
o set mean=0;
o set sum=0;
o sum = sum+array[i]
o repeat step 3 until length of array
o mean=sum/length of array
}

function calculatestandard deviation()


{
o set sum=0;
o set standard deviation=0
o set var=0
o var=take square of (array[index]-mean)
o standard deviation = take squareroot of (var/array.length)

function value()

{
o loop till (index < n)
o if ( data[index] < y)
write “f grade”
o if ( y <= data[index] and data[index]<y)
write “d” grade
o ” if (y <= data[index] and data[index] < z)
write “c grade”
o if ( z <= data[index] and data[index] < z )
write “b grade”
o if ( y <= data[index] )
write “a grade”
o

MUAZ SHAHZAD 02-131202-081


2. Suppose a linked list in a memory consisting of numerical values. Select a procedure for each
of the following tasks:

a) Maximum Value
b) Average
c) Product

1
SOLUTION:

MAX VALUE:

 Store the maximum of first two nodes in a variable max.


 Store the minimum of first two nodes in a variable second_max.
 Iterate over the remaining linked list. For each node:
 If current node value is greater than max, then set second_max as max and max as current
node’s value.

AVERAGE:
 Create variable R and sum.
 Repeat the node n times from the head node to tail node.
 For i=0; repeat i till next.node = 0;
 Add the value of each node in the variable sum i.e sum += R
 Increment the value of loop
 Divide the sum by the length of linked list and print average.

PRODUCT:
 Create variable R and product
 Repeat the node n times from the head node to tail node.
 For i=0; repeat i till next.node = 0;
 Multiply the value of each node in the variable product i.e product *= R
 Increment the value of loop
 Print the product.

MUAZ SHAHZAD 02-131202-081

You might also like