Sunday, 14 June 2020

How to design or write an algorithm for a given problem statement.....


How to write an Algorithm for a following Problem Statement:

Problem Statement:

In second year computer engineering class, group A student’s play cricket, group B students play badminton and group C students play football. 

Write a Python program using functions to compute following: -

a) List of students who play both cricket and badminton 

b) List of students who play either cricket or badminton but not both 

c) Number of students who play neither cricket nor badminton 

d) Number of students who play cricket and football but not badminton. 

(Note- While realizing the group, duplicate entries should be avoided, Do not use SET built-in functions) 

 

 

Solution:

First of all we have to analyze the problem statement, we have to find out the following things from the Problem statement.
1. What is given in the Problem statement? [Given]

2. Identify the entity and it's attributes. [Entity]
 
3. Identify the users actual requirements and what are the inputs we are accepting from user.[Input]

4. Identify to store and process the data which data structure is required? [Data Structure]

5. How many functions are there in Problem statement? [Output]


Analysis of Problem Statement by referring above five points: 

1. Given: 

In the above Problem Statement Given/Assume things are: 
a. Class SEA Student Roll numbers. that is whole class strength of SEA
b. Students Plays in Group_A Cricket: Group_B Badminton: and Group_C Football: 

2. Entity:

Here the entity is Class_SE_A and the attribute is Rollno.

3. Input:

As a input we have to accept following things from the user:

3.1 Group_A Cricket: The Rollno of students who plays Cricket from Class_SE_A.
3.2 Group_B Badminton: The Rollno of students who plays Badminton from Class_SE_A.
3.3 Group_C Football: The Rollno of students who plays Football from Class_SE_A.
3.4 Class_SE_A: we have to assume the N number of students in class SE A. 

4. Data Structure:

To Store and Process the data as per user requirement we are using LIST  as a data Structure in Python Programming Language.

5. Output:

As per the user requirement user wants following things as an output when he is going to process the data.
5.1 List of students who play both cricket and badminton.
5.2 List of students who play either cricket or badminton but not both.
5.3 Number of students who play neither cricket nor badminton.
5.4 Number of students who play cricket and football but not badminton.

In this way we are going to analyze each and every problem statement before designing the algorithm that is called as "Requirement Analysis" in Software Development Life Cycle.

So by referring the above analysis,
we comes to know that we have to design Four algorithms for  each and every Output.

Algorithms:

5.1 Algorithm for List of students who play both cricket and badminton.


  
5.2 Algorithm for List of students who play either cricket or badminton but not both.



5.3 Algorithm for Number of students who play neither cricket nor badminton.


 
5.4 Algorithm for Number of students who play cricket and football but not badminton.


data structures and algorithms Web Developer

1 comment:

  1. Should there be another persuasive post you can share next time, I’ll be surely waiting for it.
    เล่นบอลไม่มีขั้นต่ำ

    ReplyDelete