Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
8 views
5 pages
Together With
Class 12 stack chapter
Uploaded by
Arush Verma
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download
Save
Save Together with For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
0 ratings
0% found this document useful (0 votes)
8 views
5 pages
Together With
Class 12 stack chapter
Uploaded by
Arush Verma
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Carousel Previous
Carousel Next
Download
Save
Save Together with For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
Download
Save Together with For Later
You are on page 1
/ 5
Search
Fullscreen
5 DATA STRUCTURE-STACK LEARNING OUTCOMES ‘After this chapter students will be able to: + describe the data structure along with its operations. + understand the stack. DATA STRUCTURE USING LIST, STACKS AND QUEUES 1. Data Structure. It is a way to store a collection of arbitrary data. The data structure can be implemented via the list, dictionary, tuple, set etc. 2. Classification of Data Structure. Data ¥ y ake Static or Fixed Dynamic Structure Structure12 Together ucek® Computer Science (Python) —12 n reverse order of their arrival. The stack 4 Structure. Some of eT called Last In First Out (LIFO) arrangemen, 3. Operations on Da the operations that are performed on data structure are as FollOWS: ce a aa ee nts in ush, Pe «Insertion (Addition of new eleme [Lisserion_} mmm Deletion the list.) «Deletion (Removal of an element from alist.) « Traversal (Visiting elements of a list.) « Searching (Finding an element in the list.) 4, Stack. Stack means arranging one object over another and these objects are removed 5. Operations on Stack. Push : Insertion of a new element (from the beginning) in stack. [Push(4) Top 2] [Push2)] [5 J [Pushts)) Top ESaS Top Top Pop : Deletion of an element(from the beginning) in stack. Pop 4 3 z 1 6. Conditions associated with Stack/Queue: * Overflow condition: It is a situation where we are not able to ai (o memory ition: i able to add new element di lue full or range is overfilled with values. * Underflow condition: It is a situation where there is no we wish to it is i is no element left and we still stil remove an element or display the list. ications of Stack. Stack a word or rev e and it can also used Stack. can be used to reverse /erse a lin al ction call routines,SOLVED QUESTION BANK Very Short Answer Type Questions [1 Mark] 1. Define data structure. Ans. It is a Way to store a collection of related data together. The data structure can be implemented via the list, dictionary, tuple, set etc 2, What is LIFO? Ans. Last In First Out. 3. What is traversal? Ans. Accessing each element is known as traversal 4. Name some applications of Stack. Ans. Application of Stack are: (a) Reverse of a String or Line (b) Function call routines. (0) Backtracking 5. Alist contains LST=(10,7,9,15,12].8 is added to the list. What will be the output? If (a) LST as Stack —_(b) LST as Queue Ans. (a) LST as Stack LST = [8,10,7,9,15,12] (6) LST as Queue LST = (10,7,9.15.12.8] Short Answer Type Questions [2/3 Marks] 6. Python program to check whether the list is empty or not. FileName: ch-datas\Q15] Ams. A = [] Af not A: print(“List 15 eroty”) Long Answer Type Questions [4 Marks] 7. Write # program to implement the stack using list. Ans-() wy wile (c+s"y") §. Write Push(Book) and Pop(Book) methods in Python to Add a new Book and Remove a Book from a List of Books, considering them to act as PUSH and POP operations of the data structure Stack. Ams. def push(Book Enter any number print (“Stack Enoty* else: print (“Deleted elenent 15:" Book. pop 9. Write a menu driven python program ‘using function Push(), Pop() and Display to implement the stack. The program will store the name of the books.14 Jogether week® Computer Science (Python)—12 Ans, def push(Book) : nane=input ("Enter the book nane") Book. append(nane) def pop(Book): if Book= print("Under Flow") else: print("Book Deleted" ,Book.pop()) def display (Book): print("Books in Stack") 1=1en (Book) for i in range(1~ print (Book[i], -1,-1): vend="*) # rain Book=[] while True: print("\n1. Push\n2. Pop \n3. Display\ nu, Exit") cheint(input ("Enter your choice") if ch==1: push (Book) elifch==2: pop (Book) elifch==3: display (Book) else: break 10. Write a menu driven python program using function Push (), Pop () and Display() to implement the stack. The program will store the Employee details i.e. Employee number, Employee name and Salary. Ans. def push(Emp): : enosint (input ("Enter the Empolyee Number") ) 'e=input("Enter the Employee Name") input ("Enter the Salary") pend([eno, enane, sal]) (Emp) print ("Under Flow") else: print("Employee Recorg Deleted" Emp. pop()) def display (Emp) : if Emp==[]: print ("Underflow!!!") else: print ("Employee record in Stack\n*) A-len(Emp) for i in range(1-1,-1,-1): print(Emp[i}) # main Emp=[] while True: print("\nl. Pushy n2. Pop \n3. Display\ nd. Exit") cheint (input ("Enter your choice")) if ch push(Emp) elif che=2: pop (Emp) elif ch==3: display (Emp) else: break Competency/Case-based Question 11. Read the following code carefully which is implementing the concept of STACK: defisEmpty(STACK): if len(STACK) return True else: return False def pop(STACK): if isEmpty(STACK): return "Underflow" else: element = STACK.pop() if, len(STACK) ‘top = None else: top = len(STACK) - 2 return element(a) How are the above two functions inter- related? Ans. The function isEmpty(STACK) will be called when pop(STACK) is called (6) What is the difference in between STACK.pop() and pop(STACK) Ans. STACK. pop() is pre defined and pop(STACK) is user defined (©) What is the retum type of the function defisEmpty (STACK) PRACTICE QUESTIONS Very Short Answer Type Questions [1 Mark] 1. Write the full form FIFO. 2. A list contains LST=[10,7,9,15,12]. An element is removed. What will be the output? If (a) LST as Stack (b) LST as Queue 3. Which method accepts two arguments (index element)? If the index is more than the size, then it will insert at the end. Data Structure-Stack 15 Ans. Boolean (@) What will the pop(STACK) function return if the stack already consist of [‘A’,’B’] at the position 0 and 1 respectively Ans. B (0) if len(STACK ; What is the purpose of this line in the above code: Ans. It checks if the stack is already empty. 4. Which is a situation when there is no element left and still wish to remove element? Long Answer Type Questions [4 Marks] 5. Write algorithm for PUSH(insert) operation in stack. 6. Write algorithm for POP(Remove) operation in stack. ANSWERS TO PRACTICE QUESTIONS 1. First in first out. 2. (a) LST as Stack LST = (7,9,15,12] (6) LST as Queue LST = [10,7,9,15,12] 3. Insert() 4. Underflow 5, Algorithm for PUSH in stack 1. Start 2.Element = Input("Enter the value to be added as element in Stack.") 3.Stak.append(Element) # Stak is the name of Stack. append() is used to insert the # element in the end of stack. 4. TopeToprd 5. End. 6. Algorithm for POP in stack. Start StakLen = len(Stak) # len() is used to calculate the length of the Stack. if StakLen <0 # To check whether stack is enpty or not Print("Pop is not possible as stack is empty”) else: val = Stak.pop() # pop() is used to remove the last inserted element in Stack. top = top-1 return top End
You might also like
Most Expected 2 Marks Most Expected Questions Stack Computer Science Class 12
PDF
100% (2)
Most Expected 2 Marks Most Expected Questions Stack Computer Science Class 12
28 pages
Data Structures Notes
PDF
No ratings yet
Data Structures Notes
10 pages
CS 12 Data Structures (Stack)
PDF
No ratings yet
CS 12 Data Structures (Stack)
8 pages
CH 5 - Stack Material For Board Exam
PDF
No ratings yet
CH 5 - Stack Material For Board Exam
9 pages
Together With Class 12
PDF
No ratings yet
Together With Class 12
8 pages
Stacks Preeti Arora
PDF
100% (1)
Stacks Preeti Arora
6 pages
Stack Class XII
PDF
100% (1)
Stack Class XII
16 pages
Stack
PDF
No ratings yet
Stack
9 pages
Data Structure For Class 12 CS 083 Python
PDF
No ratings yet
Data Structure For Class 12 CS 083 Python
24 pages
Pradeep Chemistry Class 12 Volume 1
PDF
No ratings yet
Pradeep Chemistry Class 12 Volume 1
9 pages
Pradeep Chemistry Class 12 Volume 1
PDF
No ratings yet
Pradeep Chemistry Class 12 Volume 1
6 pages
Data Structure in Python
PDF
No ratings yet
Data Structure in Python
36 pages
NOTES DataStructure Stacks 2022 23
PDF
No ratings yet
NOTES DataStructure Stacks 2022 23
8 pages
05 Data Structures
PDF
No ratings yet
05 Data Structures
11 pages
Pradeep Chemistry Class 12 Volume 1
PDF
No ratings yet
Pradeep Chemistry Class 12 Volume 1
6 pages
CSC KV CHN - Stack With Worksheet
PDF
No ratings yet
CSC KV CHN - Stack With Worksheet
10 pages
Stack
PDF
No ratings yet
Stack
27 pages
Stacks
PDF
No ratings yet
Stacks
23 pages
Data Structure
PDF
No ratings yet
Data Structure
10 pages
DS Notes-1
PDF
No ratings yet
DS Notes-1
174 pages
Study Material Xii Cs (Term-II)
PDF
No ratings yet
Study Material Xii Cs (Term-II)
93 pages
Updated Ds - Unit II
PDF
No ratings yet
Updated Ds - Unit II
63 pages
04 Data Structures (Stack)
PDF
No ratings yet
04 Data Structures (Stack)
11 pages
DS Unit 1
PDF
No ratings yet
DS Unit 1
78 pages
Ncert Class 12 Chapter 1
PDF
100% (1)
Ncert Class 12 Chapter 1
5 pages
Stack
PDF
No ratings yet
Stack
14 pages
Unit-II Linear Structures
PDF
No ratings yet
Unit-II Linear Structures
60 pages
Dsa (Week 5)
PDF
No ratings yet
Dsa (Week 5)
67 pages
Data Structure - Stack-1
PDF
No ratings yet
Data Structure - Stack-1
43 pages
cs12 - Data Structures Stack Using List
PDF
No ratings yet
cs12 - Data Structures Stack Using List
7 pages
Data Structures Stack
PDF
No ratings yet
Data Structures Stack
40 pages
Lecture 07 Stack and Queue
PDF
No ratings yet
Lecture 07 Stack and Queue
54 pages
DataStructure Stack
PDF
No ratings yet
DataStructure Stack
41 pages
Data Structure
PDF
No ratings yet
Data Structure
17 pages
Data Structure
PDF
No ratings yet
Data Structure
24 pages
Stack Data Structure
PDF
No ratings yet
Stack Data Structure
30 pages
Data Structure
PDF
No ratings yet
Data Structure
37 pages
Data Structures IN Python: Prepared By: Jyoti Gupta PGT (Computer Science) KV Sliet Longowal
PDF
No ratings yet
Data Structures IN Python: Prepared By: Jyoti Gupta PGT (Computer Science) KV Sliet Longowal
29 pages
Unit - 2 Linear Data Structures (Stacks)
PDF
No ratings yet
Unit - 2 Linear Data Structures (Stacks)
15 pages
Stack Questions
PDF
No ratings yet
Stack Questions
23 pages
SYCS Data Structure Practical Manual
PDF
No ratings yet
SYCS Data Structure Practical Manual
34 pages
Ads Assignment No. 3
PDF
No ratings yet
Ads Assignment No. 3
17 pages
Computer Science Grade XII Unit 1 Chapter 8pdf
PDF
No ratings yet
Computer Science Grade XII Unit 1 Chapter 8pdf
11 pages
Data Structure Stack and Queue 1
PDF
No ratings yet
Data Structure Stack and Queue 1
10 pages
Stack Question Banksolution
PDF
No ratings yet
Stack Question Banksolution
10 pages
Data Structure
PDF
No ratings yet
Data Structure
10 pages
Revised STACK in Python XII CS
PDF
No ratings yet
Revised STACK in Python XII CS
15 pages
Data Structure (Stack)
PDF
No ratings yet
Data Structure (Stack)
7 pages
Stack
PDF
No ratings yet
Stack
10 pages
Dsa Unit 2 Notes
PDF
No ratings yet
Dsa Unit 2 Notes
9 pages
Data Structures
PDF
No ratings yet
Data Structures
11 pages
Sample Paper Together With
PDF
No ratings yet
Sample Paper Together With
10 pages
Data Structures
PDF
No ratings yet
Data Structures
7 pages
MySQL Interface Python
PDF
No ratings yet
MySQL Interface Python
8 pages
DATA STRUCTUREhjhhnhmm
PDF
No ratings yet
DATA STRUCTUREhjhhnhmm
5 pages
Data Structure
PDF
No ratings yet
Data Structure
5 pages
Image To PDF 20230905 14.38.26
PDF
No ratings yet
Image To PDF 20230905 14.38.26
8 pages
Chap-7 Data Structures
PDF
No ratings yet
Chap-7 Data Structures
4 pages
XII Data Structure Reading Material
PDF
No ratings yet
XII Data Structure Reading Material
4 pages
Ncert Class 12 Chapter 1
PDF
No ratings yet
Ncert Class 12 Chapter 1
5 pages
Chap-9 Data Structures-I: Linear Lists Raw Data Data Item Data Type Data Structure
PDF
No ratings yet
Chap-9 Data Structures-I: Linear Lists Raw Data Data Item Data Type Data Structure
4 pages
Ncert Class 12 Chapter 1 Part 5
PDF
No ratings yet
Ncert Class 12 Chapter 1 Part 5
5 pages
Notes of Stack
PDF
No ratings yet
Notes of Stack
2 pages
Data Structures in Python - For App
PDF
No ratings yet
Data Structures in Python - For App
2 pages
Stack Importan Questions and Answers
PDF
No ratings yet
Stack Importan Questions and Answers
4 pages
Class 12 DS 1
PDF
No ratings yet
Class 12 DS 1
3 pages
CH Datastructure Stack
PDF
No ratings yet
CH Datastructure Stack
2 pages
05 - 12A - Data Structure
PDF
No ratings yet
05 - 12A - Data Structure
1 page