0% found this document useful (0 votes)
6 views

Old Question DSA Using Python (1)

Uploaded by

kumar.pawan2005g
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Old Question DSA Using Python (1)

Uploaded by

kumar.pawan2005g
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 126

Uploaded by youtube.

com/c/getpythoncode
Contact me at [email protected]
Telegram id - @AK4Gp
Uploaded by youtube.com/c/getpythoncode
Contact me at [email protected]
Telegram id - @AK4Gp
Your last recorded submission was on
All questions carry
2020-01-28, 21:09 IST
equalweightage.
Al Python
aline final submission will be
raded
code is assumed to be executed using
Python3. You may submit as many times as B
you
1) What is the value of f(4000) for the function
below/?

def f(x):
d
while x > 1:
(x,d)(x/5,d+1)
hon return(d)

2) What is h(36) -h(34). given the deinition of n


balov
thve
sorting
def h(n)
9
forin range(2,n
f i - - 0:

ceturn()
6

2) What is h(36)-h(34), given the definition of h


elow?
ting
def h{n):

for i in range(2,n):
if n%i == 0:
s S+i

return(s)

35

3) For what value of n would g(637,n) return 4? If there are multiple possibilities. write any one

def g(m,n):
res 0
uhile m n:
(res,m)-(res+1,m/n)
returnres)
35

3) For what value of n would g(637,n) return 4? If there are mutiple possiblities, write any one

def g(m, n):


res e
while m >= n:
(res,m) (res+1,m/n)
return(res)

4) Considerthe following function

def nys(m):
if m 1:
return(1
else:
return(mmys (n-1))
5

4) Consider the followving functionf:

def mys(m):
f m 1:
return(1)
else:
return(m+my's (m-1))

Which of the following is correct?

The function always termin ates with mys(n) = factorial of n


The function always terminates with mys(n)= 1+2+ +n
The function terminates for positive n with mys(n) = factorial of n
*
The function terminates for
postive nvith mys(0)= 1-2
Youmay submitany number of times before the due date The final submission will be considered for grading
SubmitAnswers
I f the question asks about a value of
type string, remember to enclose your answer in single or double quotes
I f the question asks about a value of
type list, remember to enclose your answer in square brackets and use commas to separate list items
1) One of the following 10 statements generates an error Which one? (Your answer should be a number between 1 and 10)

x
[1,"abcd",, "efgh",[3,4]] * Statement 1
y x[®:6] #Statement
#Statement 3
wy # Statement
x[1] x[1][0:3] *d # Statement
y[2] = 4
#Statement
z[1][1:3] 'yzw' # Statement
# Statement 8
w[41[e] = 1000 #Statement 9
a (x[4][1] == 4) # Statement 10

25po-
2) Consider the following lines of Python code 25 po

[423, 'b',37, 'f'


u x[1:]

u u[0:
Statement
z[e] e #Statement 8
w[4][e] 1000 # Statement 9
a-(x[4][1] - 4) # Statement 10

7
2) Consider the following lines of Python code

x
=[423, 'b',37, 'f*]
u x[1:]

u uf0:]
u[1] 5 3
x[2] 4 7

After these execute which of the following is correct?


x{2) = 47. y[1] == 37, 47 ul1] == 53
w[2]
x[2= 47. yl1)== 53 w[2] == 47. u[1) == 53

x2]-
x/2]
47 y[1) 37, w2]
==
37 ul1] 53
==

47 yl1) == 53 w[2]= 37 uf1]=s 53


==

3) What is the value of second after executing the following lines?


After these execute, which of the following is correct?

x[2] 4 7 . yl1] ==
37,w2]= 47. uf1==53
x{2]==47, y[1]== 53, w2]= 47, ul[1]= 53
O 37, u[1] 53
x2]== 47. y[1] =37, w[2]=
==

37, ul1) 53
x2 47. yl1)== 53, w2]
= == ==

3) What is the value of second after executing the following lines?

first = "tarantula"
Second = ""

for i in range(len (first) -1,-1, -1):


second first[i] +second

tarantula

What is the value of list1 after the following lines are executed?
4)

def mystery(l) :

1 1[0:5]
return()
for i in range(len (first) -1,-1,-1):
second first[i] + second

tarantula

4) What is the value bf list1 ater the following lines are executed?

def mystery(1) :
1 1[e:5]
return(

list1
[44,71,12,8, 23, 17, 16]
mystery(list1)

144.71.12.8.23.17.16]
2
You maysubmit any number of times before the due date The final submission will be considered for grading
Submit Answers
Course All questions cary equal weightage Al Python code is assumed to be executed
outline using Python3 You may submt as many times as you like within the deadine Your
final submission wll be graded
How does an Note
NPTEL online f the question asks about a value of type string. remember to endose your
course work? answer in single or double quotes
. the question asks about a value of type 1ist, remember to encdose your
Week 1: answer in square brackets and use commas to separate list items
Introduction
1Consider the fotlowing Python funcsion
Week 1 Quiz

Week 2: stery(1,v):
i f len(1) 0 :
Basics of
eturn (v)
Pythe n
else:

Week 2 Quiz return (mystery(1[: -1],it-1]+v))

Week 2
What does-ystery([ 2, 14, 19,65,82,55],1) retuan?
Programming
Assignment
2.5 points
Week 3:
Lists, 2)Whatisthe value of triples ofter the following esignment?
inductive
for
function triples [ (x.y,)
in range (5,7) if 2*xy> 3°z
for x in
range(2,4)
]
for y in
range(2,5)
definitions,
sorting

Week 3 2.5 points

seEECsr(OATTthetoloing detonay 2.5 points


Python 8.1 (tags/v3.8.1:1b293D6, Dec 18 2019, 22:39:24) [MSC v.1916 32 bit (Intel)) on win32

oninecourses.nptel.acin/noc20_cs26/unit?unit = 968assessme. Type "hels", "copyright", "credits" or 1icense" for nore informat ion.
>> def m y s t e r y , v )
ii Apps Downioads Giraffe Academy ython for Web De. Development Guid if len(1) * 8:
return (v)

Course
Assignment not submitted Due date: 202002-26. 23:591ST.
Al questions carry equal weightage All Python code is assumed to be executed
else:
return (ystery(1[ i -1],1[-1]+v))
outline using Python3 You may submt as many times as you like within the deadine Your
final submission wl be graded »ystery( (22, 14,19,65,82,55), 1)
File "<stdin>", 1ine 1
How does an Note ystery ((22,14,19,65, 82, 55], 1)
NPTEL online .H the queeston asks about a value of type string. remember to endose your tndentat ionE rror: unexpected indent
course work? answer in singe or double quotes >> =ystery((22,14,19,65,82,55),1)
H the question asks about a value of type list. remember to encdose your 258

Week 1 answer in square brackets and use commas to separate list tems
Introduction
1)Consider the following Python functon
Week 1 Quiz

Week 2: def mystery(1,v):


Besics of if len(1) 0 :
return (v)
Python
else
Week 2 Qulz return (mystery (1[ -1],if-1]*v))

Week 2
What doesystery([22, 14, 19, 65,82,55].1) retun?
Programming
Assignment 258
2.5 points
Week 3:
Lists 2yWhat is the value of triples sfter the following *ssignnent?
inductive
function riples y.z) for x in range(2,4) for y in range(2,5 for
definitions. n range(5,7) if 2x'y >3
sorting

Week 3 2.5 points

sESEsr(OATetetotowngdcionary 2.5 points


Python 3.8.1 Dec 18 2019, 22:39:24) [MSC v.1916 32 bit (Intel)] win32
ags/v3.8.1:1b293b6, on

E> C 0 (aoninecourses.nptelacin/noc20_cs26/unit?unit=96&assessme.. Type help", "copyright",


»» def mystery(,v):
"credits" or "1icense" for more infornat
ion.
Apps £ Downioads Graffe Academy Pyhon for Web De Development Guid **
if len(1 ) * ®:

return (v)
Week TQuz else:
return (mystery (1[ : -1],i[-1]+v))
Week 2: def mystery(1,v):
Besics of if len(1) 0 : ystery([22, 14, 19,65,82, 55), 1)
FEle <stdin>", 1ine 1
return (v)
Python ystery([22, 14,19, 65,82,55),1)
else:

Week 2 Quiz return (mystery (1[: -1],1[-1]*v)) Indentat ionError:


unexpected indent
3>> mystery([22,14,19,65,82,55], )
258
Week 2
What doesystery( [22, 14,19,6,82,55] .1) rotu? >triples -
t (x,y,:) for x in
range(2,4) for y in range(2,5) for z in range(5,7) if 2*x*y

Programming >> triples


Assignment 258 2, 4, 5), (3, 3, 5), (3, 4, 5), (3, 4, 6)1
2.5 points
Week 3:
Lists, 2)What is the value of triples ofter the following assignaent?
inductive
function triples (x,y,z)
for
in range(S,7) if 2°x"y
x in
3°: 1
range(2,4) for y in
range(2,5) for
definitions,
sorting
3 3.5)(3. 4 5) (3.4.6)
Week 3 2.5 points
Programming
Assignment 3)Consider the folowing dictionary 2.5 points

