Problem 1: Write a program that takes a positive integer as input and prints its factorial. Write two separate functions, one that computes the factorial iteratively, and the other recursively. Problem 2: Write a program to print the first n Fibonacci numbers. Write separate iterative and recursive versions. Which version do you suspect is more efficient ? Why ? Problem 3: Write a program that tests if a number is prime or not. Input a number from the user. The output should be ‘True’ if the number is a prime, ‘False’ otherwise. Problem 4: Write a program to sort a list of integers using Insertion sort, Mergesort and Quicksort. First take as input the size ‘n’ of the array, then read in the ‘n’ input integers that need to be sorted. Problem 5: Devise an experiment to verify that the runtime of the list index operator is indeed O(1), You might want to read sections 3.5 and 3.6 of Miller and Ranum’s online book.
Devise an experiment to verify that the runtime of the list index operator is indeed O(1), You might want to read sections 3.5 and 3.6 of Miller and Ranum’s online book.
Write a program to sort a list of integers using Insertion sort, Mergesort and Quicksort. First take as input the size ‘n’ of the array, then read in the ‘n’ input integers that need to be sorted.
Write a program that tests if a number is prime or not. Input a number from the user. The output should be ‘True’ if the number is a prime, ‘False’ otherwise.
Write a program to print the first n Fibonacci numbers. Write separate iterative and recursive versions. Which version do you suspect is more efficient ? Why ?
Write a program that takes a positive integer as input and prints its factorial. Write two separate functions, one that computes the factorial iteratively, and the other recursively.
String &Regular Expressions
Write a python script to take two string S1 and S2 and do the following:
Check S1 and S2 are anagrams or not.
Check S1 is Sub string of S2 or not.
S1 is palindrome or not
Imagine a collection of nuts and bolts that are all together in one pile on a table. Describe, in pseudocode, how you would find all matching pairs of nuts and bolts. You need to find one solution for each of the problem-solving approaches given below. For each of your solution, determine how many comparisons of pairs of nuts and bolts you might have to make in the best- and worst- case scenario. You can assume that there are complete pairs, no single nuts or bolts, and that for each bolt, there is exactly one nut that fits. Describe a solution to the nuts and bolts problem (in pseudocode) using a Divide and Conquer Approach.
Imagine a collection of nuts and bolts that are all together in one pile on a table. Describe, in pseudocode, how you would find all matching pairs of nuts and bolts. You need to find one solution for each of the problem-solving approaches given below. For each of your solution, determine how many comparisons of pairs of nuts and bolts you might have to make in the best- and worst- case scenario. You can assume that there are complete pairs, no single nuts or bolts, and that for each bolt, there is exactly one nut that fits. Describe a solution to the nuts and bolts problem (in pseudocode) using a Brute Force Approach.
a) Write a program using functions to imitate a university canteen ticketing system. A student is required to enter their registration number and pin to access the food menu and make payments. Also a student is allowed to enter only two times a wrong pin before account is blocked.
b) Demonstrate using functions to calculate the area and perimeter as right angled triangle. Given that the perimeter of a triangle is the sum of all three sides and the hypotenuse of a triangle is obtained by sqtr((len * len)+(height * height)) where sqtr() is in a built-in function.