NPTEL Week 3: Functions and Program Running Time Assignments Solution

Solution of assignment  of week 3 Online course conduct by  NPTEL on Programming, Data Structures and Algorithms

Functions and Program Running Time


NPTEL Palindrome Checker

Write a program which takes a string as input and prints the longest prefix of the string whose reverse is a valid suffix of the string. For example, if "notation" is given as input, the prefix "no" is the longest prefix that has a matching valid suffix (namely "on") at the end.

NPTEL Evaluating a Recurrence Relation

A recurrence relation T is defined on n >= 0 and is given as T(n) = T(n-1) + 2*n with the base case T(0) = 1. You will be given one integer k and you have to write a program to find out T(k). The program must implement T( ) recursively.

NPTEL Evaluating a Polynomial

You are given a polynomial of degree n. The polynomial is of the form P(x) = anxn + an-1xn-1 + … + a0, where the ai‘s are the coefficients.  Given an integer x, write a program that will evaluate P(x).


You are provided with a function named power( ) that takes two positive integers x & y and returns xy. If y is 0, the function returns 1.


The prototype of this function is

NPTEL Count pairs such that x^y > y^x

Given a  sequence A of N positive integers, write a program to find the number of pairs (A[i], A[j]) such that i < j and A[i]A[j] > A[j]A[i] (A[i] raised to the power A[j] > A[j] raised to the power A[i]).
You are provided with a function named power( ) that takes two positive integers x & y and returns xy. If y is 0, the function returns 1.

The prototype of this function is
int power(int x, int y);

You do not have to write the program for power ( ) function. This function is automatically added at the end of the code segment that you write.

In your program, use this function to count the number of such pairs.

NPTEL Week 3 on Functions and Program Running Time

Assessment 3 on Functions and Program Running Time

Share