Week 4:
runs
(Test": ("Rahul": [90, 14,35],"xohli":[103,73,42],"Pujar
Sorting. :[53,15,133,8]), "o01:("Sharms":(37,99],"Kohli:[63,47]))
Tuples,
Dictionaries, Which of the folowing statements does not generate an eror?
Passing
Functions, Oruns["00r"]("Rahul"].append([74])
List Oruns["o01"]("Rahul"].extend([74])
Comprehension Oruns( "o0r"|["Rehul"]to]-74
Oruns[ "o01"]["Rahul"]-174]
2.5 points
Python 3.8.1 (tags/V3. 8.1:1b293b6, Dec 18 2019,, 22:39:24) [MSC v.1916 32 bit (Intel)] on win32

C O i onlinecourses.nptel.acin/noc20_cs26/unit?unit=96&assessme. Type "help", "copyright", "credits" or "1icense" for more infornat íon.
» d e f mystery(,v):
i Apps Downloads Girafe Academy yhon for Web De Development Guid if len(1) * 8:
return (v)
2.5 points else:
Programming return (mystery(1[ : -1],1f-11+v))
Assignment 3)Consider the folowing dictionary 25 points

runs Test": {"Rahul": [90,14,3s],"Kohli":[3,103,73,42],"Pujar »ystery([22,14,19,65,


FEle <stain>", 1ine 1
82,55), 1)
Week 4:
Sorting.
a[53,15, 133,s)), "oo1": ("Shanres": [37,9], "kohli": [63,47])) ystery ([22,14,19,65, 82, 55], 1)
Tuples. Indentat ionE rror:
unexpect ed indent
Which of the folowing statements does not generate an emor?
Dictionaries. ystery([22, 14,19,65,82,55), 1)
258
Passing O runs["CO1"i["Rabul"].eopend([74]) >»» triples t (x,y,z) for x in range (2,4) for y in range(2,5) for in range(5,7) if 2*x*y
Functions.
3>»»
List
Oruns( "00r"]["Rahul"].extend([74]) triples

Comprehension
runs["o1"]["Rahul"ito]-74 >»
(2, 4, 5), (3, 3, 5), (3, 4, 5), (3, 4, 6)1
runsTest: (Rauiiso,14,35),*konii":[3, 103,73,42],"Pujara":[53, 15,13,8)),"001":("s
h a r m a " : [ 3 7 , 9 9 ] ." K o h l i : [63,47])}

Week 4 Quiz runs[ "c0r"]("Rabul"]-[74) > runs[0O1 ]("Rahul") -

append([74])
raceback (most recent call last):
4JAs ume that actor has been initlalzed as an empty dictionary 2.5 points
Quiz File stdin>", 1ine 1, in <module>
Keytrror: "Rahul"
Week 4
>> runs[°00I](*Rahul").extend( [74])
Qutz actomm( Traceback (most recent
File "<stdin>", line 1, in <module>
cal1 last):
Week 4 Keytrror : 'Rahul
Which of the folowing generates an eTor ? >»» runs["c01*]["Rahul"][®]-74
Programming
Assignment
Traceback (most recent call last)
File "<stdin>", line 1, in <module>
O sctor["star ["Rey","Ridley"]
ars"] -

Keytrror: "Rahul'

Text O actor["star Hars, Rey"] "Ridley" runs[0OI"]("Rahul "]-[74)


Transcripts O actor[[star Hers", "Rey"]] "Ridley"
Books
O
actort("star ars", "Rey"))- "Ridley"
You may submit any number of tmes before the due date The fnal submission will
Downloed beconsideredfor grading
Videos Submit Answers

SCHEENCAST(MTI
Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019,
O g r d m i n g , Data structure

license" for more information.


onlinecourses.nptel.ac.in/noc20_cs26/unit?unit =96&assessme.. Type "help", "copyright", "credits" or

>>> def mystery(,V):


Web De.. Development Guid.. if len(1) 08:
i Apps Downloads
nd Giraffe Academy Python for return (v)
2.5 points else:
Programming return (mystery (1[: -1j,1[-1]+v))
3)Consider the following dictionary 2.5 points
Assignment
>»»mystery([22,14,19,65,
File "<stdin>", line 1
82, 55 ],1)
runs {"Test " : {"Rahul": [90, 14,35],"Kohli": [3,103,73,42], "Pujar
Week 4: mystery([22,14, 19,65, 82, 55),1)
a":[53,15,133, 8]},"0DI" : {"Sharma": [37,99], "Kohli": [63,47]}}
Sorting, IndentationError: unexpected indent
Tuples, 1)
Dictionaries, Which of the following statements does not generate an eror? >>mystery([22,14,19,65, 82, 55],
258
Passing O runs["00I"]["Rahul"].append([ 74]) »» triples -t (x,y,z) for x in
range (2,4) for y in
range (2, 5) for
z in range(5,7) if 2*x*y
Functions, 3*z 1
List
Comprehension
Oruns["00I"]("Rahul"].extend([74] >>» triples
t(2, 4, 5),(3, 3, 5), (3, 4, 5), (3, 4,"Kohli"
6)1
Oruns[ "ODI"]["Rahul"][®]=74
>> runs Test":(Rahul": (98,14, 35],
: (3, 103,73,42], "Pujara": [53, 15, 133,8]) ,
"ooI :{"s

Week 4 Quiz runs[ "oOI"]["Rahul"]-[74] harma":[37,99],"Kohli":[63,47]}}


>>> runs["0DI"]["Rahul"].append([74]1)
4)Assume that actor has been initialized as an empty dictionary 2.5 points Traceback (most recent call last):
File "<stdin>", 1ine 1, in <module>
Quiz
Week 4 KeyError: "Rahul
Quiz > runs["0DI"]["Rahul"].extend( [74])
actor { } Traceback (most recent call last):
File "<stdin>", 1ine 1, in <module>
Week 4 KeyError: "Rahul'
Programming Which of the following generates an eror? >> runs[ "ODI"]["Rahul"][®]-74
Traceback (most recent call last):
Assignment File "<stdin>", 1ine 1, in <module>
Oactor["star Wars"] ["Rey", "Ridley"]1
-

KeyError: 'Rahul"
Text O actor["Star Hars, Rey"] "Ridley" >
runs["ODI"][ "Rahul"]-[74]
Transcripts >>> actor {
actor[["star Wars", "Rey"]] "Ridley" >actor["Star Wars"] ["Rey", "Ridley"]
O actor[("Star ars", "Rey")] = "Ridley"
Books actor["Star Wars, Rey"] "Ridley"
>>

>>» actor[["Star Wars", "Rey"]] "Ridley"


You may submit any number of times before the due date The final subrmission will
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
Download be consideredfor grading9 unhashable 'list'type:
Videos TypeError:
SubmitAnwers >actort("star Hars", "Rey")1 "Ridley

SeEECAsOwaT
NPTEL Programming.
DataStructuesAndAlgorithmsUsing Python Announcements About the Course Ask a Question Progress Mentor

Unit 15-Week 6 Quiz

Course outline
Week 6 Quiz
How does an NPTEL online
course work? Your last recorded submission was on 2020-03-10, 08:35 IST Due date: 2020-03-11, 23:59 IST.
All questions carry equal weightage. All Python code is assumed to be executed using Python3. You may submit as many times as you like within the deadline.

Week 1: Introduction Your final submission will be graded.


Note

Week 1 Quiz I f the question asks about a value of type string. remember to enclose your answer in singte or doutble quotes.
If the question asks about a value of type list. remember to enciose your answer in square brackets and use commas to separate list items
Week 2: Basics of Python u? 2.5 point
1) Suppose u and v both denote sets in Python. Under what conditon can we guarantee that u-(v-u)

Week 2 Quiz O The sets u and v should be disjoint.


The set u should be a subset ofthe set v
Week 2 Programmingg
Assignment
OThe set v should be a subset ofthe set u

This is true for any u and v.

sts WIT ingeYAIC ulv != u'v. Wnat can we conclude about u and v? 2.5 point
2) Suppose u and v both denote sets in Python. and
Week 1: Introduction Your final submission ill be graded
Note
Week 1 Quiz .If the question asks about a value of type string. remember to enclose your answer in single or double quotes.
I f the question asks about a value of type list. remember to enclose your answer in square brackets and use commas to separate list items.
Week 2: Basics of Python
Suppose uand vboth denote setsin Python Unde hat condition can we guarantee that u-(v-u) -- u? 2.5 point

Week 2 Quiz The sets u and v shoutd be disjoint.


The set u should be a subset ofthe set v
Week 2 Programming
The set v shoutd be a subset of the set u
Assignment
This is true for any u and v.

Week 3: Lists, inductive


function definitions, sorting 2) Suppose u and v both denote sets in Python. and ulv !- utv. What can we conclude about u and v? 2.5 point

Week 3 Programming
The sets u and v should overlap
The set v should be a subset ofthe set u.
Assignment
The set u should be a subset ofthe set v.
Week 4: Sorting, Tuples, This is true for any u and v.
Dictionaries, Passing
Functions, List 3) Which ofthe following does not correspond to a min-heap on the list of values [19.97,83.45.72.55.31,28.31.29] 2.5 point-
Comprehension
O[19, 28, 72. 31, 29,83, 97, 55, 45, 31]
Week 4 Quiz O[19, 31, 28, 45, 31. 97, 29, 72, 55, 83]
O[19, 28, 29, 31, 31, 45, 55, 72, 83, 97
HPam MATIC
SSäEkASTO) MATIe [19, 28, 29, 31, 45. 83, 97, 55, 72. 31]
The set v should be a subset of the setu
Assignment
This is true for any u and v.

Week 3: Lists, inductive


function definitions, sorting 2) Suppose u and v both denote sets in Python and
u!= u^v. What can we conclude about uand v? 2.5 point=
The sets u and v should overlap
Week 3 Programming9
The setv should be
Assignment a subset of the set u.

The set u should be a subset of the set v.

Week 4: Sorting, Tuples, This is true for any u and v.


Dictionaries, Passing
Functions, List 3) Which of the following does not correspond to a min-heap on the list of values
[19.97.83.45.72.55.31.28.31,29] 2.5 point
Comprehension
O[19, 28, 72, 31, 29, 83, 97, 55, 45, 31]
Week 4 Quiz [19, 31, 28, 45, 31, 97, 29, 72, 55, 83]
[19, 28, 29, 31, 31, 45, 55, 72. 83, 97
Week 4 Programming
[19, 28, 29, 31, 45, 83, 97, 55, 72, 31]
Assignment
4) Considerthe min-heap (19, 28, 31, 31, 29, 83, 55, 97, 45. 72) Suppose we apply the operation delete_nin() to this min-heap The resulting min- 2.5 point
Week 5: Exception handling heap is
inputoutput, file handling,
string processing O (28, 29, 31. 31, 97, 83. 55, 72. 45]
[28, 29, 31, 31, 72, 83, 55, 97, 45]
Week 6 Programming
Assignment f28,29, 31. 31, 83, 72, 55, 97, 45]
[28, 29, 31. 31, 55, 83. 72. 97, 45]

You may submit any number of times before the due date. The final submission will be considered for grading.
week 2 Quiz
1) Given the following permutation of a.b.c.d.e.f.g.h.ij, what is the previous permutation in lexicographic (dictionary) order? Write your answer without any blank
Week 2 Programming spaces between letters.
Assignment
fjadchbegi
Week 3: Lists, inductive
function definitions, sorting
Jadcaihet
Week 3 Programming 2.5 points
Assignment
2) Assume we have defined a class Node that implements user defined lists of numbers. Each object node of type Node has two attributes node. value 2.5 points
Week 4: and node.next with the usual interpretation. We want to add a function sum) to the class Node which will compute the sum of values in the list. An incomplete
Sorting. Tuples,
Dictionaries, Passing implementation of sum() given below. Wnat should be put in place of X*X and YYY?
Functions, List def sum(self):
Comprehension if self.value -= None:

return(e)
Week 4 Quiz
elif self.next None:t
return(Xx)
Week 4 Programming
else:
Assignment return(YY)
Week 5: Exception handling,
inputoutput, file handling, Replace *xX by 1 and YYY by 1 +selfnext.sum()
string processing O Replace XXX by 1 and YYY by self.value+ setf.next sum()
Replace XXX by self.value and YYY by 1 + self next sum()
49RP5jtammiag Replacexxx by self.value and YYY by selfvalue + setf.next sum()
SSs33ASTOMATI
course work?
Week 7 Quiz
Week 1:Introduction Your last recorded submission was on 2020-03-18, 13:37 IST Due date: 2020-03-18, 23:59 IST.
cary equal weightage. All Python code is assumed to be executed using Python3. You may submit
Week 1 Quiz All questions
Your final submission will be graded
as many times as you like within the deadline.

Week 2: Basics of Python


Note
I f the question asks about a value of type string. remember to enclose your answer in single or double
I f the question asks about a value of type list, remember to enclose your answer in square brackets and
quotes
Week 2 Quiz use commas to separate list tems
1) Gven the tlowing permutation of a.b.c.d.e..g.hij, what is the previous permutation in lexicographic (dictionary) order? Wnte your answer without any blank
Week 2 Programming spaces between lettersl
Assignment

Week 3: Lists, inductive


fjadchbegi
function definitions, sorting

Week 3 Programming
Tjadcgiheb
2.5 point
Assignment
2) Assume we have defined a class Node that implements user defined lists of numbers. Each object node of type Node has two attributes node value 2.5 point
Week 4: and node.next with the usualinterpretationWe want to add a tunction sum0 to the class Node which will compute the sum of values in the list. An incomplete
Sorting, Tuples,
Dictionaries, Passing implementation of sum() given below. What should be put in place of XXX and YYY?
Functions, List
def sun(self) :
Comprehension if self. value None
return(e)
elif self.next -- None:
SCREENCAST MATI return(XXx)
Week 3 Programming
Tiadcaihet
Assignment 2.5 point
2) Assume we have defined a class Node that implements user defined lists of numbers. Each
object node of type Node has two attributes node.value 2.5 point
Week 4: and node.next with the usual interpretation. We want to add a function
Sorting, Tuples, sum() to the class Node which will compute the sum of values in the list. An incompletee
Dictionaries, Passing
Functions, List
implementation of sum) gven below What should be put in place of Xox and YYY?
def sum(self) :
Comprehension if self.value None:

Week 4 Quiz
return(e)
elif self.next -=
None
return(Xx)
Week 4 Programming9
else:
Assignment
return(YY)
Week 5: Exception handling,
inputoutput, file handling. ReplaceXXXX by 1 and YXby 1+sef.nextsumo
string processing Replace xxx by 1 and YYby seltvalue+sett.next.sumo
ReplaceXXX by seif.value andYYY by 1+self.nextsum)
Week 5 Programming Replace XXX by sef.value and YYY by setf.value+ sett.next.sum)
Assignment
3) Suppose we add this function foo() to the class Tree that implements search trees. For a name mytree with a value of type Tree, what would 2.5 point=
Week 6: Backtracking, scope,
mytree.foo() compute?
data structures; stacks,
queues and heaps
def foo(self) :
if self.isempty () :
s NASr (OMATIE return(0)
Replace XXX by self.value and YYY by 1 +setf.next.sum()
Week 5 Programming Replace XXX by self.value and YYY by self.value+ self.next.sum()
Assignment
3) Suppose we add this function foo() to the class Tree that implements search trees. For a name mytree with a value of type Tree. what would 2.5 poin
Week 6: Backtracking. scope,
mytree.foo() compute?
data structures; stacks,
queues and heaps
def foo(self) :
Week 6 Quiz if self.isempty () :
return(@)
elif self.isleaf() :
Week 7: Classes, objects and
user defined datatypes return(self.value)
else
Week 7 Quiz return(self.value + max(self. left.foo()
self.right.foo()))
Quiz: Week 7Quiz
Week 8: Dynamic The sum of the elements in the tree
programming, wrap-up The maximum sum across all root to leaf paths in he tree
The length ofthe longest root to leaf pah in Me tree
Week 8 Programming
Assignment
The number ofroot to leaf paths in thetree
4) The preorder traversal of a binary search tree with integer values produces the following sequence: 35, 23, 26, 46, 40, 39, 41, 52. Wnat is the value of 2.5 poi
Text Transcripts the right child of the root of the tree?
3CORDED wrA
39
SEREENCAST OMATIC
return(e0)
Week 7: Classes, objects and
elif self.isleaf () :
user defined datatypes return(self.value)
else:

Week 7 Quiz return(self.value max(self. left.foo(),


self.right.foo()))
Quiz: Week 7 Quiz

Week 8: Dynamic The sum ofthe elements in the tree


programming, wrap-up The maximum sum across all root to leaf paths in the tree
The length of the longest root to leaf path in the tree
Week 8 Programming The number of root to leaf paths in the tree.
Assignment
4) The preorder traversal of a binary search tree with integer values produces the tollowing sequence 35, 23, 26, 46, 40, 39, 41, 52 What is the value of 2.5 point
Text Transcripts the right child of the root of the tree?

Books 39
40
Download Videos 41
46
You may suumit any number of times before the due date. The final sutbmission will be considered tor grading.
Submit Answers

D E D WITA

