0% found this document useful (0 votes)
30 views3 pages

Ass 1

The document discusses using arrays as a linear data structure in Python to store marks scored by N students in a subject. It describes how to compute the average score, highest and lowest scores, absent students, and most frequent mark. Sample code is provided to find the average marks using an array. The time complexity of related operations is also discussed.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views3 pages

Ass 1

The document discusses using arrays as a linear data structure in Python to store marks scored by N students in a subject. It describes how to compute the average score, highest and lowest scores, absent students, and most frequent mark. Sample code is provided to find the average marks using an array. The time complexity of related operations is also discussed.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Assignment Number: 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].

Graphical representation of array:

Python

Create an array containing car names:

cars = ["Ford", "Volvo", "BMW"]

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

2. Insertion and deletion at any location is difficult

Algorithm:

For finding average marks:

Input: Array of size n


Output: Average marks of student

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 ___________________

2) Finding maximum of an array is _____________________

Test cases

1. n=30 (array size is 20)


2. n=6
10 20 -1 18 -1 -1
3. n=6
-1 20 -1 18 -1 15
4. n=7
-1 -1 -1 -1 -1 -1 -1

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

You might also like