Programming, Data Structures and Algorithms using Python | Week 1

Session: JULY-DEC 2024

Course name: Programming, Data Structures and Algorithms using Python

Course Link: Click Here

For answers or latest updates join our telegram channel: Click here to join

These are Programming Data Structures and Algorithms using Python Week 1 Nptel Assignment 1 Answers


Q1. What does h(27993) return for the following function definition?
def h(x):
(d,n) = (1,0)
while d <= x:
(d,n) = (d*3,n+1)
return(n)

Answer:10


Q2.What is g(60) – g(48), given the definition of g below?
def g(n):
s=0
for i in range(2,n):
if n%i == 0:
s = s+1
return(s)

Answer: 2


For answers or latest updates join our telegram channel: Click here to join

These are Programming Data Structures and Algorithms using Python Week 1 Nptel Assignment 1 Answers


Q3. Consider the following function f.
def f(n):
s=0
for i in range(1,n+1):
if n//i == i and n%i == 0:
s = 1
return(s%2 == 1)
The function f(n) given above returns True for a positive number n if and only if:

n is an odd number.
n is a prime number.
n is a perfect square.
n is a composite number.

Answer: n is a perfect square


Q4. Consider the following function foo.
def foo(m):
if m == 0:
return(0)
else:
return(m+foo(m-1))
Which of the following is correct?

The function always terminates with foo(n) = factorial of n
The function always terminates with foo(n) = n(n+1)/2
The function terminates for non­negative n with foo(n) = factorial of n
The function terminates for non­negative n with foo(n) = n(n+1)/2

Answer: The function terminates for non­negative n with foo(n) = n(n+1)/2


For answers or latest updates join our telegram channel: Click here to join

These are Programming Data Structures and Algorithms using Python Week 1 Nptel Assignment 1 Answers

See also  Programming DSA using Python Nptel Week 4 Assignment Answers

Programming, Data Structures and Algorithms using Python NPTEL All weeks: Click Here

More Nptel Courses: https://progiez.com/nptel-assignment-answers


These are Programming Data Structures and Algorithms using Python Week 1 Nptel Assignment 1 Answers