SCREENCAST(OMATic
3/14/2021 Programming, Data Structures And Algorithms Using Python - - Unit 3 - Week 1 Quiz

(https://swayam.gov.in) (https://swayam.gov.in/nc_details/NPTEL)

[email protected]

NPTEL (https://swayam.gov.in/explorer?ncCode=NPTEL) » Programming, Data Structures And Algorithms

Using Python (course)

Course
outline Week 1 Quiz
The due date for submitting this assignment has passed.
How does an Due on 2020-09-30, 23:59 IST.
NPTEL online Score: 4/4=100%
course work?

Week 1 : Assignment submitted on 2020-09-14, 17:34 IST


Introduction All questions carry equal weightage. All Python code is assumed to be executed using Python3. You
may submit as many times as you like within the deadline. Your final submission will be graded.
Week 1 Quiz
1) What does h(19685) return for the following function definition?
Quiz : Week 1
Quiz def h(x):
(assessment? (d,n) = (1,0)
name=104) while d <= x:
(d,n) = (d*3,n+1)
Week 2: Basics
return(n)
of Python

Week 2 Quiz 10

Yes, the answer is correct.


Week 2 Score: 1
Programming Accepted Answers:
Assignment (Type: Numeric) 10

1 point
Week 3: Lists,
inductive function 2) What is g(36) - g(35), given the definition of g below?
definitions,
sorting

https://onlinecourses.nptel.ac.in/noc20_cs70/unit?unit=22&assessment=104 1/3
3/14/2021 Programming, Data Structures And Algorithms Using Python - - Unit 3 - Week 1 Quiz

def g(n):
Week 3
s=0
Programming
Assignment for i in range(2,n):
if n%i == 0:
s = s+1
Week 4: Sorting,
Tuples, return(s)
Dictionaries,
Passing 5
Functions, List
Comprehension Yes, the answer is correct.
Score: 1
Accepted Answers:
Week 4 Quiz (Type: Numeric) 5

Week 4 1 point
Programming
3) Consider the following function f. 1 point
Assignment
def f(n):
Week 5: s=0
Exception
for i in range(1,n+1):
handling,
if n//i == i and n%i == 0:
input/output, file
s = 1
handling, string
return(s%2 == 1)
processing

Week 5 The function f(n) given above returns True for a positive number n if and only if:
Programming
n is an odd number.
Assignment
n is a prime number.
Week 6: n is a perfect square.
Backtracking, n is a composite number.
scope, data
structures; Yes, the answer is correct.
Score: 1
stacks, queues
Feedback:
and heaps
f(n) sets s to 1 if there is a number i such that i*i == n.
Accepted Answers:
Week 6 Quiz
n is a perfect square.

Week 7: Classes, 4) Consider the following function fpp. 1 point


objects and user
defined def foo(m):
datatypes if m == 0:
return(0)
Week 7 Quiz else:
return(m+foo(m-1))
Week 8: Dynamic
programming, Which of the following is correct?
wrap-up
The function always terminates with f(n) = factorial of n
Week 8 The function always terminates with f(n) = n(n+1)/2
Programming

https://onlinecourses.nptel.ac.in/noc20_cs70/unit?unit=22&assessment=104 2/3
3/14/2021 Programming, Data Structures And Algorithms Using Python - - Unit 3 - Week 1 Quiz

Assignment The function terminates for nonnegative n with f(n) = factorial of n


The function terminates for nonnegative n with f(n) = n(n+1)/2
Text Transcripts
Yes, the answer is correct.
Score: 1
Books
Feedback:
If m is negative, the function does not terminate. Otherwise, it computes 1+2+..+m = m(m+1)/2.
Download Videos
Accepted Answers:
The function terminates for nonnegative n with f(n) = n(n+1)/2
Online
Programming
Test - Sample

Online
Programming
Test 1, 01 Dec
2020, 10:00-
12:00

Online
Programming
Test 2, 01 Dec
2020, 20:00-
22:00

Online
Programming
Test 1, 09 Mar
2021, 10:00-
12:00

Online
Programming
Test 2, 09 Mar
2021, 20:00-
22:00

https://onlinecourses.nptel.ac.in/noc20_cs70/unit?unit=22&assessment=104 3/3
3/14/2021 Programming, Data Structures And Algorithms Using Python - - Unit 5 - Week 2 Quiz

(https://swayam.gov.in) (https://swayam.gov.in/nc_details/NPTEL)

[email protected]

NPTEL (https://swayam.gov.in/explorer?ncCode=NPTEL) » Programming, Data Structures And Algorithms

Using Python (course)

Course
outline Week 2 Quiz
The due date for submitting this assignment has passed.
How does an Due on 2020-09-30, 23:59 IST.
NPTEL online Score: 10/10=100%
course work?

Week 1 : Assignment submitted on 2020-09-25, 18:35 IST


Introduction All questions carry equal weightage. All Python code is assumed to be executed using Python3. You
may submit as many times as you like within the deadline. Your final submission will be graded.
Week 1 Quiz Note:
If the question asks about a value of type string, remember to enclose your answer in
Week 2: Basics
single or double quotes.
of Python
If the question asks about a value of type list, remember to enclose your answer in square
brackets and use commas to separate list items.
Week 2 Quiz
1) One of the following 10 statements generates an error. Which one? (Your answer should be a
Quiz : Week 2 number between 1 and 10.)
Quiz
(assessment?
name=105)

Week 2
Programming
Assignment

Week 3: Lists,
inductive function
definitions,
sorting

https://onlinecourses.nptel.ac.in/noc20_cs70/unit?unit=31&assessment=105 1/3
3/14/2021 Programming, Data Structures And Algorithms Using Python - - Unit 5 - Week 2 Quiz

x = ["slithy",[7,10,12],2,"tove",1] # Statement 1
Week 3
y = x[0:50] # Statement 2
Programming
Assignment z = y # Statement 3
w = x # Statement 4
x[0] = x[0][:5] + 'ery' # Statement 5
Week 4: Sorting,
Tuples, y[2] = 4 # Statement 6
Dictionaries, z[4] = 42 # Statement 7
Passing w[0][:3] = 'fea' # Statement 8
Functions, List x[1][0] = 5555 # Statement 9
Comprehension a = (x[4][1] == 1) # Statement 10

Week 4 Quiz 8

Week 4 Yes, the answer is correct.


Score: 2.5
Programming
Accepted Answers:
Assignment (Type: Numeric) 8

Week 5: 2.5 points


Exception
2) Consider the following lines of Python code. 2.5 points
handling,
input/output, file
b = [23,44,87,100]
handling, string
a = b[1:]
processing
d = b[2:]
c = b
Week 5
d[0] = 97
Programming
Assignment c[2] = 77

Week 6: Which of the following holds at the end of this code?


Backtracking,
a[1] == 77, b[2] == 77, c[2] == 77, d[0] == 97
scope, data
structures; a[1] == 87, b[2] == 87, c[2] == 77, d[0] == 97
stacks, queues a[1] == 87, b[2] == 77, c[2] == 77, d[0] == 97
and heaps
a[1] == 97, b[2] == 77, c[2] == 77, d[0] == 97

Week 6 Quiz Yes, the answer is correct.


Score: 2.5
Feedback:
Week 7: Classes, a[1] == 87, b[2] == 77, c[2] == 77, d[0] == 97
objects and user
b and c refer to the same list, while a and d are two independent slices. The update to d[0] does
defined
not affect any of the other lists, but the update to c[2] is also reflected in b[2].
datatypes
Accepted Answers:
a[1] == 87, b[2] == 77, c[2] == 77, d[0] == 97
Week 7 Quiz
3) What is the value of endmsg after executing the following lines?
Week 8: Dynamic
programming, startmsg = "python"
wrap-up endmsg = ""
for i in range(1,1+len(startmsg)):
Week 8 endmsg = startmsg[-i] + endmsg
Programming

https://onlinecourses.nptel.ac.in/noc20_cs70/unit?unit=31&assessment=105 2/3
3/14/2021 Programming, Data Structures And Algorithms Using Python - - Unit 5 - Week 2 Quiz

Assignment 'python'

Text Transcripts Yes, the answer is correct.


Score: 2.5
Accepted Answers:
Books (Type: Regex Match) \s*\'python\'\s*
(Type: Regex Match) \s*\"python\"\s*
Download Videos
2.5 points
Online 4) What is the value of mylist after the following lines are executed?
Programming
Test - Sample def mystery(l):
l = l[1:]
Online return()
Programming
Test 1, 01 Dec mylist = [7,11,13]
2020, 10:00- mystery(mylist)
12:00
[7, 11, 13]
Online
Programming Yes, the answer is correct.
Test 2, 01 Dec Score: 2.5
2020, 20:00- Accepted Answers:
22:00 (Type: Regex Match) \s*\[\s*7,\s*11,\s*13\s*]\s*

2.5 points
Online
Programming
Test 1, 09 Mar
2021, 10:00-
12:00

Online
Programming
Test 2, 09 Mar
2021, 20:00-
22:00

https://onlinecourses.nptel.ac.in/noc20_cs70/unit?unit=31&assessment=105 3/3
3/14/2021 Programming, Data Structures And Algorithms Using Python - - Unit 10 - Week 4 Quiz

