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

Problem Set

This document provides 30 problems related to algorithmic thinking and programming concepts like data structures, algorithms, searching, sorting, strings, and files. The problems cover basic Python programs and concepts like lists, dictionaries, series summation, number swapping, factoring methods, string operations, file I/O, and more. Students are asked to write Python code to solve each problem and demonstrate steps for some of the problems.

Uploaded by

421243
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
116 views3 pages

Problem Set

This document provides 30 problems related to algorithmic thinking and programming concepts like data structures, algorithms, searching, sorting, strings, and files. The problems cover basic Python programs and concepts like lists, dictionaries, series summation, number swapping, factoring methods, string operations, file I/O, and more. Students are asked to write Python code to solve each problem and demonstrate steps for some of the problems.

Uploaded by

421243
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Introduction to Algorithmic Thinking and Programming (CS101) – Problem Set

Inbuilt Data Structures:


1. Given a list of numbers, construct a Python program to count Even and Odd numbers in a List.
2. Construct a python program to get all unique combinations of two lists L1 and L2. You can assume that
the elements of each list is unique within the list and unique between the two lists. Do not use any kind
of in-built functions. If L1 = ['a', 'b'], L2 = [1, 2] then output should be [['a', 1], ['a', 2], ['b', 1], ['b', 2]].
3. Construct a python program to extract all elements of a list with frequency greater than k. Do not use
the "count" method. If input list is [4, 6, 4, 3, 3, 4, 3, 4, 3, 8] and K = 3 then output should be [4, 3].
4. Construct a Python program using dictionary to find the most frequent word occurring in the text file
mytext.txt.
5. Construct a Python program to find the smallest divisor of an integer given as input.

Fundamental Algorithms:
6. Construct a Python program to find the sum of the following series:
1 1 1 1 1 1 1 1 1
𝑠
+ 𝑠+ 𝑠+ 𝑠+ 𝑠+ 𝑠+ 𝑠+ 𝑠+ 𝑠…
2 3 5 7 11 13 17 19 23
The program needs two values n and s as input, n defines number of terms in the series and s can be
either integer or float value.
7. Construct a python program to swap the given two number using arithmetic and bitwise operators.
8. Consider your roll number as a input, Construct a python program to print True if the binary
representation of the given roll number is palindrome. Else, print False.
9. Construct an algorithm and python program to calculate sum of the following series
𝑎. 𝑥 𝑛 + 𝑎2 . 𝑥 (𝑛−1) + 𝑎3 . 𝑥 (𝑛−2) + ⋯ + 𝑎𝑛 . 𝑥 (𝑛−(𝑛−1))
10. Construct a python program to solve given problem: Consider your roll number as input, find the average
of the digits in the given number. If average is even, rotate your roll number to right direction as last digit
number of times. Else, rotate your roll number to the left direction as first digit number of times.

Factoring methods:

11. Construct a flowchart and Python program to read two number b and P from the user and then compute
the value of 𝒃𝒑 in lesser than p multiplications. Demonstrate the steps of your program for the values of
b=5 and p=99.
12. Construct a user defined Python function to calculate the square root of the given number without using
any predefined functions and power operator. Count the number of function calls initiated for the input
value 25.
13. Construct a Python program to find the non-prime factors of the given number. Illustrate the number of
steps required to compute the non-prime factors of the number n.
14. Construct a recursive Python function to find the 𝒏𝒕𝒉 Fibonacci number. Demonstrate the steps of your
python function for the input value 9 and count the number of function calls.
15. A) which of the following expressions will help us to extract third-to-last digit and second-to-last digit:
i. number % 10 %10
ii. number //10 //10
iii. number – number //10
iv. (number %100) // 10
v. number %10
vi. (numver%1000)//100
B) Illustrate the output of the following code snippet for the given inputs:
def recu_fun(n): Inputs:
if n<0: i) n=8
return recu_fun(-n) ii) n = -513
elif n<10: iii) n = 3052
return n iv) n = 74
else:
return n%10+recu_fun(n//10)

Searching and Sorting Techniques:


16. Construct a Python program that accepts the following list of numbers to sort: L= [19, 1, 9, 7, 3, 10, 13,
15, 8, 12]. Show the list that represents the partially sorted list after three complete passes of bubble
sort?
17. Construct a Python program that accepts the following list of numbers to sort: L= [11, 7, 12, 14, 19, 1, 6,
18, 8, 20]. Show the list that represents the partially sorted list after four complete passes of selection
sort?
18. Construct a Python program that accepts the following list of numbers to sort: L= [15, 5, 4, 18, 12, 19, 14,
10, 8, 20]. Show the list that represents the partially sorted list after four complete passes of Insertion
sort?
19. Construct a Python program that accepts the following list of numbers L= [15, 18, 2, 19, 18, 0, 8, 14, 19,
14]. Suppose you are doing a sequential search of the list. How many comparisons would you need to do
in order to find the key 18, 19 and 20?
20. Suppose you have the following sorted list [3, 5, 6, 8, 11, 12, 14, 15, 17, 18] and you are using the recursive
binary search algorithm. Construct a Python program that find out the number of comparisons required
to search for the key 16, 18 and 8?
Strings:
21. Consider a text file called sample.txt which consists of a paragraph of text. Write a python program to
read the file and print the longest String and its length from the paragraph in the file. Note: Don’t use
built-in functions in Strings.
22. Construct a Python program that accepts a comma separated sequence of words as input and prints the
words in a comma-separated sequence after sorting them alphabetically. Suppose the following input is
supplied to the program: without, hello, bag, world then, the output should be: bag, hello, without,
world.
23. Construct a Python Program to validate a password using following Constraints:
I) Password length must be between 8 and 12
II) Password should not start with Special Character
III) Password should contain at least One Capital, one Small and one digit.
IV) Password Should contain one Special symbol from the given set [_, @, #, .,$,&amp;,*]
24. Consider a List having set of Strings, construct a Python program to display the count of Strings which
have the same Prefix and Suffix by comparing them at a time.
25. Consider a file called ‘str.txt’ which consists of collection of sentences. Construct a Python program to
read the file and find the word frequency of the words which are palindrome whose minimum length is
4. Note: Don’t use String inbuilt functions.
Files:
26. Construct two language sets, such that the first language set consists of English alphabets from ‘a’ to ‘m’
both inclusive and the second language consists of English alphabets from ‘N’ to ‘Z’ both inclusive. You
are given a file named “Vocabulary.txt”, which consists of 10 lines, each line with a sentence as sequence
of K words. Construct a python program that takes filename as input and find the number of valid
sentences from the file. A sentence will be a valid only if each word of the sentence contains only
characters from one of the language sets, but different words may come from different language sets.
27. Given two files “Binary.txt” and “Decimal.txt” where Binary.txt file consist of 100 binary numbers and
Decimal.txt consists of 100 decimal numbers. Construct a python program to find whether for each
binary number in Binary.txt there exists a corresponding Decimal number in Decimal.txt and print the
total number of matches found.
28. Given a file “Input_String.txt” which consists of a string S of length N. Modify the sting for K in steps such
that in step-1, reverse the prefix of length 1, in step-2, reverse the prefix of length 2 and in step-i, reverse
the prefix of length i and so on. Example:
S=abferty and K=4
Step-1: S=abferty
Step-2: S=baferty (reversed ab to ba)
Step-3: S=faberty (reversed baf to fab)
Step-4: S=ebafrty(reversed fabe to ebaf)
Construct a python code that takes file name and an integer K as inputs and modify the string for K steps
while writing the modified string in each step to another file “Reverse.txt”.
29. A file “Students.txt” consists of details of 2000 students which has student name, rollnumber, age and
year of admission. Construct a python program that read names of students from Students.txt file and
whenever you encounter the first vowel {a,e,i,ou} in name, reverse the entire substring that came before
the vowel and print all the names after doing the reversing on the output screen.
30. Given a file “Numbers.txt” which consists of 100 unsorted integers one in each line. Construct a python
code that reads the every 5th integer and let it be X from the file Numbers.txt and replace it with 1 if
GCD(X,R)=1 and 0 otherwise. Where R is randomly generated number from 1 to 100.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy