CSE1021 - Introduction to Problem Solving and Programming – Question Bank for
Midterm Examination – November 2024
Module 1 - Introduction to Computer Problem Solving
1. Brief the essential components of the problem-solving techniques.
2. Write a pseudocode to read the marks of 10 students. If marks are greater than 50, the student
passes, else the student fails. Count the number of students passing and failing.
3. Write an algorithm and draw a flowchart that calculates salary of an employee. Prompt the
user to enter the Basic Salary, HRA, TA, and DA. Add these components to calculate the
Gross Salary. Also, these components to calculate the Gross salary. Also deduct 10% salary
from the Gross Salary to be paid as tax.
4. Explain the top-down approach to problem-solving using a simple example.
5. Write Short notes on uses of Flowchart. Write the algorithm and draw a flowchart for
the implementation of a calculator.
6. Describe the problem-solving process in computer science. Discuss the importance of
defining a problem clearly and provide an example illustrating each process step, from
problem definition to solution implementation.
7. Create a flowchart for an algorithm that calculates the average of a list of numbers through
top-down design in algorithm development. Include an explanation of how each step in the
flowchart corresponds to the algorithmic process.
8. Draw a flowchart to simulate a simple banking system where a user can either deposit or
withdraw money. Ensure that the balance cannot be negative.
9. What is the time complexity of linear search and binary search? Explain with example, why
is binary search more efficient?
10. Develop an algorithm, pseudocode, and flowchart to simulate a basic ATM machine that
allows a user to withdraw money from an account, provided they have sufficient balance.
11.
Analyze the time and space complexity of the above code by providing comments for each
step.
12. Develop an algorithm, pseudocode, and flowchart to calculate the “Average Score for a
Class”
13. Explain the top-down approach facilitate the process of writing a program in Python, and
what are the key steps involved in implementing it? Provide an example to illustrate the
approach.
14. Explain the function 'Addition of two numbers' from the problem definition perspective.
15. Explain with examples the best, average, and worst case of an algorithm.
16. Write the pseudo-code and draw a flowchart to calculate the Electricity Bill (EB) using four
levels of unit rates.
17. What are the various symbols used in flowchart design?
Create a flowchart for a Simple Voting System in which if the user is 18 years or older and a
citizen, allow them to proceed to the voting process.
If the user is not eligible, meaning they are either under 18 or not a citizen, display a message
indicating their ineligibility and terminate the process
18. Elucidate the properties of an algorithm. Write an algorithm to determine a student’s final
grade and indicate whether it is passing or failing. The final grade is calculated as the average
of four marks.
19. Explain the different types of asymptotic notation and discuss their significance in evaluating
the performance of algorithms.
20. Explain the key steps involved in problem solving with some examples
21. Write the algorithm to compute the factorial of n. (4 Marks)
Draw the flowchart that represents the process of calculating the factorial. (3 Mrks)
Write the pseudocode for the same problem. (3 Mrks)
22. Provide a flow chart and an algorithm to determine whether the supplied number is Armstrong
or not.
23. If you want to check the efficiency of your implemented algorithm, then what are the
important factors that must be considered for the same? Explain with suitable examples.
24. Write an algorithm for grade calculation of a student. Grade of a student will be assigned as
per below table
Grade Marks
> 90 S
Between 81 and 90 A
Between 71 and 80 B
Between 61 and 70 C
Between 51 and 60 D
Between 41 and 50 E
< 41 Fail
25. Describe top down design approach with one example. Draw a flowchart to calculate factorial
of a given number.
26. Write the algorithm and draw the flow chart for biggest among three number
27. Explain about Top Down Approach with example
28. Write the pseudo code for Quadratic equation and explain.
29. Explain about various problem solving aspects in detail with real time example.
30. Provide a flowchart and pseudo code for calculating the roots for the quadratic equation.
31. Create pseudocode, algorithm and a flowchart for calculating the sum of integer numbers
from 1 to 100.
32. Analyze the time and space complexity for the below program.
def sumofpairs(lst):
n = len(lst)
pairsum = 0
for i in range(n):
for j in range(i+1, n):
pairsum += lst[i] + lst[j]
return pairsum
numbers = [1, 2, 3, 4, 5]
result = sumofpairs(numbers)
print("Sum of pairs of elements:", result)
33. What is an algorithm and pseudocode, and why do we use them? Also, explain how they're
different with an example?
34. Write a Python script to find the roots of a quadratic equation. It should not use any predefined
functions and should explain the involved datatypes and their usages.
35. Create a flowchart demonstrating the process of managing a bank account, including deposits,
withdrawals, and balance inquiries. Write pseudocode for withdrawing money from an
account while ensuring there are sufficient funds. Develop a Python program that simulates
a bank account, allowing users to deposit, withdraw, and check their balance
36. Consider a scenario where you need to process a large text file and perform various operations
on its contents. How would you approach optimizing the time complexity of your Python
script to handle this task efficiently with an example code?
Module2 - Python Data, Expressions and Statements
1. Provide an example of concatenating a string with an integer in Python and explain why it
requires type conversion?
2. Write a python program that reads integers until the user wants to stop. When the user stops
entering numbers, display the largest of all the numbers entered.
3. What is the use of functions in a program? Explain how functions implement modularity
4. Operators in Python have varying precedence. Explain operator precedence in python with
an example. Evaluate the following expression. 45 / 5 + 3 × 4 – 7 * (44 % 5)
5. Discuss the importance of functions in Python programming. Write a function that takes a list
of numbers and returns the sum and average of those numbers. Provide an example of how to
call this function.
6. Outline the various data types available in Python. Explain the difference between
expressions and statements with examples. Describe how operator precedence affects the
evaluation of expressions, and illustrate with a code snippet.
7. Evaluate the expression 75 - 5 ** 2 + 3 * 2 ** 4 // 2 and explain how precedence and
associativity affect the result.
8. Write a Python program to check the number is even or odd by using bitwise operators.
9. Write a Python program to find the 2nd largest digit of a number.
Example: if the number is 4798, the output should be 8.
10. Write a Python program that prints all numbers between 1 and 300 in reverse order, which
are divisible by both 2 and 3 but not divisible by 5.
11. Imagine you are writing a Python script and want to test small code snippets quickly without
running the entire program. Which Python interpreters can help in this scenario? Provide an
example to demonstrate.
12. Suppose you need to write a Python function that calculates the factorial of a number. How
would you define this function without any parameters, and how would you use it in your
program? Write the function definition and explain how to call it in the main flow of your
program.
13. Construct a Python function to calculate the square root of a number without using any
parameters, and how to incorporate it into your program? Provide the function definition and
explain how to call it within the main part of your program.
14. Illustrate Python interpreter, and how does the interactive mode help in testing and debugging
small code snippets? Provide examples to demonstrate its use.
15. Explain operator precedence and solve the following expression accordingly:
8 + (15 / 3) * 4 - 6^2 + (10 - 3) / 7
16. Solve the following using bitwise AND, OR, and XOR operations (A = 44, B = 96) (i)
A | B (ii) A & B (iii) A ^ B
17. Explain the concept of parameters and arguments in Python functions and how understanding
the flow of execution helps write better code. Provide a practical example in Python to
demonstrate these concepts
18. What are the various operators in python? Write a code snippet for membership operators.
19. A ________ function in Python is a small anonymous function which is defined using the
______ keyword.
Write a code snippet to multiply two numbers using above function
20. Discuss keyword arguments and variable length arguments with example
21. Given the following Python Expression result = 5 + 3 * 2 ** 2 // 4 - 1.
a) Explain the steps of how Python evaluates this expression based on operator precedence
and associativity.
b) Rewrite the expression by adding parentheses to show the order in which the operations
are performed
22. Write a Python function find_unique_characters(s) that takes a string 's' and returns a new
string that contains only the characters that appear exactly once in 's', in the order they first
appear.
Input : programming
Output: progamin
23. Differentiate between python parameters and arguments and explain all arguments types
supported by python with examples.
24. Implement a python function to perform swapping of two numbers and consider below
given constraint in your code:
1-> don’t use any third variable
2-> don’t use any arithmetic of comma operators
25. Explain the use of associativity and precedence in operator. Describe four different bitwise
operators with one example.
26. What is recursive function? Write a user defined function in python to print the following
pattern. Function should have number of rows as an argument.
1
23
456
7 8 9 10
27. Explain the relational and logical operators with suitable examples for each case?
28. Write a program for swapping a number with using temporary variable and without using
temporary variable.
Sample Input: a=10, b=20
Sample Output: a=20, b=10
29. Explain about function with the its proto type, argument and return type and also write a
python program for finding the factorial for the given number using function.
30. What is the role of an interpreter? Give a detailed note on python interpreter and interactive
mode of operation. Explain how python works in interactive mode and script mode with
examples.
31. Explain the following expressions in a detailed, step-by-step manner:
a) result = (8 << 2) | (3 >> 1)
b) result = ((5 + 2) * 3 - 4 / 2)+1
32. Explain in detail about various operator used in python with example
33. Consider you where tasked with creating a Python program that analyzes sales data. You need
to design modules and functions to handle various tasks such as data input, processing, and
output. Explain how you would define and utilize functions effectively within your program,
discuss the flow of execution, and elaborate on the concepts of parameters and arguments in
the context of your implementation.
34. What is the role of an interpreter? Give a detailed note on python interpreter and interactive
mode of operation. Explain how python works in interactive mode and script mode with
examples.
35. Can you explain how Python's interactive mode handles syntax errors and exceptions
differently compared to running scripts? With an example
36. Explain how to implement a sorting algorithm in Python, and you need to swap elements in
a list during the sorting process. How can tuple assignment be used to perform element
swapping without using temporary variables?
37. Discuss the difference between positional arguments, keyword arguments, and default
arguments in Python function definitions. Provide examples demonstrating their usage
38. Explain the following expressions in a detailed, step-by-step manner:
a) result = (8 << 2) | (3 >> 1)
b) result = ((5 + 2) * 3 - 4 / 2)+1
39. Explain about function with the its proto type, argument and return type and also write a
python program for finding the factorial for the given number using function
40. Write a program for swapping a number with using temporary variable and without using
temporary variable.
Sample Input: a=10, b=20
Sample Output: a=20, b=10
Module 3 - Fundamental Algorithms
1. Write a python program to print the following pattern.
2. Write an iterative program to find the factorial of a number.
3. Describe how character to number conversion is performed in Python. Write a Python function
that takes a string of digits as input and returns the corresponding integer value
4. Write a Python program to print the following picture.
*
***
*****
*******
*********
*******
*****
***
*
5. How can you use conditional statements in Python to make decisions within a program?
Provide an example to demonstrate.
6. Implement conditional statements in Python to control the flow of your program based on
specific conditions with any example
7. Write a Python program that asks the user for a positive integer and calculates its factorial
using a while loop. If the user enters zero or a negative number, the program should display
an error message and continue prompting for a valid positive integer.
8. Explain with examples the following statements:
i) break ii) continue iii) pass
9. How can you use conditional statements in Python to make decisions within a program?
Provide an example to demonstrate.
10. Write a Python program for a movie theatre that calculates ticket prices based on age and time
of day. Tickets for children (age < 12) are $5, adults (age >= 12) are $10, and seniors (age >=
60) are $7. For evening shows (after 5 PM), there’s an additional $2 surcharge
11. Write a programme to carry out the eligibility function, which shows a company's eligibility
for insurance based on a set of requirements:
1->if the worker is married
2->if the worker is a male professional without a spouse and under 35 years old
3->if the worker is a female professional without a spouse and under 30 years old
Insurance was rejected in the remaining situations
12. Write a python program to display all Armstrong numbers in between 100 to 999.
13. Two numbers A and B are passed as input. A number N is also passed as the input. The
program must print the numbers from B to A (inclusive of A and B) which are not divisible
by N.
Hint : Sample Input1
4
15
5
Sample Output1
14 13 12 11 9 8 7 6 4
The numbers 5,10,15,20 are left out as they are divisible by 5
14. Discuss the different types of loops with example code?
15. The integer value Hrs and Mins was passed as the input to the program. Write the python
program to print the total number of seconds in the given hrs and Mins.
16. The Managing Director(MD) of the company has planned to encourage the staff members
coming to the office on time. MD was announced the consecutive incentives form the starting
of the week Monday to end of the week Saturday. The reward will be given as Rs.500 that is
more than the punctuality incentive than the previous day. The starting day Incentive (Icen) is
passed as the first input. The second input N is passed as the number of days the staff came on
time to the office and the output should be p which is the total amount of incentive he got in
the particular week.
Hint :
Sample Input1
1000
3
Sample Output1
4500
Explanation:
On First Day he receives : Rs. 1000, second day : Rs. 1500, Third Day : 2000.
So total : Rs. 4500.
17. Balu was kind to beggars. Balu daily donates 50% of the amount he has when a beggar request
him. Input for the program is the amount M1 left in Balu hand and the number of beggars B1
who received the amount are passed as the input. The program must print the money Balu had
in the starting of the day
Hint : Sample Input1
100
2
Sample Output1
400
Balu donated to 2 beggars.
When Balu encountered Second beggar he had 100 *2 = 200
When Balu encountered First beggar he had 200 *2 = 400
18. Write a python program to convert any base(2,8,16) to decimal.
19. Explain about various Iterative and control statements with example in python.
20. Explain about various Iterative statement with example
21. Write a python program to reverse the given input.
Sample Input: VIT Bhopal 2024
Sample Output: 4202 lapohB TIV
22. How do Boolean values relate to conditions and decision-making in Python programming?
Justify with an examples.
23. Write a function find_index(), which returns the index of a number in the Fibonacci sequence,
if the number is an element of this sequence and returns-1 if the number is not contained in it,
call this function using user input and display the result
24. Write a Python function to compute the factorial of a non-negative integer without using
recursion or built-in functions like math.factorial(). Your function should handle large input
values efficiently and provide a solution with optimal time complexity. Explain with an
example.
25. Balu was kind to beggars. Balu daily donates 50% of the amount he has when a beggar request
him. Input for the program is the amount M1 left in Balu hand and the number of beggars B1
who received the amount are passed as the input. The program must print the money Balu had
in the starting of the day
Hint : Sample Input1
100
2
Sample Output1
400
Balu donated to 2 beggars.
When Balu encountered Second beggar he had 100 *2 = 200
When Balu encountered First beggar he had 200 *2 = 400