(https://swayam.gov.in) (https://swayam.gov.in/nc_details/NPTEL)

[email protected]

NPTEL (https://swayam.gov.in/explorer?ncCode=NPTEL) » Programming, Data Structures And Algorithms

Using Python (course)

Course
outline Week 4 Quiz
The due date for submitting this assignment has passed.
How does an Due on 2020-10-14, 23:59 IST.
NPTEL online Score: 10/10=100%
course work?

Week 1 : Assignment submitted on 2020-10-05, 13:35 IST


Introduction All questions carry equal weightage. All Python code is assumed to be executed using Python3. You
may submit as many times as you like within the deadline. Your final submission will be graded.
Week 1 Quiz Note:
If the question asks about a value of type string, remember to enclose your answer in
Week 2: Basics
single or double quotes.
of Python
If the question asks about a value of type list, remember to enclose your answer in square
brackets and use commas to separate list items.
Week 2 Quiz
1) Consider the following Python function.
Week 2
Programming def mystery(l):
Assignment if l == []:
return(l)
Week 3: Lists, else:
inductive function return(mystery(l[1:])+l[:1])
definitions,
sorting What does mystery([22,14,19,65,82,55]) return?

[55, 82, 65, 19, 14, 22]


Week 3
Programming Yes, the answer is correct.
Assignment Score: 2.5

https://onlinecourses.nptel.ac.in/noc20_cs70/unit?unit=53&assessment=108 1/3
3/14/2021 Programming, Data Structures And Algorithms Using Python - - Unit 10 - Week 4 Quiz

Accepted Answers:
Week 4: Sorting, (Type: Regex Match) [ ]*[[ ]*55[ ]*,[ ]*82[ ]*,[ ]*65[ ]*,[ ]*19[ ]*,[ ]*14[ ]*,[ ]*22[ ]*][ ]*
Tuples,
2.5 points
Dictionaries,
Passing 2) What is the value of pairs after the following assignment?
Functions, List
Comprehension pairs = [ (x,y) for x in range(4,1,-1) for y in range(5,1,-1) if (x+
y)%3 == 0 ]
Week 4 Quiz
[(4, 5), (4, 2), (3, 3), (2, 4)]
Quiz : Week 4
Quiz Yes, the answer is correct.
(assessment? Score: 2.5
name=108) Accepted Answers:
(Type: Regex Match) [ ]*[[ ]*\([ ]*4[ ]*,[ ]*5[ ]*\)[ ]*,[ ]*\([ ]*4[ ]*,[ ]*2[ ]*\)[ ]*,[ ]*\([ ]*3[ ]*,[ ]*3[ ]*\)[ ]*,[
Week 4 ]*\([ ]*2[ ]*,[ ]*4[ ]*\)[ ]*][ ]*
Programming
Assignment 2.5 points

3) Consider the following dictionary. 2.5 points


Week 5:
Exception wickets = {"Tests":{"Kumble":[3,5,2,3],"Srinath":[4,4,1,0],"Prasad":
handling, [2,1,7,4]},"ODI":{"Kumble":[2,0],"Srinath":[1,2]}}
input/output, file
handling, string Which of the following statements does not generate an error?
processing
wickets["ODI"]["Prasad"][0:] = [4,4]
Week 5 wickets["ODI"]["Prasad"].extend([4,4])
Programming
wickets["ODI"]["Prasad"] = [4,4]
Assignment
wickets["ODI"]["Prasad"] = wickets["ODI"]["Prasad"] + [4,4]
Week 6: Yes, the answer is correct.
Backtracking, Score: 2.5
scope, data Feedback:
structures; Direct assignment to a new key adds a value. All other updates result in KeyError.
stacks, queues Accepted Answers:
and heaps wickets["ODI"]["Prasad"] = [4,4]

4) Assume that hundreds has been initialized as an empty dictionary: 2.5 points
Week 6 Quiz
hundreds = {}
Week 7: Classes,
objects and user Which of the following generates an error?
defined
datatypes hundreds["Tendulkar, international"] = 100
hundreds["Tendulkar"] = {"international":100}
Week 7 Quiz
hundreds[("Tendulkar","international")] = 100
hundreds[["Tendulkar","international"]] = 100
Week 8: Dynamic
programming, Yes, the answer is correct.
wrap-up Score: 2.5
Feedback:
Week 8 Dictionary keys must be immutable values.
Programming Accepted Answers:

https://onlinecourses.nptel.ac.in/noc20_cs70/unit?unit=53&assessment=108 2/3
3/14/2021 Programming, Data Structures And Algorithms Using Python - - Unit 10 - Week 4 Quiz

Assignment hundreds[["Tendulkar","international"]] = 100

Text Transcripts

Books

Download Videos

Online
Programming
Test - Sample

Online
Programming
Test 1, 01 Dec
2020, 10:00-
12:00

Online
Programming
Test 2, 01 Dec
2020, 20:00-
22:00

Online
Programming
Test 1, 09 Mar
2021, 10:00-
12:00

Online
Programming
Test 2, 09 Mar
2021, 20:00-
22:00

https://onlinecourses.nptel.ac.in/noc20_cs70/unit?unit=53&assessment=108 3/3
3/14/2021 Programming, Data Structures And Algorithms Using Python - - Unit 15 - Week 6 Quiz

(https://swayam.gov.in) (https://swayam.gov.in/nc_details/NPTEL)

[email protected]

NPTEL (https://swayam.gov.in/explorer?ncCode=NPTEL) » Programming, Data Structures And Algorithms

Using Python (course)

Course
outline Week 6 Quiz
The due date for submitting this assignment has passed.
How does an Due on 2020-10-28, 23:59 IST.
NPTEL online Score: 7.5/10=75%
course work?

Week 1 : Assignment submitted on 2020-10-25, 13:03 IST


Introduction All questions carry equal weightage. All Python code is assumed to be executed using Python3. You
may submit as many times as you like within the deadline. Your final submission will be graded.
Week 1 Quiz Note:
If the question asks about a value of type string, remember to enclose your answer in
Week 2: Basics
single or double quotes.
of Python
If the question asks about a value of type list, remember to enclose your answer in square
brackets and use commas to separate list items.
Week 2 Quiz
1) Suppose u and v both denote sets in Python. What is the most general condition 2.5 points
Week 2 that guarantees that u - (v - u) == u?
Programming
Assignment The sets u and v should be disjoint.
The set v should be a subset of the set u.
Week 3: Lists, The set u should be a subset of the set v.
inductive function
This is true for any u and v.
definitions,
sorting Yes, the answer is correct.
Score: 2.5
Week 3 Feedback:
Programming v - u, by definition, has no elements from u. Hence u - (v - u) does not remove any
Assignment elements from u.

https://onlinecourses.nptel.ac.in/noc20_cs70/unit?unit=73&assessment=111 1/3
3/14/2021 Programming, Data Structures And Algorithms Using Python - - Unit 15 - Week 6 Quiz

Accepted Answers:
Week 4: Sorting, This is true for any u and v.
Tuples,
2) Suppose u and v both denote sets in Python. What is the most general condition 2.5 points
Dictionaries,
that guarantees that u|v == u^v?
Passing
Functions, List
The sets u and v should be disjoint.
Comprehension
The set u should be a subset of the set v.
Week 4 Quiz The set v should be a subset of the set u.
This is true for any u and v.
Week 4
Yes, the answer is correct.
Programming Score: 2.5
Assignment Feedback:
u^v has all elements that are in exactly one of u or v. This is the same as u|v - u&v. Since u^v
Week 5: = u|v, we have u&v is empty, so u and v are disjoint.
Exception Accepted Answers:
handling, The sets u and v should be disjoint.
input/output, file
handling, string 3) Suppose we insert 19 into the min heap [17,25,42,67,38,89,54,98,89]. What is the resulting
processing heap?

[17,19,42,67,25,89,54,98,8
Week 5
Programming Yes, the answer is correct.
Assignment Score: 2.5
Accepted Answers:
Week 6: (Type: Regex Match) [ ]*[[ ]*17[ ]*,[ ]*19[ ]*,[ ]*42[ ]*,[ ]*67[ ]*,[ ]*25[ ]*,[ ]*89[ ]*,[ ]*54[ ]*,[ ]*98[ ]*,[
Backtracking, ]*89[ ]*,[ ]*38[ ]*][ ]*
scope, data
2.5 points
structures;
stacks, queues 4) Suppose we execute delete-min twice on the min-heap [13,29,24,67,52,89,45,98.79,58]. What
and heaps is the resulting heap?

Week 6 Quiz [29,52,45,67,98.79,89,58]

Quiz : Week 6 No, the answer is incorrect.


Score: 0
Quiz
(assessment?
Feedback:
The original heap is:
name=111)

