Ass 1
Ass 1
Problem statement:
Write a Python program to store marks scored in subject “Fundamental of Data
Structure” by N students in the class. Write functions to compute following:
a) The average score of class
b) Highest score and lowest score of class
c) Count of students who were absent for the test
d) Display mark with highest frequency
Objective:
Understand the use of Array as linear data structure
Theory:
Linear Data structure
A data structure is said to be linear if its elements form a sequence or
a linear list.
Examples:
1. Array
2. Linked List
3. Stacks
4. Queues
Definition of Array:
An array is a collection of data that holds fixed number of values of same data type.
Declaration of array:
C/C++: data_type array_name[array_size];
For example: if you want to store marks of 100 students, you can create an array as
float marks[100];
suppose you declared an array mark as above. The first element is mark[0], second
element is mark[1] and last element is mark[99].
Python
Advantages of array:
1. Easier to use and access
2. Faster access to the element
3. Array permit efficient random access
4. Arrays are most appropriate for storing a fixed amount of data
5. Arrays are most compact data structures
6. Well known application such as searching ,hash table, matrix operation and
sorting
Disadvantages of array:
1. Fixed size - the size of the array is static
Algorithm:
Step 1: Start
Step 2: Read number of students in n
Step 3: Read marks of n students in array marks
Step 4: Initialize sum =0 and i=0
Step 5: if (i >= n ) go to 9
Step 6: sum =sum + marks[i]
Step 7: i=i+1
Step 8: go to 5
Step 9: average=sum/n
Step 6: Display average
Step 7: Stop
Time Complexity:
1) Calculating Average is ___________________
Test cases
Conclusion: Array is better data structure for implementing fixed size of data and
processing is also easy.
Practice problem:
Find out how many students have got first class in that subject