0% found this document useful (0 votes)
75 views9 pages

Xii Cs Unit I Part7 Data Structure 2020 21

The document provides information about the Class 12 Computer Science syllabus for the academic year 2020-21. It discusses the distribution of marks across three units and topics covered in each unit. Unit I focuses on computational thinking, programming in Python, functions, file handling, and data structures like lists, stacks and queues. It provides implementation details and examples of commonly used list, stack and queue operations in Python.

Uploaded by

BEENA HASSINA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views9 pages

Xii Cs Unit I Part7 Data Structure 2020 21

The document provides information about the Class 12 Computer Science syllabus for the academic year 2020-21. It discusses the distribution of marks across three units and topics covered in each unit. Unit I focuses on computational thinking, programming in Python, functions, file handling, and data structures like lists, stacks and queues. It provides implementation details and examples of commonly used list, stack and queue operations in Python.

Uploaded by

BEENA HASSINA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Computer Science (083)

CLASS-XII 2020-21

DISTRIBUTION OF MARKS:
UNIT UNIT NAME MARKS

I Computational Thinking and Programming - 2 40

II Computer Networks 10

III Database Management 20

TOTAL 70

● Revision of the basics of Python covered in Class XI.


● Functions: scope, parameter passing, mutable/immutable properties of data
objects, passing strings, lists, tuples, dictionaries to functions, default
parameters, positional parameters, return values, functions using libraries:
mathematical and string functions.
● File handling: Need for a data file, Types of file: Text files, Binary files and
CSV (Comma separated values) files.
● Text File: Basic operations on a text file: Open (filename – absolute or
relative path, mode) / Close a text file, Reading and Manipulation of data
from a text file, Appending data into a text file, standard input / output and
error streams, relative and absolute paths.
● Binary File: Basic operations on a binary file: Open (filename – absolute or
relative path, mode) / Close a binary file, Pickle Module – methods load and
dump; Read, Write/Create, Search, Append and Update operations in a binary
file.
● CSV File: Import csv module, functions – Open / Close a csv file, Read from a
csv file and Write into a csv file using csv.reader ( ) and csv.writerow( ).
● Using Python libraries: create and import Python libraries.
● Recursion: simple algorithms with recursion: print a message forever, sum of
first n natural numbers, factorial, Fibonacci numbers; recursion on arrays:
binary search.
● Idea of efficiency: performance measurement in terms of the number of
operations.
●Data-structures: Lists as covered in Class XI, Stacks – Push, Pop using a list,
Queues – Insert, Delete using a list.
Data Structure:

Is a named group of data of different data types which is stored in a


specific way and can be processed as a single unit. A data structure has
well-defined operations, behaviour and properties.

It is a way of organizing and storing data in such a manner so that it can


be accessed and work over it can be done efficiently and fewer
resources are required. It defines the relationship between the data and
the operations over those data.

Python Data Structure:

List (Linear Data Structure):

It is a collection of items and each item has its own index value. Index of
first item is 0 and the last item is n-1. Here n is number of items in a list.

Indexing of list
Creating a list:

Lists are enclosed in square brackets [ ] and each item is separated by a


comma.

Example:

list1 = [‘English', ‘Hindi', 1997, 2000];


list2 = [11, 22, 33, 44, 55];
list3 = ["a", "b", "c", "d"];

Access Items from a List:

List items can be accessed using its index position.

e.g.
list =[3,5,9]
print(list[0]) 3
print(list[1]) 5
print(list[2]) 9
print('a pause') a pause
print(list[-1]) 9
print(list[-2]) 5
print(list[-3]) 3

Iterating through a List:

List elements can be accessed using looping statement.

list =[3,5,9]
for i in range(0, len(list)):
print(list[i])

Output
3
5
9
Slicing of a List:

List elements can be accessed in subparts.

list =['I','N','D','I','A']
print(list[0:3])
print(list[3:])
print(list[:])

Output
['I', 'N', 'D']
['I', 'A']
['I', 'N', 'D', 'I', 'A']

Updating Lists:

We can update single or multiple elements of lists by giving the slice on


the left-hand side of the assignment operator.

list = ['English', 'Hindi', 1997, 2000]