Week 7: Classes, 13
objects and user / \
defined 29 24
datatypes / \ / \
67 52 89 45
Week 7 Quiz / \ /
98 79 58
Week 8: Dynamic
programming, After one delete-min, we have:
wrap-up

Week 8
Programming

https://onlinecourses.nptel.ac.in/noc20_cs70/unit?unit=73&assessment=111 2/3
3/14/2021 Programming, Data Structures And Algorithms Using Python - - Unit 15 - Week 6 Quiz

Assignment
24
/ \
Text Transcripts
29 45
/ \ / \
Books
67 52 89 58
/ \
Download Videos
98 79

Online
After the second delete-min, we have:
Programming
Test - Sample
29
/ \
Online
52 45
Programming
/ \ / \
Test 1, 01 Dec
2020, 10:00- 67 79 89 58
12:00 /
98
Online
Programming Accepted Answers:
(Type: Regex Match) [ ]*[29[ ]*,[ ]*52[ ]*,[ ]*45[ ]*,[ ]*67[ ]*,[ ]*79[ ]*,[ ]*89[ ]*,[ ]*58[ ]*,[ ]*98[ ]*][ ]*
Test 2, 01 Dec
2020, 20:00- 2.5 points
22:00

Online
Programming
Test 1, 09 Mar
2021, 10:00-
12:00

Online
Programming
Test 2, 09 Mar
2021, 20:00-
22:00

https://onlinecourses.nptel.ac.in/noc20_cs70/unit?unit=73&assessment=111 3/3
3/14/2021 Programming, Data Structures And Algorithms Using Python - - Unit 17 - Week 7 Quiz

(https://swayam.gov.in) (https://swayam.gov.in/nc_details/NPTEL)

[email protected]

NPTEL (https://swayam.gov.in/explorer?ncCode=NPTEL) » Programming, Data Structures And Algorithms

Using Python (course)

Course
outline Week 7 Quiz
The due date for submitting this assignment has passed.
How does an Due on 2020-11-04, 23:59 IST.
NPTEL online Score: 7.5/10=75%
course work?

Week 1 : Assignment submitted on 2020-10-31, 16:02 IST


Introduction All questions carry equal weightage. All Python code is assumed to be executed using Python3. You
may submit as many times as you like within the deadline. Your final submission will be graded.
Week 1 Quiz Note:
If the question asks about a value of type string, remember to enclose your answer in
Week 2: Basics
single or double quotes.
of Python
If the question asks about a value of type list, remember to enclose your answer in square
brackets and use commas to separate list items.
Week 2 Quiz
1) Given the following permutation of a,b,c,d,e,f,g,h,i,j, what is the next permutation in
Week 2 lexicographic (dictionary) order? Write your answer without any blank spaces between letters.
Programming
Assignment fjadbihgec

Week 3: Lists, 'fjadcbeghi'


inductive function
definitions, Yes, the answer is correct.
Score: 2.5
sorting
Accepted Answers:
(Type: Regex Match) [ ]*fjadcbeghi[ ]*
Week 3 (Type: Regex Match) [ ]*\"fjadcbeghi\"[ ]*
Programming (Type: Regex Match) [ ]*\'fjadcbeghi\'[ ]*
Assignment

https://onlinecourses.nptel.ac.in/noc20_cs70/unit?unit=82&assessment=112 1/3
3/14/2021 Programming, Data Structures And Algorithms Using Python - - Unit 17 - Week 7 Quiz

2.5 points
Week 4: Sorting,
Tuples, 2) We want to add a function length() to the class Node that implements user defined 2.5 points
Dictionaries, lists which will compute the length of a list. An incomplete implementation of length() given below.
Passing You have to provide expressions to put in place of XXX, YYY. and ZZZ.
Functions, List
Comprehension
def length(self):
Week 4 Quiz if self.value == None:
return(XXX)
Week 4 elif self.next == None:
Programming return(YYY)
Assignment else:
return(ZZZ)
Week 5:
Exception XXX: 0, YYY: 0, ZZZ: self.next.length()
handling,
XXX: 0, YYY: 0, ZZZ: 1 + self.next.length()
input/output, file
handling, string XXX: 0, YYY: 1, ZZZ: self.next.length()
processing XXX: 0, YYY: 1, ZZZ: 1 + self.next.length()

No, the answer is incorrect.


Week 5 Score: 0
Programming Feedback:
Assignment Inductive definition: if empty, return 0, if singleton return 1, else add 1 to the length of the list
starting at self.next.
Week 6: Accepted Answers:
Backtracking, XXX: 0, YYY: 1, ZZZ: 1 + self.next.length()
scope, data
structures; 3) Suppose we add this function foo() to the class Tree that implements search trees. 2.5 points
stacks, queues For a name mytree with a value of type Tree, what would mytree.foo() compute?
and heaps
def foo(self):
Week 6 Quiz if self.isempty():
return(0)
Week 7: Classes, elif self.isleaf():
objects and user return(1)
defined else:
datatypes return(1 + max(self.left.foo(),self.right.foo()))

Week 7 Quiz The number of nodes in mytree

Quiz : Week 7 The largest value in mytree.


Quiz The length of the longest path from root to leaf in mytree.
(assessment?
The number of paths in mytree.
name=112)
Yes, the answer is correct.
Week 8: Dynamic Score: 2.5
programming, Feedback:
wrap-up This computes the height of the tree, which is the length of the longest root to leaf path.
Accepted Answers:
Week 8 The length of the longest path from root to leaf in mytree.
Programming

https://onlinecourses.nptel.ac.in/noc20_cs70/unit?unit=82&assessment=112 2/3
3/14/2021 Programming, Data Structures And Algorithms Using Python - - Unit 17 - Week 7 Quiz

Assignment 4) Inorder traversal of a binary tree has been defined in the lectures. A preorder traversal lists the
vertices of a binary tree (not necessarily a search tree) as follows:
Text Transcripts Print the root.
Print the left subtree in preorder.
Books Print the right subtree in preorder.

Suppose we have a binary tree with 10 nodes labelled a, b, c, d, e, f, g, h, i, j, with


Download Videos
preorder traversal gbhecidajf and inorder traversal ehbicgjafd. What is the right child of the root
node?
Online
Programming 'd'
Test - Sample
Hint
Online
Programming
Yes, the answer is correct.
Test 1, 01 Dec Score: 2.5
2020, 10:00-
Accepted Answers:
12:00 (Type: Regex Match) [ ]*d[ ]*
(Type: Regex Match) [ ]*"d"[ ]*
Online (Type: Regex Match) [ ]*'d'[ ]*
Programming
Test 2, 01 Dec 2.5 points
2020, 20:00-
22:00

Online
Programming
Test 1, 09 Mar
2021, 10:00-
12:00

Online
Programming
Test 2, 09 Mar
2021, 20:00-
22:00

https://onlinecourses.nptel.ac.in/noc20_cs70/unit?unit=82&assessment=112 3/3
3/14/2021 Programming, Data Structures And Algorithms Using Python - - Unit 5 - Week 2 Quiz

(https://swayam.gov.in) (https://swayam.gov.in/nc_details/NPTEL)

[email protected]

NPTEL (https://swayam.gov.in/explorer?ncCode=NPTEL) » Programming, Data Structures And

Algorithms Using Python (course)

Course
outline Week 2 Quiz
The due date for submitting this assignment has passed.
How to access Due on 2019-08-21, 23:59 IST.
the portal

Week 1: Assignment submitted on 2019-08-20, 09:36 IST


Introduction All questions carry equal weightage. All Python code is assumed to be executed using Python3.
You may submit as many times as you like within the deadline. Your final submission will be
Week 1 Quiz graded.
Note:
Week 2: Basics
If the question asks about a value of type string, remember to enclose your answer in
of Python
single or double quotes.
If the question asks about a value of type list, remember to enclose your answer in
Week 2 Quiz
square brackets and use commas to separate list items.
Quiz : Week 2 1) One of the following 10 statements generates an error. Which one? (Your answer should be
Quiz
a number between 1 and 10.)
(assessment?
name=89)
x = [1,"abcd",2,"efgh",[3,4]] # Statement 1
Week 2 y = x[0:50] # Statement 2
Programming z = y # Statement 3
Assignment w = x # Statement 4
x[1] = x[1] + 'd' # Statement 5
Week 3: Lists, y[2] = 4 # Statement 6
inductive x[1][1] = 'y' # Statement 7
function z[0] = 0 # Statement 8
definitions, w[4][0] = 1000 # Statement 9
sorting a = (x[4][1] == 4) # Statement 10

Week 3 '7'
Programming

https://onlinecourses.nptel.ac.in/noc19_cs40/unit?unit=20&assessment=89 1/3
3/14/2021 Programming, Data Structures And Algorithms Using Python - - Unit 5 - Week 2 Quiz

Assignment No, the answer is incorrect.


Score: 0
Accepted Answers:
Week 4: Sorting,
(Type: Regex Match) [ ]*7[ ]
Tuples,
Dictionaries, 2.5 points
Passing
Functions, List 2) Consider the following lines of Python code. 2.5 points
Comprehension
x = [13,4,17,1000]
Week 4 Quiz w = x[1:]
u = x[1:]
y = x
Week 4
Programming u[0] = 50
Assignment y[1] = 40

