Millions of computer science students have taken a  course on algorithms and data structures, typically  the second course after the initial one introducing  programming. One of the basic data structures in  such a course is the stack. The stack has a special  place in the emergence of computing as a science,  as argued by Michael Mahoney, the pioneer of the  history of the theory of computing. The Stack can  be used in many computer applications, few are  given below: 

Slide12.JPG

Slide13.JPG
Slide14.JPG

Identify the suitable code for the blank of Statement 1.

(A) .append()

(B) .insert()

(C) .extend()

(D) .append(Len(Country), N)

 

Answer:

Slide15.JPG

(A) .append()

Question 2 (i) - Teachoo.png

(B) .insert()

Question 2 (i)B - Teachoo.png

(C) .extend()

Question 2 (i)c - Teachoo.png

(D) .append(Len(Country), N)

Question 2 (i)d - Teachoo.png

 

Question 2 (ii)

Fill the Statement 2, to insert the alternate element from Country list.

(A) 3

(B) 0

(C) –1

(D) 2

 

Answer:

Checking the options

  • (A) 3 

Question 2 (ii)A - Teachoo.png

(B) 0 

Question 2 (ii)B - Teachoo.png

(C) –1

Question 2 (ii)C - Teachoo.png

(D) 2

Question 2 (ii)D - Teachoo.png

So, the correct answer is (D)

 

Question 2 (iii)

Fill the statement 3, to check the stack is empty.

(A) Country=[]

(B) Country. is Empty()

(C) Len(Country)==0

(D) No of the above

 

Answer:

Checking the options

  • (A) Country=[] 

Question 2 (iii)A - Teachoo.png

(B) Country. is Empty()

Question 2 (iii)B - Teachoo.png

(C) len(Country)==0

Question 2 (iii)c - Teachoo.png

(D) No of the above 

So, the correct answer is (C)

 

Question 2 (iv)

Fill the statement 4, to delete an element from the stack.

(A) pop(1)

(B) pop()

(C) del country[1]

(D) Country. delete(1)

 

Answer:

Checking the options

  • (A) pop(1)

Question 2 (iv)A - Teachoo.png

(B) pop()

Question 2 (iv)B - Teachoo.png

(C) del country[1]

Question 2 (iv)c - Teachoo.png

(D) Country. delete(1)

Question 2 (iv)D - Teachoo.png

So, the correct answer is (B)

 

Question 2 (v)

Fill the statement 5, to call the pop function.

(A) pop(C)

(B) pop(Country)

(C) call pop(Country)

(D) def pop(Country)

 

Answer:

Checking the options

  • (A) pop(C) 

Question 2 (v)A - Teachoo.png

(B) pop(Country) 

Question 2 (v)B - Teachoo.png

(C) call pop(Country)

Question 2 (v)c - Teachoo.png

(D) def pop(Country) 

Question 2 (v)D - Teachoo.png

So, the correct answer is (B)

 

Go Ad-free

Transcript

Case Base Question 2 Millions of computer science students have taken a course on algorithms and data structures, typically the second course after the initial one introducing programming. One of the basic data structures in such a course is the stack. The stack has a special place in the emergence of computing as a science, as argued by Michael Mahoney, the pioneer of the history of the theory of computing. The Stack can be used in many computer applications, few are given below: In recursive function When function is called. Expression conversion such as – Infix to Postfix, Infix to Prefix, Postfix to Infix, Prefix to Infix. In Stack, insertion operation is known as Push whereas deletion operation is known as pop. Code – 1 def push (Country, N): Country. ______ (N) #Statement 1 #Function Calling Country=[] C=[‘Indian’, ‘USA’, ‘UK’, ‘Canada’, ‘Sri Lanka’] for i in range (0, len(C), ______): #Statement 2 push (Country, C[i]) print (Country) Required Output: [‘Indian’, ‘UK’, ‘Shri Lanka’] Code – 2 def pop (Country): if __________ : #Statement 3 return “Under flow” else: return Country. __________ () #Statement 4 #Function Calling for i in range(len(Country)+1): print (__________) #Statement 5 Required Output: Sri Lanka UK India Under flow Fill the above statement based on given questions: (A) .append() (B) .insert() (C) .extend() (D) .append(len(Country), N)

Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 14 years. He provides courses for Maths, Science and Computer Science at Teachoo