print ("Value available at index 2 : ", list[2])
list[2:3] = 2001,2002 #list[2]=2001 for single item update
print ("New value available at index 2 : ", list[2])
print ("New value available at index 3 : ", list[3])

Output
('Value available at index 2 : ', 1997)
('New value available at index 2 : ', 2001)
('New value available at index 3 : ', 2002)
Add Item to a List

append()method is used to add an Item to a List.

list=[1,2]
print('list before append', list)
list.append(3)
print('list after append', list)
Output
('list before append', [1, 2])
('list after append', [1, 2, 3])

extend() method can be used to add multiple item at a time in list.eg -


list.extend([3,4])

Add Two Lists e.g.

list = [1,2]
list2 = [3,4]
list3 = list + list2
print(list3)

OUTPUT
[1,2,3,4]

Delete Item from a List

list=[1,2,3]
print('list before delete', list)
del list [1]
print('list after delete', list)

Output
('list before delete', [1, 2, 3])
('list after delete', [1, 3])

dellist[0:2]# delete first two items


dellist# delete entire list
Some useful functions of lists:

Function Description
list.append() Add an Item at end of a list
list.extend() Add multiple Items at end of a list
list.insert() insert an Item at a defined index
list.remove() remove an Item from a list
del list[index] Delete an Item from a list
list.clear() empty all the list
list.pop() Remove an Item at a defined index
list.index() Return index of first matched item
list.sort() Sort the items of a list in ascending or descending order
list.reverse() Reverse the items of a list
len(list) Return total length of the list.
max(list) Return item with maximum value in the list.
min(list) Return item with min value in the list.
list(seq) Converts a tuple, string, set, dictionary into list.

Stack:

A stack is a linear data structure in which all the insertion and deletion
of data / values are done at one end only.

 It is type of linear data structure.


 It follows LIFO (Last in First Out)
 Insertion / Deletion in stack can only be done from top.
 Insertion in stack is also known as a PUSH operation.
 Deletion from stack is also known as POP operation.

Applications of Stack:

 Expression Evaluation
 Expression Conversion
 Parenthesis Checking
 String Reversal
 Function Call
Using list as Stack:

Stack implementation is easy in Python, as it support inbuilt functions


append() and pop() for stack implementation.

To add an item to the top of the list, i.e., to push an item, we use
append() function and to pop out an element we use pop() function.

Example:

class Stack:
def init (self):
self.items = []
def is_empty(self):
return self.items == []
def push(self, data):
self.items.append(data)
def pop(self):
return self.items.pop()

s = Stack()
while True:
print('Press 1 for push')
print('Press 2 for pop')
print('Press 3 for quit')
do = int(input('What would you like to do'))
if do == 1:
n=int(input("enter a number to push"))
s.push(n)
elif do == 2:
if s.is_empty():
print('Stack is empty.')
else:
print('Popped value: ', s.pop())
elif operation == 3:
break
Queue:

Queue is a data structure that is based on First in First out (FIFO)


strategy, i.e. the first element that is added to the queue is the first
one to be removed.

 Queue follows the FIFO (First - In -First Out) structure.


 According to its FIFO structure, element inserted first will also be
removed first.
 In a queue, one end is always used to insert data (enqueue) and the
other is used to delete data (dequeue), because queue is open at
both its ends.

Applications of Queue

 Synchronization
 Scheduling
 Searching
 Interrupt handling

Using list as Queue:

Queue implementation is easy in Python , as it support inbuilt functions


insert() and pop() for queue implementation.

To add an item at front of the queue, i.e., to enqueue an item, we use


insert() function and to dequeue an element we use pop() function.
Example:

class Queue:
def init (self):
self.items = []
def isEmpty(self):
return self.items == []
def enqueue(self, item):
self.items.insert(0,item)
def dequeue(self):
return self.items.pop()
def size(self):
return len(self.items)

q = Queue()
while True:
print('Press 1 for insert')
print('Press 2 for delete')
print('Press 3 for quit')
do = int(input('What would you like to do'))
if do == 1:
n=int(input("enter a number to push"))
q.enqueue(n)
elif do == 2:
if q.isEmpty():
print('Queue is empty.')
else:
print('Deleted value: ', q.dequeue())
elif operation == 3:
break

You might also like