Week 5: Which of the following is correct?


Exception
handling, x[1] == 40, y[1] == 40, w[0] == 4, u[0] == 50
input/output, file x[1] == 50, y[1] == 40, w[0] == 50, u[0] == 50
handling, string x[1] == 4, y[1] == 40, w[0] == 4, u[0] == 50
processing
x[1] == 40, y[1] == 40, w[0] == 50, u[0] == 50

Week 5 Yes, the answer is correct.


Programming Score: 2.5
Assignment Feedback:
(d) x[1] == 40, y[1] == 40, w[0] == 4, u[0] == 50
x and y refer to the same list, while w and u are two independent slices. The update to u[0]
Week 6:
does not affect any of the other names. The update to y[1] is also reflected in x[1].
Backtracking,
scope, data Accepted Answers:
structures; x[1] == 40, y[1] == 40, w[0] == 4, u[0] == 50
stacks, queues
3) What is the value of endmsg after executing the following lines?
and heaps
startmsg = "hello"
Week 6 Quiz endmsg = ""
for i in range(0,len(startmsg)):
Week 7: endmsg = startmsg[i] + endmsg
Classes, objects
and user defined 'olleh'
datatypes
Yes, the answer is correct.
Week 7 Quiz Score: 2.5
Accepted Answers:
(Type: Regex Match) \s*\'olleh\'\s*
Week 8:
(Type: Regex Match) \s*\"olleh\"\s*
Dynamic
programming, 2.5 points
wrap-up
4) What is the value of mylist after the following lines are executed?
Week 8 def mystery(l):
Programming l = l + l
Assignment return()

Download mylist = [22,34,57]


videos mystery(mylist)

https://onlinecourses.nptel.ac.in/noc19_cs40/unit?unit=20&assessment=89 2/3
3/14/2021 Programming, Data Structures And Algorithms Using Python - - Unit 5 - Week 2 Quiz

[22,34,57]
Text Transcripts
Yes, the answer is correct.
Online Score: 2.5
Programming Accepted Answers:
Test - Sample (Type: Regex Match) \s*\[\s*22,\s*34,\s*57\s*]\s*

2.5 points
Online
Programming
Test 1, 26 Sep
2019, 09:30-
11:30

Online
Programming
Test 2, 26 Sep
2019, 20:00-
22:00

https://onlinecourses.nptel.ac.in/noc19_cs40/unit?unit=20&assessment=89 3/3
3/14/2021 Programming, Data Structures And Algorithms Using Python - - Unit 10 - Week 4 Quiz

(https://swayam.gov.in) (https://swayam.gov.in/nc_details/NPTEL)

[email protected]

NPTEL (https://swayam.gov.in/explorer?ncCode=NPTEL) » Programming, Data Structures And

Algorithms Using Python (course)

Course
outline Week 4 Quiz
The due date for submitting this assignment has passed.
How to access Due on 2019-08-28, 23:59 IST.
the portal

Week 1: Assignment submitted on 2019-08-28, 22:01 IST


Introduction All questions carry equal weightage. All Python code is assumed to be executed using Python3.
You may submit as many times as you like within the deadline. Your final submission will be
Week 1 Quiz graded.
Note:
Week 2: Basics
If the question asks about a value of type string, remember to enclose your answer in
of Python
single or double quotes.
If the question asks about a value of type list, remember to enclose your answer in
Week 2 Quiz
square brackets and use commas to separate list items.

Week 2 1) Consider the following Python function.


Programming
Assignment def mystery(l):
if l == []:
return (l)
Week 3: Lists,
inductive else:
function return (l[-1:] + mystery(l[:-1]))
definitions,
sorting What does mystery([31,32,71,18,51]) return?

[51, 18, 71, 32, 31]


Week 3
Programming Yes, the answer is correct.
Assignment Score: 2.5
Accepted Answers:
Week 4: Sorting, (Type: Regex Match) [ ]*[[ ]*51[ ]*,[ ]*18[ ]*,[ ]*71[ ]*,[ ]*32[ ]*,[ ]*31[ ]*][ ]*
Tuples,
2.5 points

https://onlinecourses.nptel.ac.in/noc19_cs40/unit?unit=42&assessment=94 1/3
3/14/2021 Programming, Data Structures And Algorithms Using Python - - Unit 10 - Week 4 Quiz

Dictionaries, 2) What is the value of pairs after the following assignment?


Passing
Functions, List pairs = [ (x,y) for x in range(3,0,-1) for y in range(2,0,-1) if
Comprehension (x+y)%3 == 0 ]

Week 4 Quiz [(2, 1), (1, 2)]

Quiz : Week 4 Yes, the answer is correct.


Quiz
Score: 2.5
(assessment? Accepted Answers:
name=94) (Type: Regex Match) [ ]*[[ ]*\([ ]*2[ ]*,[ ]*1[ ]*\)[ ]*,[ ]*\([ ]*1[ ]*,[ ]*2[ ]*\)[ ]*][ ]*

2.5 points
Week 4
Programming 3) Consider the following dictionary. 2.5 points
Assignment
marks = {"Quizzes":{"Mahesh":[3,5,7,8],"Suresh":[9,4,8,8],"Um
Week 5: a":[9,9,7,6]},"Exams":{"Mahesh":[37],"Uma":[36]}}
Exception
handling, Which of the following statements does not generate an error?
input/output, file
handling, string marks["Exams"]["Suresh"][0:] = [44]
processing marks["Exams"]["Suresh"].append(44)
marks["Exams"]["Suresh"] = [44]
Week 5
marks["Exams"]["Suresh"].extend([44])
Programming
Assignment Yes, the answer is correct.
Score: 2.5
Week 6: Feedback:
Direct assignment to a new key adds a value. All other updates result in KeyError.
Backtracking,
scope, data Accepted Answers:
structures; marks["Exams"]["Suresh"] = [44]
stacks, queues 4) Assume that d has been initialized as an empty dictionary: 2.5 points
and heaps
d = {}
Week 6 Quiz
Which of the following generates an error?
Week 7:
Classes, objects d[12] = 5
and user defined d["1,2"] = 5
datatypes
d[(1,2)] = 5
d[[1,2]] = 5
Week 7 Quiz
Yes, the answer is correct.
Week 8: Score: 2.5
Dynamic Feedback:
Key must be an immutable value. List is not OK. Tuple, string and integer are OK.
programming,
wrap-up Accepted Answers:
d[[1,2]] = 5
Week 8
Programming
Assignment

Download
videos

https://onlinecourses.nptel.ac.in/noc19_cs40/unit?unit=42&assessment=94 2/3
3/14/2021 Programming, Data Structures And Algorithms Using Python - - Unit 10 - Week 4 Quiz

Text Transcripts

Online
Programming
Test - Sample

Online
Programming
Test 1, 26 Sep
2019, 09:30-
11:30

Online
Programming
Test 2, 26 Sep
2019, 20:00-
22:00

https://onlinecourses.nptel.ac.in/noc19_cs40/unit?unit=42&assessment=94 3/3
3/14/2021 Programming, Data Structures And Algorithms Using Python - - Unit 15 - Week 6 Quiz

(https://swayam.gov.in) (https://swayam.gov.in/nc_details/NPTEL)

[email protected]

NPTEL (https://swayam.gov.in/explorer?ncCode=NPTEL) » Programming, Data Structures And

Algorithms Using Python (course)

Course
outline Week 6 Quiz
The due date for submitting this assignment has passed.
How to access Due on 2019-09-11, 23:59 IST.
the portal

Week 1: Assignment submitted on 2019-09-11, 18:07 IST


Introduction All questions carry equal weightage. All Python code is assumed to be executed using Python3.
You may submit as many times as you like within the deadline. Your final submission will be
Week 1 Quiz graded.
Note:
Week 2: Basics
If the question asks about a value of type string, remember to enclose your answer in
of Python
single or double quotes.
If the question asks about a value of type list, remember to enclose your answer in
Week 2 Quiz
square brackets and use commas to separate list items.

Week 2 1) Suppose u and v both denote sets in Python. Under what condition can we 2.5 points
Programming guarantee that u - (u - v) == v?
Assignment
The sets u and v should be disjoint.
Week 3: Lists, The set v should be a subset of the set u.
inductive The set u should be a subset of the set v.
function
This is true for any u and v.
definitions,
sorting Yes, the answer is correct.
Score: 2.5
Week 3 Feedback:
Programming From u you take away all elements that are not in v and you are left with u ∩ v. Since u ∩ v
Assignment = v, we have v is a subset of u.
Accepted Answers:
Week 4: Sorting, The set v should be a subset of the set u.
Tuples,

https://onlinecourses.nptel.ac.in/noc19_cs40/unit?unit=62&assessment=96 1/3
3/14/2021 Programming, Data Structures And Algorithms Using Python - - Unit 15 - Week 6 Quiz

Dictionaries, 2) Suppose u and v both denote sets in Python. Under what condition can we 2.5 points
Passing guarantee that u|v == u^v?
Functions, List
Comprehension The sets u and v should be disjoint.
The set u should be a subset of the set v.
Week 4 Quiz The set v should be a subset of the set u.
This is true for any u and v.
Week 4
Programming Yes, the answer is correct.
Assignment Score: 2.5
Feedback:
u^v has all elements that are in exactly one of u or v. This is the same as u|v - u&v. Since
Week 5:
u^v = u|v, we have u&v is empty, so u and v are disjoint.
Exception
handling, Accepted Answers:
input/output, file The sets u and v should be disjoint.
handling, string 3) Suppose we insert 97 into the max heap [98,67,89,38,42,54,89,17,25]. What is the resulting
processing
heap?

