// Anna University, Chennai / 2020
Anna University — Problem Solving and Python Programming (GE8151), November/December 2020
Problem Solving and Python Programming · GE8151 · R2017 · B.E./B.Tech. Engineering (common paper) · Semester 1
Files open in a new tab. Use your browser's download or save option to keep a copy.
Work through the questions
15 questions
No verified answers are available for this paper.
What factors are used to judge the quality of algorithms?
No verified answer or solution is available for this question.
What is control flow? List and define the ways in which control is executed.
No verified answer or solution is available for this question.
Define expression.
No verified answer or solution is available for this question.
Write a Python program to exchange the values of two numbers without using a temporary variable.
No verified answer or solution is available for this question.
Define a string slice. Give an example.
No verified answer or solution is available for this question.
Given an array of n elements, write a function to search for a given element x in the array.
No verified answer or solution is available for this question.
What is cloning a list? Give an example.
No verified answer or solution is available for this question.
What is the difference between a list and a tuple in Python?
No verified answer or solution is available for this question.
What are packages? How do you import modules from a package?
No verified answer or solution is available for this question.
How will you update the contents of one file to another file in Python?
No verified answer or solution is available for this question.
(a) (i) Explain the strategies for developing algorithms with an example. (10 marks) (ii) Write an algorithm for the Towers of Hanoi problem. (6 marks) (OR) (b) Explain the process of algorithm design and analysis. (8 + 8 marks)
No verified answer or solution is available for this question.
(a) (i) Explain the order of evaluation when an expression contains more than one operator. (8 marks) (ii) Differentiate parameters and arguments. Explain how to pass arguments to a function with a suitable example. (4 + 4 marks) (OR) (b) Define various methods and functions in Python. Differentiate them with an example. (8 + 8 marks)
No verified answer or solution is available for this question.
(a) (i) Describe fruitful and void functions with examples. (4 + 4 marks) (ii) There are two sorted arrays A and B of size n each. Write an algorithm to find the median after merging them into an array of length 2n. (8 marks) (OR) (b) (i) Write a recursive implementation of binary search. (8 marks) (ii) What are immutable strings? For the sentence "Chennai Anna University", sort the words in ascending order. (8 marks)
No verified answer or solution is available for this question.
(a) (i) Write nested_sum, which adds all integers from the nested lists, and cumsum, which takes a list of numbers and returns the cumulative sum list. Its ith element equals the sum of the first i + 1 elements of the input. (5 + 5 marks) (ii) Take dictionaries d1 and d2 and return a new dictionary containing all keys from d1 that are absent from d2. (6 marks) (OR) (b) (i) Write is_sorted, which returns True if a list is sorted in ascending order and False otherwise, and has_duplicates, which returns True if any element appears more than once. The original list should be preserved. (8 marks) (ii) Write a function that takes a histogram, returns a list of word-frequency tuples and prints the ten most common words. (8 marks)
No verified answer or solution is available for this question.
(a) (i) Write a program that reads a file and builds a histogram of the words in the file. (8 marks) (ii) Print all numbers in a text file and the number of blank spaces in it. (8 marks) (OR) (b) (i) Write a function called sed that takes a pattern string, a replacement string and two filenames. Read the first file and write the contents to the second, creating it if necessary. Replace every occurrence of the pattern with the replacement. If opening, reading, writing or closing fails, catch the exception, print an error message and exit. (8 marks) (ii) Explain how to read or process command line arguments in Python, with an example. (8 marks)
No verified answer or solution is available for this question.