• Home
  • Courses
  • School
  • Programs
  • Problems
  • Contact Us
  • My account
  • Register

Have any question?

(+91) 98222 16647
info@simplycoding.in
RegisterLogin
Simply Coding
  • Home
  • Courses
  • School
  • Programs
  • Problems
  • Contact Us
  • My account
  • Register

Python

CBSE Python Data Structures Exercises

  • Categories Python, Data Structures
Python Data Structures

CBSE Python Data Structures Exercises:

1.Evaluate the following postfix notation of expression :
                        20, 10, +, 5, 2, * , –  ,10,  /
Ans. 
Scanned ElementsOperationStack Status
20Push20
10Push20, 10
+Pop twice
10+20= 30
Push
30
5Push30, 5
2Push30, 5, 2
*Pop twice
5*2= 10
Push
20
–Pop twice
30-10= 20
Push
20
10Push20, 10
/Pop twice
20/10= 2
Push
2
 
2.Convert the following infix expression to its equivalent postfix expression. Show stack contents for the conversion(A+B*(C-D) /E).
Ans.
Let us rewrite like(A+B*(C-D) / E)
Scanned ElementsOperationStack Status
((
A(A
+( +A
B( +AB
*( + *AB
(( + * (AB
C( + * (ABC
–( + * ( –ABC
D( + * ( –ABCD
)( + *ABCD –
/( + /ABCD – *
E( + /ABCD – * E
)ABCD – * E/+
 
3.Write a program to perform insert and display a Queue containing Members details as given in the following definition of each item:
                 MemberName            String
                         Age                        integer
Ans.
def INSERTQ(Arr):
MemberName=input("enter data to be inserted: ")
age=int(input("enter data to be inserted: "))
data = [MemberName, age]
Arr.append(data)
def Display(Arr):
   if Arr==[]:
       print("Queue Empty!")
   else:
       front= 0
       rear=len(Arr)-1
       for a in range(1,rear):
              print (Arr[a])
 
4.Write a program to implement a stack. Implement only push and display operations. The push function takes in stack and item to be pushed. Display takes in only stack.
Ans.
def Push(stack, item):
           stack.append(item)
           def Display(stack) :
   if isEmpty(stack):
       print("Stack empty")
   else:
       top=len(stack)-1
       for a in range(top-1,-1,-1):
            print(stack[a])
 
5.Change the following infix expression into postfix expression (A+B)*C + D/E –F
Ans.  Let us rewrite like(( A+B)*C+D/E-F)
Scanned ElementsOperationStack Status
((
(( (
A( (A
+( ( +A
B( ( +AB
)(AB+
*( *AB+
C( *AB+C
+( +AB+C*
D( +AB+C*D
/( + /AB+C*D
E( + /AB+C*DE
–( –AB+C*DE/+
F( –AB+C*DE/+F
)AB+C*DE/+F-
Ans. Output AB+C*DE/+F-
 
6.Write a program to delete an element from a sorted linear list.
Ans.
def Bsearch(AR,ITEM):
   beg = 0
   last = len(AR) - 1
   while(beg <= last):
       mid=(beg + last)//2
       if(ITEM == AR[mid]):
           return mid
       elif(ITEM > AR[mid]):
           beg = mid + 1
       else:
            last = mid - 1
   else:
           return False
myList=[10,20,30,40,50,60,70]
ITEM=int(input("Enter element to be deleted:"))
position=Bsearch(myList,ITEM)
if position:
   del myList[position]
   print("The list after deleting",ITEM,"is")
   print(myList)
else:
    print("Element not in the list")
 
7.Obtain the postfix notation for the following infix notation of expression showing the contents of the stack and postfix expression formed after each step of conversion.     A*B+(C-D/F)
Ans.
Let us rewrite like (A*B +(C-D/F))
Scanned ElementsOperationStack Status
((
A(A
*( *A
B( *AB
+( *AB*
(( + (AB*
C( + (AB*C
–( + ( –AB*C
D( + ( –AB*CD
/( + ( – /AB*CD
F( + ( – /AB*CDF
)( +AB*CDF/-
)AB*CDF/- +
Output: AB*CDF/-+

  • Share:
author avatar
Simply Coding

Previous post

Java Program on Special Number
April 23, 2020

Next post

Python Pyplot Example
April 23, 2020

You may also like

Queue
Python Queue
17 June, 2021
character python
Solve any character pattern program in python
3 June, 2021
number pattern in python
Solve any number patterns programs in python
3 June, 2021

Leave A Reply Cancel reply

You must be logged in to post a comment.

Categories

  • Uncategorized
  • Programs
    • Python
    • Java
  • Problems
    • Python
    • Java
    • Web Development
      • Internet
    • Emerging Technologies
  • Notes
    • General
    • QBasic
    • MS Access
    • Web Development
      • XML
      • HTML
      • JavaScript
      • Internet
    • Database
    • Logo Programming
    • Scratch
    • Emerging Trends
      • Artificial Intelligence
      • Internet of Things
      • Cloud Computing
      • Machine Learning
    • Computer Fundamentals
      • Computer Networks
      • E-Services
      • Computer Hardware
    • Python
    • Java
  • School
    • ICSE
      • Computers Class 9
        • Java Introduction
        • Tokens & Data Types
        • Java Operators
        • Math Library
        • if & switch
        • For & While
        • Nested loops
      • Computer Class 10
        • Sample Papers
        • OOPS concepts
        • Functions in Java
        • Constructors
        • Arrays in Java
        • Strings in Java
    • SSC
      • IT Class 11
        • IT Basics
        • DBMS
        • Web Designing
        • Cyber Laws
      • IT Class 12
        • Web Designing
        • SEO
        • Advanced JavaScript
        • Emerging Tech
        • Server Side Scripting
        • E-Com & E-Gov
      • Computer Science 11
      • Computer Science 12
    • CBSE
      • Computer 9
        • Basics of IT
        • Cyber Safety
        • Scratch
        • Python
      • Computer 10
        • Sample Papers
        • Networking
        • HTML
        • Cyber Ethics
        • Scratch
        • Python
      • Computer Science 11
        • Computer Systems
        • Python 11
          • Python Basics
          • Python Tokens
          • Python Operators
          • Python if-else
          • Python loops
          • Python Strings
          • Python List
          • Python Tuple
          • Python Dictionary
          • Python Modules
        • Data Management
      • Computer Science 12
        • Sample Papers
        • Python 12
          • Python Functions
          • Python File Handling
          • Python Libraries
          • Python Recursion
          • Data Structures
        • Computer Networks
        • Data Management
    • ISC
      • Computer Science 11
        • Introduction to Java
        • Values & Data Types
        • Operators
        • if & switch
        • Iterative Statements
        • Functions
        • Arrays
        • String
        • Data Structures
        • Cyber Ethics
      • Computer Science 12
        • Sample Papers
        • Boolean Algebra
        • OOPS
        • Wrapper Classes
        • Functions
        • Arrays
        • String

Categories

  • Uncategorized
  • Programs
    • Python
    • Java
  • Problems
    • Python
    • Java
    • Web Development
      • Internet
    • Emerging Technologies
  • Notes
    • General
    • QBasic
    • MS Access
    • Web Development
      • XML
      • HTML
      • JavaScript
      • Internet
    • Database
    • Logo Programming
    • Scratch
    • Emerging Trends
      • Artificial Intelligence
      • Internet of Things
      • Cloud Computing
      • Machine Learning
    • Computer Fundamentals
      • Computer Networks
      • E-Services
      • Computer Hardware
    • Python
    • Java
  • School
    • ICSE
      • Computers Class 9
        • Java Introduction
        • Tokens & Data Types
        • Java Operators
        • Math Library
        • if & switch
        • For & While
        • Nested loops
      • Computer Class 10
        • Sample Papers
        • OOPS concepts
        • Functions in Java
        • Constructors
        • Arrays in Java
        • Strings in Java
    • SSC
      • IT Class 11
        • IT Basics
        • DBMS
        • Web Designing
        • Cyber Laws
      • IT Class 12
        • Web Designing
        • SEO
        • Advanced JavaScript
        • Emerging Tech
        • Server Side Scripting
        • E-Com & E-Gov
      • Computer Science 11
      • Computer Science 12
    • CBSE
      • Computer 9
        • Basics of IT
        • Cyber Safety
        • Scratch
        • Python
      • Computer 10
        • Sample Papers
        • Networking
        • HTML
        • Cyber Ethics
        • Scratch
        • Python
      • Computer Science 11
        • Computer Systems
        • Python 11
          • Python Basics
          • Python Tokens
          • Python Operators
          • Python if-else
          • Python loops
          • Python Strings
          • Python List
          • Python Tuple
          • Python Dictionary
          • Python Modules
        • Data Management
      • Computer Science 12
        • Sample Papers
        • Python 12
          • Python Functions
          • Python File Handling
          • Python Libraries
          • Python Recursion
          • Data Structures
        • Computer Networks
        • Data Management
    • ISC
      • Computer Science 11
        • Introduction to Java
        • Values & Data Types
        • Operators
        • if & switch
        • Iterative Statements
        • Functions
        • Arrays
        • String
        • Data Structures
        • Cyber Ethics
      • Computer Science 12
        • Sample Papers
        • Boolean Algebra
        • OOPS
        • Wrapper Classes
        • Functions
        • Arrays
        • String
Simply Coding Computer Courses for School                Privacy Policy     Terms of Use     Contact Us

© 2021 Simply Coding

Login with your site account

Lost your password?

Not a member yet? Register now

Register a new account

Are you a member? Login now