Week 5 [98,97,89,38,67,54,89,17,2
Programming
Assignment Yes, the answer is correct.
Score: 2.5
Accepted Answers:
Week 6: (Type: Regex Match) [ ]*[[ ]*98[ ]*,[ ]*97[ ]*,[ ]*89[ ]*,[ ]*38[ ]*,[ ]*67[ ]*,[ ]*54[ ]*,[ ]*89[ ]*,[ ]*17[ ]*,
Backtracking, [ ]*25[ ]*,[ ]*42[ ]*][ ]*
scope, data
structures; 2.5 points
stacks, queues
and heaps 4) Suppose we we apply delete_max() twice to the heap [100,97,93,38,67,54,93,17,25,42].
What is the resulting heap?
Week 6 Quiz [93,67,93,38,42,54,25,17]

Quiz : Week 6 Yes, the answer is correct.


Quiz Score: 2.5
(assessment? Accepted Answers:
name=96) (Type: Regex Match) [[ ]*93[ ]*,[ ]*67[ ]*,[ ]*93[ ]*,[ ]*38[ ]*,[ ]*42[ ]*,[ ]*54[ ]*,[ ]*25[ ]*,[ ]*17[ ]*][ ]*

Week 7: 2.5 points


Classes, objects
and user defined
datatypes

Week 7 Quiz

Week 8:
Dynamic
programming,
wrap-up

Week 8
Programming
Assignment

Download
videos

https://onlinecourses.nptel.ac.in/noc19_cs40/unit?unit=62&assessment=96 2/3
3/14/2021 Programming, Data Structures And Algorithms Using Python - - Unit 15 - Week 6 Quiz

Text Transcripts

Online
Programming
Test - Sample

Online
Programming
Test 1, 26 Sep
2019, 09:30-
11:30

Online
Programming
Test 2, 26 Sep
2019, 20:00-
22:00

https://onlinecourses.nptel.ac.in/noc19_cs40/unit?unit=62&assessment=96 3/3
3/14/2021 Programming, Data Structures And Algorithms Using Python - - Unit 17 - Week 7 Quiz

(https://swayam.gov.in) (https://swayam.gov.in/nc_details/NPTEL)

[email protected]

NPTEL (https://swayam.gov.in/explorer?ncCode=NPTEL) » Programming, Data Structures And

Algorithms Using Python (course)

Course
outline Week 7 Quiz
The due date for submitting this assignment has passed.
How to access Due on 2019-09-18, 23:59 IST.
the portal

Week 1: Assignment submitted on 2019-09-18, 18:22 IST


Introduction All questions carry equal weightage. All Python code is assumed to be executed using Python3.
You may submit as many times as you like within the deadline. Your final submission will be
Week 1 Quiz graded.
Note:
Week 2: Basics
If the question asks about a value of type string, remember to enclose your answer in
of Python
single or double quotes.
If the question asks about a value of type list, remember to enclose your answer in
Week 2 Quiz
square brackets and use commas to separate list items.

Week 2 1) Given the following permutation of a,b,c,d,e,f,g,h,i,j, what is the next permutation in
Programming lexicographic (dictionary) order? Write your answer without any blank spaces between letters.
Assignment
eibjdhgfca
Week 3: Lists,
inductive [e,i,b,j,f,a,c,d,g,h]
function
definitions, No, the answer is incorrect.
Score: 0
sorting
Feedback:
The suffix to change is dhgfca. This becomes facdgh
Week 3
Accepted Answers:
Programming (Type: Regex Match) [ ]*eibjfacdgh[ ]*
Assignment (Type: Regex Match) [ ]*\'eibjfacdgh\'[ ]*
(Type: Regex Match) [ ]*\"eibjfacdgh\"[ ]*
Week 4: Sorting,
Tuples, 2.5 points

https://onlinecourses.nptel.ac.in/noc19_cs40/unit?unit=71&assessment=97 1/3
3/14/2021 Programming, Data Structures And Algorithms Using Python - - Unit 17 - Week 7 Quiz

Dictionaries, 2) We want to add a function listmax() to the class Node that implements user 2.5 points
Passing defined lists such that listmax() computes the maximum value in a list where values are of
Functions, List type int.
Comprehension
An incomplete implementation of listmax() given below. You have to provide expressions to
put in place of AAA, BBB and CCC.
Week 4 Quiz

Week 4 def listmax(self):


Programming
if self.value == None:
Assignment
return(AAA)
elif self.next == None:
Week 5:
return(BBB)
Exception
else:
handling,
return(CCC)
input/output, file
handling, string
processing AAA: 0, BBB: self.value, CCC: max(self.value, self.next.listmax())
AAA: 0, BBB: self.value, CCC: max(self.value, self.next.value)
Week 5
AAA: None, BBB: self.value, CCC: max(self.value, self.next.listmax())
Programming
Assignment AAA: None, BBB: self.value, CCC: max(self.value, self.next.value)

Yes, the answer is correct.


Week 6: Score: 2.5
Backtracking, Feedback:
scope, data listmax is not defined for the empty list, so AAA is None.
structures; If the list has only one value, that value is the maximum, so BBB is self.value.
stacks, queues If there are two or more elements, inductively compute the maximum of the rest of the
and heaps list and take the max with respect to the current values, so CCC is
max(self.value,self.next.listmax())
Week 6 Quiz
Accepted Answers:
AAA: None, BBB: self.value, CCC: max(self.value, self.next.listmax())
Week 7:
Classes, objects 3) Suppose we add this function foo() to the class Tree that implements search 2.5 points
and user defined trees. For a name mytree with a value of type Tree, what would mytree.foo() compute?
datatypes
def foo(self):
Week 7 Quiz if self.isempty():
return(0)
Quiz : Week 7 elif self.isleaf():
Quiz return(1)
(assessment? else:
name=97) return(self.left.foo() + self.right.foo()))

Week 8:
Dynamic The number of nodes in mytree
programming, The largest value in mytree.
wrap-up
The length of the longest path from root to leaf in mytree.

Week 8 The number of leaves in mytree.


Programming Yes, the answer is correct.
Assignment Score: 2.5
Feedback:
Download This computes the number of leaves in the tree. An empty tree has no leaves. A tree with just
videos one node has a single leaf. Otherwise, compute the number of leaves in left and right subtrees
and add them.

https://onlinecourses.nptel.ac.in/noc19_cs40/unit?unit=71&assessment=97 2/3
3/14/2021 Programming, Data Structures And Algorithms Using Python - - Unit 17 - Week 7 Quiz

This does not compute the number of nodes in the tree. For that, we need to add 1 in the
Text Transcripts
inductive case, to account for the current node. So the else: expression would be return(1
+ self.left.foo() + self.right.foo())).
Online
Accepted Answers:
Programming
The number of leaves in mytree.
Test - Sample
4) Inorder traversal of a binary tree has been defined in the lectures. A postorder traversal lists
Online the vertices of a binary tree (not necessarily a search tree) as follows:
Programming Print the left subtree in postorder.
Test 1, 26 Sep Print the right subtree in postorder.
2019, 09:30- Print the root.
11:30
Suppose we have a binary tree with 10 nodes labelled a, b, c, d, e, f, g, h, i, j, with
Online postorder traversal ehicbjfadg and inorder traversal ehbicgjafd. What is the left child of the
Programming root node?
Test 2, 26 Sep
[b]
2019, 20:00-
22:00
Hint

No, the answer is incorrect.


Score: 0
Feedback:
From the post traversal, g is the root. The inorder traversal tells us that ehbic lie to the left of
the root. The postorder traversal of this segment says b is the root of this subtree, so b is the
left child of the root.
Accepted Answers:
(Type: Regex Match) [ ]*b[ ]*
(Type: Regex Match) [ ]*\'b\'[ ]*
(Type: Regex Match) [ ]*\"b\"[ ]*

2.5 points

https://onlinecourses.nptel.ac.in/noc19_cs40/unit?unit=71&assessment=97 3/3

You might also like