0% found this document useful (0 votes)
3 views8 pages

Python Programming and Data Structures

The document covers fundamental concepts of Python programming and data structures, including queues, stacks, and binary trees. It explains various operations, types of data structures, and features of Python, along with examples of algorithms and functions. Additionally, it discusses recursion, time and space complexity, and the differences between mutable and immutable data types.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views8 pages

Python Programming and Data Structures

The document covers fundamental concepts of Python programming and data structures, including queues, stacks, and binary trees. It explains various operations, types of data structures, and features of Python, along with examples of algorithms and functions. Additionally, it discusses recursion, time and space complexity, and the differences between mutable and immutable data types.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Python Programming and Data Structures • Linked List

(Other options: Stack, Queue)


1.
2.
Enqueue – Insert element into the queue (rear end).
Dequeue – Remove element from the queue (front end).
Linear Queue
Last position does not connect to first.
Circular Queue
Last position connects back to first.
3. Peek/Front – View the front element. Causes wastage of space when front moves ahead. No wastage; space reused efficiently.
IsEmpty / IsFull – Check status of queue.
Attempt any Five of the following: [2 marks each]
4. Implemented using simple array. Implemented using circular array.
Front → Rear only in one direction. Front and Rear wrap around circularly.
f) List any four sorting algorithms.

1. Bubble Sort f) What is recursion? e) List applications of Queue.


a) What is meant by immutable data type in Python? 2. Selection Sort
3. Insertion Sort Recursion is a programming technique where a function calls itself until a base condition is met. 1. CPU scheduling
Immutable data types are those whose value cannot be changed after creation. 4. Merge Sort 2. Printers (print spooling)
If you try to modify them, Python creates a new object. Example: factorial, Fibonacci, tree traversal. 3. Call center / customer service systems
(Other valid options: Quick Sort, Heap Sort, Shell Sort) 4. Breadth-First Search (BFS) in graphs
Examples: int, float, string, tuple. a) Define time complexity and space complexity.
a) What is Binary Tree?
Time Complexity:
A Binary Tree is a tree data structure in which each node has at most two children, called: It measures how much time an algorithm takes to run depending on the size of input. f) List features of Python.
b) What is keyword? List any 4 keywords in Python.
• Left child Space Complexity: 1. Simple and easy syntax
• Right child It measures how much memory an algorithm uses during execution. 2. Object-oriented
A keyword is a reserved word in Python that has a special meaning and cannot be used as a variable
name. 3. Large standard library
It is used in searching, sorting, and hierarchical data representation. 4. Platform independent
Any 4 keywords: 5. Supports functional and structured programming
if, for, while, return b) What is anonymous function? How to create it?
a) List some popular applications of Python programming language.
b) What is the role of indentation in Python? An anonymous function is a function without a name.
1. Web development (Django, Flask)
c) What is the use of lambda()? Indentation in Python is used to define blocks of code. In Python, it is created using the lambda keyword. 2. Data science & Machine Learning
Instead of curly braces {}, Python uses spaces or tabs. 3. Automation / Scripting
lambda() is used to create anonymous (nameless) functions in Python. Syntax: 4. Game development
It is mainly used for short, single-line functions. Example: 5. Desktop applications
Indentation shows which statements belong inside loops, functions, or conditions. lambda arguments: expression

Example:
lambda x: x + 5 Example:

square = lambda x: x*x


b) What is the difference between a Mutable datatype and an Immutable datatype?
c) Define Data Structure.
Mutable Datatype Immutable Datatype
d) Write any four applications of Stack. A Data Structure is a way of organizing and storing data so that it can be used efficiently.
c) How to perform input-output operations? Can be changed after creation. Cannot be changed after creation.
Examples: Array, Stack, Queue, Linked List, Tree, Graph. Examples: list, dict, set Examples: int, float, string, tuple
1. Function call management Input:
2. Expression evaluation You can take input using the input() function.
3. Undo/redo operations
4. Backtracking (maze solving, DFS) name = input("Enter name: ")
c) What are local variables and global variables in Python?
d) List any four features of Python.
Local Variables:
Output:
1. Easy to read and write (simple syntax) You can display output using the print() function.
e) What is linear data structure? List any two linear data structures. 2. Object-oriented language • Declared inside a function.
3. Supports multiple libraries print("Hello", name) • Accessible only within that function.
A linear data structure stores data in a sequential manner, one after another. 4. Platform-independent (works on Windows, Mac, Linux)
Global Variables:
Any two: d) Differentiate between circular and linear queue.
• Declared outside all functions.
• Array e) What are operations performed on queue? • Accessible throughout the program, in all functions.

for i in range(1, 10): Inserts an element at a specific position. • Searching


if i == 5:
• Updating
break
d) List any four sorting algorithms. print(i)
[Link](1, "Python") • Appending

1. Bubble Sort Output:


3) remove() a) Write a Python program to find length of a set, maximum and
2. Selection Sort 1234
3. Insertion Sort (Loop stops when i becomes 5) minimum value in a set. [4]
4. Merge Sort Removes the first occurrence of a value.
Program:
[Link]("hello")
(Other valid: Quick Sort, Heap Sort)
# create a set
2) continue Statement numbers = {10, 5, 25, 3, 18}
4) sort()
The continue statement skips the current iteration and moves to the next iteration of the loop. # length of a set
e) Write difference between Linear and Non-linear Data Structures. Sorts the list in ascending order.
print("Length of set:", len(numbers))
Syntax: # maximum value
Linear Data Structure Non-linear Data Structure [Link]() print("Maximum value:", max(numbers))
continue
Elements are arranged sequentially. Elements are arranged in hierarchical form.
# minimum value
Example: Array, Stack, Queue Example: Tree, Graph Example: print("Minimum value:", min(numbers))
(Other functions include: pop(), extend(), reverse(), count(), index())
Easy to traverse. Complex traversal.
for i in range(1, 6): Expected Output:
if i == 3:
continue Length of set: 5
f) What is Binary Search Tree? print(i)
c) Explain any two array operations. [4] Maximum value: 25
Minimum value: 3
A Binary Search Tree (BST) is a special binary tree where: Output:
1245
• Left child contains values less than the parent (3 is skipped)
• Right child contains values greater than the parent 1) Traversing an Array b) What is the difference between a Set and Dictionary? [4]
• No duplicate values allowed
Traversing means visiting each element in the array one by one. Set Dictionary
It is used for fast searching, insertion, and deletion. Unordered collection of unique values. Collection of key–value pairs.
b) What is List? State any four built-in list functions with their use. Example:
Written using {1, 2, 3}. Written using {"name": "Ram", "age": 20}.
Q2) Attempt all of the following. [4 marks each] [4] from array import *
arr = array('i', [10, 20, 30, 40])
Only values are stored. Both keys and values are stored.
List (Definition) for x in arr: Elements cannot be accessed by index. Values can be accessed using keys.
print(x) Used for mathematical operations like union, intersection. Used for mapping values (like mini database).
A list in Python is a mutable, ordered collection of items.
a) Explain any two loop control statements with proper syntax and Items can be of different data types.
2) Insertion in an Array
example. [4] c) Explain how to create class and object in Python. [4]
Example:
Insertion means adding a new element at a specific position.
Loop control statements are used to change the normal flow of loops. mylist = [10, "hello", 3.5] Class (Definition):
Syntax:
A class is a blueprint/template used to create objects.
Four Built-in List Functions array_name.insert(index, value) It defines attributes (variables) and methods (functions).
1) break Statement
1) append() Example: Object (Definition):
The break statement is used to exit the loop immediately, even if the loop condition is still true.
arr = array('i', [1, 2, 3]) An object is an instance of a class.
Adds an element to the end of the list. [Link](1, 10) # inserts 10 at index 1
Syntax: It represents real-world entities.
[Link](20)
break
Other array operations (extra points if needed):
Example: 2) insert() How to create a class and object?
• Deletion
Example: A stack is a linear data structure that works on LIFO (Last In First Out) principle. Step 1: For A * B → * A B • Types: Input Restricted, Output Restricted.
The element inserted last is removed first. Step 2: For C * D → * C D
# creating a class Step 3: For total: + (A*B) (C*D) →
class Student:
# constructor
Four Stack Operations:
def __init__(self, name, marks): Prefix = + * A B * C D b) Write the elements in BFS of the following Binary Tree. [4]
[Link] = name
[Link] = marks
Tree Structure:
# method
1) push() – Insert element into stack
def display(self):
print("Name:", [Link]) stack = []
2) Postfix (Reverse Polish Notation) /
a
\
print("Marks:", [Link]) [Link](10) # push 10 b c
Operator comes after operands / \ / \
# creating object of class d e f g
s1 = Student("Rahul", 85)
2) pop() – Remove top element Step 1: A * B → A B * / \ \
h i j
# calling method
Step 2: C * D → C D *
[Link]() [Link]() Step 3: Final expression →

Output:
3) peek() – View top element without removing
Postfix = A B * C D * + b) Write the elements in BFS and DFS of the
Name: Rahul
Marks: 85 top = stack[-1]
a) What is Queue? Explain types of Queue. [4] following Binary Tree.
print(top)
Queue (Definition)
) Explain function in Python with suitable example. [4]
A function in Python is a block of reusable code that performs a specific task.
4) isEmpty() – Check if stack is empty A Queue is a linear data structure that follows the FIFO (First In First Out) principle. 1) BFS (Breadth First Search) – Level Order Traversal
The element inserted first is removed first.
Functions help in reducing code repetition, improving readability, and organizing programs. if len(stack) == 0: Visit nodes level by level:
print("Stack is empty") Types of Queue:
Syntax of a function Level 1: a
Stacks are used in function calls, expression conversion, undo operations, etc. Level 2: b, c
def function_name(parameters):
statements Level 3: d, e, f, g
return value 1) Simple / Linear Queue Level 4: h, i, j

Example: c) Write Prefix and Postfix Expression of: • Elements inserted at rear, deleted from front. BFS Traversal:
• Example operations: enqueue, dequeue.
def add(a, b): A*B+C*D abcdefghij
result = a + b
return result
Given expression is:
# calling function 2) Circular Queue
print(add(5, 10)) 𝐴×𝐵+𝐶×𝐷 2) DFS (Depth First Search)
• Last position connects back to first.
Output: • Solves space wastage problem of linear queue.
DFS can be Preorder / Inorder / Postorder, but if the question says DFS, we normally give preorder.
This is of type:
15
(𝐴 ∗ 𝐵) + (𝐶 ∗ 𝐷)
DFS (Preorder: Root → Left → Right)
In this example, add() is a function that takes two numbers and returns their sum. 3) Priority Queue
Visit in this order:
• Each element has a priority.
• Element with highest priority is removed first (not based on order of arrival). a
1) Prefix (Polish Notation) b
b) What is stack? Explain any four stack operations in data d
structure using Python. [4] Operator comes before operands e
4) Double Ended Queue (Deque) h
Stack (Definition) i
• Insertion and deletion possible from both ends. c

f 20 200 A B C new_node.next = [Link]


/ \ / \ A [0 1 1] [Link] = new_node
g 10 30 150 300 B [1 0 0]
j C [1 0 0] # display list
def display(self):
Now perform the traversals: temp = [Link]
DFS Traversal: Advantages: while temp:
print([Link], end=" -> ")
abdehicfgj • Easy to implement temp = [Link]

a) Inorder, Preorder, Postorder Traversal


• Fast to check if an edge exists print("None")

# Using the Linked List


Disadvantages: ll = LinkedList()
ll.insert_at_start(30)
• Uses more memory (n² space) ll.insert_at_start(20)

1) Inorder Traversal (Left → Root → Right)


ll.insert_at_start(10)
• Not suitable for sparse graphs
c) Write Python program for stack using list. [4] [Link]()
10 20 30 100 150 200 300
Python Program: Output:
stack = [] 2) Adjacency List Representation
2) Preorder Traversal (Root → Left → Right) 10 -> 20 -> 30 -> None
# push operation • Each vertex stores a list of connected vertices.
def push(x):
[Link](x)
print(f"Pushed: {x}")
100 20 10 30 200 150 300 • Efficient for storing sparse graphs.
a) Explain features of Python programming. [6]
Example:
Python is a powerful and widely used programming language. Some important features are:
# pop operation
def pop(): 3) Postorder Traversal (Left → Right → Root) A → B, C
if not stack: B → A 1) Simple and Easy to Learn
print("Stack is empty") 10 30 20 150 300 200 100 C → A
else:
print("Popped:", [Link]()) Python has a clean and readable syntax.
Advantages: Example: No semicolons, no curly braces.
# peek operation Final Answer:
def peek(): • Uses less memory
if not stack:
2) Interpreted Language
• Inorder: • Easy to traverse neighbors
print("Stack is empty")
else: 10 20 30 100 150 200 300 Python executes code line by line.
print("Top element:", stack[-1]) • Preorder: Disadvantages: No need for compilation → debugging is easier.
100 20 10 30 200 150 300
# display stack • Postorder:
def display(): • Slightly slower to check if a specific edge exists 3) Object-Oriented
print("Stack:", stack) 10 30 20 150 300 200 100
Supports classes, objects, inheritance, polymorphism, encapsulation.
# using the stack

c) Write Python program for insert node at start position of


push(10)
push(20) 4) Extensive Standard Library
b) Explain any two ways of representation of graph. [4] Linked List. [4]
push(30)
display() Python provides many built-in modules like:
peek()
pop()
display() Graphs can be represented in two common ways: Python Program: • math
• datetime
class Node: • os
def __init__(self, data): • random
[Link] = data
a) Write the elements in inorder, preorder and postorder traversal 1) Adjacency Matrix Representation [Link] = None
These help in fast development.
of the following Binary Search Tree. • A graph with n vertices uses an n × n matrix. class LinkedList:
def __init__(self): 5) Platform Independent
• If there is an edge between vertex i and vertex j, [Link] = None
Tree Structure: matrix entry = 1, otherwise 0.
# insert at start
Python code runs on Windows, Linux, Mac without change.
def insert_at_start(self, data):
100 Example: new_node = Node(data) 6) Supports Multiple Programming Paradigms
/ \
• Procedural programming Examples: • Data A dictionary in Python stores data in key–value pairs.
• Object-oriented programming =, +=, -=, *=, /=, %= • Pointer (address of next node) Common dictionary methods are:
• Functional programming (with lambda)
Nodes are linked together using pointers.
7) Free and Open-Source
5) Bitwise Operators Features: 1) keys()
Anyone can download, modify, and use Python.
• Dynamic size Returns all keys in the dictionary.
Operate on bits.
8) Huge Community Support • Easy insertion and deletion
• No memory wastage d = {"name": "Raj", "age": 20}
Examples: print([Link]()) # dict_keys(['name', 'age'])
Large number of tutorials, documentation, and third-party libraries. & (AND), | (OR), ^ (XOR), <<, >>

2) values()
Types of Linked List
b) Explain various operators in Python 6) Membership Operators Returns all values in the dictionary.

programming. [6] Used to check membership in sequences.


1) Singly Linked List
print([Link]()) # dict_values(['Raj', 20])

Python supports several categories of operators: Examples:


in, not in • Each node has one pointer to the next node. 3) items()
• Traversal possible in one direction only.
Example: Returns key–value pairs as tuples.
A → B → C → None
1) Arithmetic Operators 5 in [1,2,3,5] # True print([Link]()) # dict_items([('name', 'Raj'), ('age', 20)])

Used for mathematical operations. 2) Doubly Linked List


4) get(key)
Examples: 7) Identity Operators • Each node has two pointers:
+ (addition), - (subtraction), * (multiplication), / (division), %, //, ** o one to the next node Returns value of a key without an error.
Check if two variables refer to the same object. o one to the previous node
print([Link]("age")) # 20
Examples: Allows backward and forward traversal.
is, is not (Other valid: update(), pop(), popitem(), clear(), setdefault(), copy())
2) Relational (Comparison) Operators None ← A ↔ B ↔ C → None

Used to compare two values.


8) Unary Operators 3) Circular Linked List **b) Sort the following elements using Bubble Sort:
Examples:
==, !=, <, >, <=, >=
Applied on single operand. • Last node points back to the first node.
• Can be singly or doubly circular. 89 29 39 79 59 49 69 19 [4]**
Example:
A → B → C → A Pass-by-pass bubble sort:
-a changes sign of a number.
3) Logical Operators
Initial list:
Used for combining conditions. 4) Circular Doubly Linked List 89 29 39 79 59 49 69 19

Examples: c) What is Linked List? Explain types of Linked •



Doubly linked + circular.

List. [6]
and, or, not Both ends connected.
Pass 1
A ↔ B ↔ C ↔ A
19 moves to end of first pass:
Linked List (Definition)
4) Assignment Operators a) Explain any four methods in Dictionary. [4]
29 39 79 59 49 69 19 89
A Linked List is a linear data structure in which elements are stored in nodes, and each node contains:
29 39 59 49 69 19 79 89
Used to assign values.

29 39 49 59 19 69 79 89 a) Write a program to reverse a given string using stack. [4] Example: 3) Circular Linked List
29 39 49 19 59 69 79 89
29 39 19 49 59 69 79 89 square = list(map(lambda x: x*x, nums)) • The last node points back to the first node.
29 19 39 49 59 69 79 89 Program:
• No node contains None.
19 29 39 49 59 69 79 89 (after full sorting) Output: [1, 4, 9, 16, 25]
def reverse_string(s):
stack = [] A → B → C → A
Bubble sort continues passes, but the list is already sorted.
# push characters into stack
for char in s: 3) reduce()
[Link](char)
4) Circular Doubly Linked List

Final Sorted List: rev = "" Used to reduce a sequence to a single value (requires functools module). • Combines both doubly + circular structures.
# pop characters from stack
while stack: Syntax: A ↔ B ↔ C (and C ↔ A)
19 29 39 49 59 69 79 89 rev += [Link]()
reduce(function, sequence)
return rev Q4(a) Traverse the following tree using preorder, inorder and
# test Example: postorder traversal techniques.
c) Write a program to create singly linked list. [4] string = "HELLO"
print("Original:", string) from functools import reduce Edges:
print("Reversed:", reverse_string(string)) total = reduce(lambda x, y: x + y, nums)
Python Program for Singly Linked List
• a → b, a → c
Output: Output: 15 • b→d
class Node:
def __init__(self, data):
Original: HELLO • c → e, c → f
[Link] = data
Reversed: OLLEO • e→g
[Link] = None
• f → h, f → i
class LinkedList: c) Explain the types of linked list. [4]
def __init__(self): So the tree structure is:
[Link] = None b) Describe the use of filter(), map() and reduce() functions in A linked list is a dynamic data structure made of nodes, and each node has:
# insert at end Python. [4] /
a
\
def insert(self, data): • data b c
new_node = Node(data) 1) filter() • pointer to the next node / / \
d e f
if [Link] is None: / / \
[Link] = new_node Used to filter elements from a sequence based on a condition. Types of Linked Lists: g h i
return
Syntax:
temp = [Link] Preorder (Root → Left → Right)
while [Link]: filter(function, sequence)
temp = [Link] 1) Singly Linked List Visit:
[Link] = new_node
Example: • Each node points to the next node.
# display list • a, b, d, c, e, g, f, h, i
• Traversal in one direction only.
def display(self): nums = [1, 2, 3, 4, 5]
temp = [Link] even = list(filter(lambda x: x % 2 == 0, nums)) Preorder: a b d c e g f h i
while temp: A → B → C → None
print([Link], end=" -> ")
temp = [Link] Output: [2, 4]
print("None")
2) Doubly Linked List
# Using the linked list
Inorder (Left → Root → Right)
LL = LinkedList() • Each node has two pointers:
[Link](10) 2) map() o next node Visit:
[Link](20) o previous node
[Link](30) Used to apply a function to each element of a sequence. • d, b, a, g, e, c, h, f, i
[Link]() Allows traversal in both directions.
Syntax: Inorder: d b a g e c h f i
None ← A ↔ B ↔ C → None
Output: map(function, sequence)

10 -> 20 -> 30 -> None


Postorder (Left → Right → Root) Q4(c) Write a Python program to check given number is prime or So, the edges are: 2) Append new element at end

Visit: not. [4] • 1→2 [Link](40) # [10, 99, 30, 40]


• 1→3
• d, b, g, e, h, i, f, c, a Program: • 2→1 3) Insert at specific position
• 2→3
Postorder: d b g e h i f c a num = int(input("Enter a number: ")) • 3→4 [Link](1, 15) # insert 15 at index 1
# [10, 15, 99, 30, 40]
• 4→1
if num <= 1:
print(num, "is not a prime number") 4) Extend list with another list
else: You can draw 4 circles (1, 2, 3, 4) and arrows as per the above connections.
is_prime = True lst2 = [50, 60]
Q4(b) Explain the graph traversal methods. [4] for i in range(2, int(num**0.5) + 1): [Link](lst2) # [10, 15, 99, 30, 40, 50, 60]
if num % i == 0:
Two main graph traversal methods are: is_prime = False
break ii) Draw Adjacency List 5) Update using slicing

1) DFS – Depth First Search if is_prime: Write for each vertex the list of nodes it points to: lst[0:2] = [1, 2] # replace first two elements
print(num, "is a prime number") # [1, 2, 99, 30, 40, 50, 60]
else:
• Goes deep into the graph before backtracking. • 1: 2, 3
print(num, "is not a prime number")
• Uses Stack (can be implemented using recursion). • 2: 1, 3 So, updating a list means changing, inserting, or adding elements using index, append(), insert(),
• 3: 4 extend(), or slicing.
This program:
Idea: • 4: 1

1. Start from a node.




Rejects 0 and 1 as non-prime
Checks divisors from 2 to √num Adjacency List form:
a) Explain the concept of Priority Queue. [4]
2. Visit an unvisited neighbour.
• Prints whether the number is prime or not prime
3. Go as deep as possible. • 1 → 2, 3 A Priority Queue is a special type of queue where each element has a priority, and the element with the
4. Backtrack when no unvisited neighbour. • 2 → 1, 3 highest priority is removed first — not the element that came first.
Q4) Attempt the following : [12] • 3→4
Uses: • 4→1 Key Features:

• Path finding • Works on priority, not FIFO.


• Detecting cycles a) Consider the following adjacency matrix. • Higher priority → served first.
• Topological sort b) Write a Python program to print factorial of a given number. [4] • If two elements have same priority → served in normal queue order.
Adjacency Matrix:
We can do this using a loop: Types of Priority Queue:
1 2 3 4
2) BFS – Breadth First Search 1 0 1 1 0 num = int(input("Enter a number: ")) 1. Ascending Priority Queue
2 1 0 1 0 Minimum value has highest priority.
if num < 0:
• Visits nodes level by level (like waves). 3 0 0 0 1 Example: Serving smallest element first.
print("Factorial does not exist for negative numbers")
• Uses a Queue. 4 1 0 0 0 elif num == 0 or num == 1: 2. Descending Priority Queue
print("Factorial of", num, "is 1") Maximum value has highest priority.
Idea: else: Example: Serving largest element first.
Here, 1 = edge present, 0 = no edge. fact = 1
This is a directed graph (because matrix is not symmetric). for i in range(1, num + 1):
1. Start from a node and visit it. fact *= i Example:
2. Visit all its neighbours. print("Factorial of", num, "is", fact)
3. Then visit neighbours’ neighbours. Insert elements with priority:
(50, priority 2), (20, priority 5), (80, priority 1)
i) Draw the graph (Describe edges)
Uses: c) How to update a Python list? [4]
Deletion order:
From the matrix:
• Finding shortest path in unweighted graphs 20 → 50 → 80 (because 5 > 2 > 1)
We can update (modify) a list in many ways because lists are mutable.
• Level order traversal in trees
• Row 1: 1 → 2, 1 → 3
• Network broadcasting 1) Change element by index Applications:
• Row 2: 2 → 1, 2 → 3
• Row 3: 3 → 4
lst = [10, 20, 30] • CPU scheduling
• Row 4: 4 → 1
lst[1] = 99 # change 20 to 99 • Dijkstra shortest path algorithm
# lst becomes [10, 99, 30] • Emergency hospital system

• Printer task management square = lambda x: x*x Datatypes define the type of data a variable can store. Python supports several built-in datatypes:
print(square(5)) 4) Mapping Types
Output: 25 a) Dictionary (dict)

b) Explain list comprehension with suitable 1) Numeric Types •



Stores data as key–value pairs.

example. [4]
Mutable.
2) Lambda with multiple arguments • int → whole numbers
Example: 10, -5 Example: {"name": "Raj", "age": 20}
add = lambda a, b: a + b • float → decimal numbers
List comprehension is a short, compact, and elegant way to create lists in Python. print(add(3, 7)) Example: 3.14
• complex → numbers with real and imaginary part
General Syntax: Output: 10 Example: 3 + 5j
5) Boolean Type
new_list = [expression for item in iterable if condition]
• Represents True or False.
Example 1: Create a list of squares • Used for conditions.
3) Lambda with no argument 2) Sequence Types
squares = [x*x for x in range(1, 6)] Example:
print(squares) hello = lambda : "Hello World"
print(hello()) a) String (str) is_active = True

Output:
[1, 4, 9, 16, 25] • Collection of characters enclosed in quotes.
4) Lambda inside map() • Immutable.
Example 2: Get only even numbers 6) None Type
nums = [1, 2, 3, 4] Example: "Hello"
double = list(map(lambda x: x*2, nums))
evens = [x for x in range(10) if x % 2 == 0] Represents no value or null.
print(evens) b) List (list)
Output: [2, 4, 6, 8]
Example:
Output: • Ordered, mutable collection. x = None
[0, 2, 4, 6, 8] • Allows duplicate values.

Benefits: 5) Lambda inside filter() Example: [10, 20, 30]

• Shorter code even = list(filter(lambda x: x % 2 == 0, nums))


c) Tuple (tuple) b) Applications of Stack and Queue [6 Marks]
• Faster execution
• Easy to read and write Output: [2, 4]
• Ordered, immutable collection.

Example: (1, 2, 3) Stack Applications (LIFO)


c) What is lambda function? Explain its forms in
6) Lambda inside reduce()
1. Function Call Management
Stack stores function calls and returns (call stack).
detail. [4]
from functools import reduce
total = reduce(lambda x, y: x + y, nums) 3) Set Types 2. Undo/Redo Operations
Used in editors like MS Word or code editors.
Output: 10 a) Set (set) 3. Expression Evaluation
A lambda function is a small, anonymous (nameless) function in Python.
Converting infix to postfix, evaluating postfix.
It can have any number of arguments, but only one expression.
• Unordered collection of unique items. 4. Backtracking
Maze solving, DFS uses stack.
Syntax: 5. Memory Management
Advantages: Example: {10, 20, 30}
lambda arguments: expression
Local variables of a function stored in stack.
• Quick one-line functions b) Frozen Set (frozenset)
• Used in functional programming
• Useful with map(), filter(), reduce()
Forms of Lambda Function • Same as set but immutable.
Queue Applications (FIFO)
1) Lambda with one argument a) Datatypes in Python [6 Marks]
1. CPU Scheduling • Used in dictionaries & sets. 𝐴+𝐵−7
Ready queue stores processes waiting for the CPU.
2. Printer Spooling c) Explain any two decision-making statements with example. [4]
Documents are printed in order of arrival.
3. Customer Service Systems
Like call centers, ticket counters.
4) Depth First Search (DFS) — for graphs Prefix (− + A B 7) Decision-making statements control the flow of the program based on conditions.
4. BFS (Breadth First Search)
• Goes deep into graph using stack/recursion.
Graph traversal uses queue. Substitute A and B:
5. Network Packet Handling
Packets processed in order received. 5) Breadth First Search (BFS) — for graphs Prefix: 1) if Statement
6. Operating System Task Management
IO buffer, job scheduling. • Traverses level-by-level using queue. -+*pθ/Rs7 Executes a block only if a condition is true.

Syntax:

c) Searching Techniques [6 Marks] Applications of Searching


Postfix (A B + 7 -)
if condition:
statements

• Database indexing
Searching is the process of finding an element in a data structure. Substitute A and B: Example:
• File search in OS
• Dictionary lookup age = 20
• AI path finding Postfix: if age >= 18:
• Data analysis print("Eligible to vote")
1) Linear Search pθ*Rs/+7-

• Checks each element one-by-one.


a) Convert p * θ + R / s – 7 into Prefix & Postfix expression. [4]
2) if–else Statement
• Works on unsorted or sorted lists.
• Simple but slow for large data (O(n)). Given infix expression:
b) Write a note on Priority Queue. [4] Runs one block if condition is true, otherwise runs the second block.
𝑅
Example: 𝑝∗𝜃+ −7 Syntax:
𝑠 A Priority Queue is an advanced type of queue in which each element has a priority, and the element with
the highest priority is removed first instead of following FIFO.
Search 40 in [10, 20, 30, 40] → found at index 3. if condition:
Let’s break it step-by-step: Key Points:
statements
else:
statements
Sub-expression 1: • Highest priority item is served first.
2) Binary Search • If two items have same priority → they follow normal queue order. Example:
p * θ
• Implemented using:
• Works on sorted lists only. o Heap num = 5
• Divides the list into halves repeatedly. • Prefix: * p θ o Array if num % 2 == 0:
• Much faster (O(log n)). • Postfix: p θ * o Linked list
print("Even")
else:
print("Odd")
Process: Sub-expression 2: Types of Priority Queue:
1. Find middle element. R / s
1. Max Priority Queue → highest value served first.
a) Explain the basic list operations (any two). [4]
2. Compare target with middle. 2. Min Priority Queue → smallest value served first.
3. Go left or right accordingly. • Prefix: / R s A list in Python supports many operations.
4. Repeat until element found or list ends. • Postfix: R s / Any two basic list operations are:
Applications:
Main Expression: • CPU scheduling
• Dijkstra shortest path
(p * θ) + (R / s) - 7 1) append() – Add element at end
3) Hash-Based Search Let A = p * θ
• Hospital emergency system
• Job scheduling in OS
Let B = R / s Adds a new element to the last position of the list.
• Uses a hash function to map key → index.
• Extremely fast (O(1) average). Priority Queue helps in handling tasks based on importance rather than arrival time.
Full infix: Example:

numbers = [10, 20, 30] 3) discard() 1) Using key A Queue is a linear data structure that works on FIFO (First In First Out) principle.
[Link](40)
print(numbers)
The element inserted first is removed first.
Removes element but does not give error if element is missing. print(d["name"])

Output: Four Queue Operations Using Python


[10, 20, 30, 40] [Link](50) 2) Using get()
print([Link]("city"))
4) union() 1) Enqueue (Insert element at rear)
2) insert() – Add element at specific index 3) Using items()
Returns all elements from both sets. queue = []
for k, v in [Link](): [Link](10) # enqueue
Inserts an element at a given index. print(k, v)
s3 = [Link](s2)

a) Explain Lambda function with syntax and


Example:
2) Dequeue (Remove element from front)
5) intersection()
example. [4]
[Link](1, 15)
print(numbers) if queue:
[Link](0)
Returns only common elements of sets.
Output:
[10, 15, 20, 30] s3 = [Link](s2) A lambda function is a small, anonymous (nameless) function in Python.
It is used for short operations and can have any number of arguments but only one expression. 3) Front / Peek (Access first element)

Syntax: if queue:
6) difference() print("Front element:", queue[0])
(Other possible operations: pop(), remove(), extend(), sort(), reverse())
lambda arguments : expression
Returns elements present in first set but not in second.

s3 = [Link](s2) Example 1: Square of a number 4) isEmpty (Check if queue is empty)


b) Define set. Explain built-in set functions with purpose. [4] square = lambda x: x * x if len(queue) == 0:
print(square(5)) print("Queue is empty")

Set (Definition) c) Define Dictionary. How to create and access values in a


dictionary? [4] Output: 25
A set is an unordered collection of unique elements in Python. 5) Display queue (optional)
It does not allow duplicates. Dictionary (Definition) Example 2: Add two numbers
print(queue)

Example: add = lambda a, b: a + b


A dictionary stores data in the form of key–value pairs. print(add(3, 7))

c) Compare Python List and Array. [4]


Keys must be unique, values may repeat.
s = {10, 20, 30}
Output: 10
Example:
Where Lambda is used? Feature Python List Array (array module)
Built-in Set Functions: student = {"name": "Amit", "age": 20}
Data type Can store different datatypes (int, str, float) Stores same datatype only
• With map() Flexibility Very flexible Less flexible
1) add() • With filter() Memory Uses more memory Uses less memory, efficient
How to Create a Dictionary • With reduce() Speed Slower for numeric operations Faster for numeric operations
Adds an element to the set. • For short inline functions Syntax lst = [1, "a", 3.5] from array import array
arr = array('i', [1, 2, 3])
1) Using {}
[Link](40) Use case General-purpose programming Mathematical / numeric computation
d = {"id": 101, "name": "Sam"}

b) Define Queue. Explain any four Queue


Summary:
2) remove() 2) Using dict()
List → stores mixed data, easy to use, more flexible.
operations using Python. [4]

Removes a specific element; gives error if not found. d = dict(city="Pune", pin=411001) • Array → stores only same-type values, memory efficient, faster for calculations.

a) Define the stack. Write the applications of stack. [4]


[Link](20)
Queue (Definition)
How to Access Values from Dictionary
Definition: c) For following binary tree, list the elements in inorder, # Display queue

preorder and postorder traversal. [4]


def display():
A stack is a linear data structure that works on LIFO (Last In First Out) principle. 2) Non-Linear Data Structures print("Queue:", queue)
The element inserted last is removed first.
Given structure: • Data is arranged hierarchically or in network form. # Using queue
• Traversal is complicated (multiple paths). enqueue(10)
Example: enqueue(20)
• 22 → left: 12, right: 30 enqueue(30)
Stack of plates → last plate kept is removed first. • 12 → left: 8, right: 20 Examples: display()
• 30 → left: 25, right: 40 dequeue()
• Tree display()
• Graph
Tree Diagram: Output Example:
Applications of Stack: 22
10 inserted
/ \
20 inserted
1) Function Call Management 12 30 3) Primitive Data Structures 30 inserted
/ \ / \
Queue: [10, 20, 30]
8 20 25 40
Used in programming languages to store function calls (call stack). • Basic data types supported by programming languages. Deleted: 10
Queue: [20, 30]
2) Undo / Redo Operations Examples: integer, float, boolean, character
1) Inorder Traversal (Left → Root → Right)
Used in editors like MS Word, Photoshop, or code editors. c) Explain Adjacency List and Adjacency Matrix for graph representation. [4]
8 12 20 22 25 30 40
3) Expression Evaluation 4) Non-Primitive Data Structures Graphs can be represented in memory using two common methods:

Used for converting infix → postfix and evaluating expressions. 2) Preorder Traversal (Root → Left → Right) • Complex data types used for better data handling.

4) Backtracking 22 12 8 20 30 25 40 Examples: Lists, Tuples, Stacks, Queues, Trees, Graphs 1) Adjacency Matrix

Used in maze solving, puzzles, DFS in graphs. • Uses a 2D matrix of size V × V (V = number of vertices)
3) Postorder Traversal (Left → Right → Root) Summary:
• 1means edge exists, 0 means no edge
5) Memory Management
Example:
8 20 12 25 40 30 22
Local variables and return addresses stored on stack. Category Examples Vertices: A, B, C
a) Define Data Structure. Explain the types of Data Structure. [4] Linear Array, Stack, Queue, Linked List
ABC
Non-Linear Tree, Graph
Data Structure: A0 1 0
Primitive int, float, char
b) Write a Python program to find factorial of a number. [4] A data structure is a method of organizing and storing data in a computer so that it can be used efficiently.
Non-Primitive lists, sets, tuples
B1 0 1
C0 1 0
Program:
Advantages:
Types of Data Structures: b) Write a Python program for queue using array. [4]
num = int(input("Enter a number: "))
• Easy to check whether an edge exists
if num < 0: 1) Linear Data Structures (Here array is implemented using Python list.)
• Good for dense graphs
print("Factorial does not exist for negative numbers")
else: queue = []
fact = 1 • Data is arranged sequentially (one after another). Disadvantages:
for i in range(1, num + 1): • Traversal happens in a single level. # Enqueue operation
fact *= i def enqueue(item): • Requires more memory (V²)
print("Factorial of", num, "is", fact) Examples: [Link](item)
print(item, "inserted")
This program multiplies numbers from 1 to n to find the factorial. • Array # Dequeue operation
• Linked List def dequeue(): 2) Adjacency List
• Stack if len(queue) == 0:
• Queue print("Queue is empty")
else: • Each vertex keeps a list of its neighbors
print("Deleted:", [Link](0)) • Uses linked list or list of lists

Example: • Implemented using arrays. o Front Examples:


• Memory is allocated contiguously. o Rear +, -, *, /, % (modulus), // (floor division), ** (power)
A → B • Each element stores: • More flexible than a normal queue (FIFO).
B → A, C
o data • Works on both FIFO and LIFO principles. 5 + 3 # 8
C → B 10 % 3 # 1
o index of next element
• Also called cursor implementation.
Advantages:
Features: 2) Relational (Comparison) Operators
• Uses less memory (good for sparse graphs) Types of Deque
• Faster to traverse neighbors Used to compare two values.
• Fixed size (cannot grow/shrink easily)
1) Input Restricted Deque
• Easy to access using index
Disadvantages: Examples:
• Difficult insertion/deletion (shifting required)
• Insertion allowed at one end only. ==, !=, <, >, <=, >=
• Checking a specific edge may be slightly slower • Deletion allowed at both ends.
5 > 3 # True

Dynamic Representation 2) Output Restricted Deque


Comparison Table • Deletion allowed at one end only. 3) Logical Operators
• Implemented using pointers (nodes).
• Insertion allowed at both ends.
• Each node has:
Feature Adjacency Matrix Adjacency List Used for combining conditions.
o data
Space Required High (V²) Low (depends on edges)
o pointer to next node
Edge lookup Fast Slower Examples:
• Memory allocated dynamically from heap.
Best for Dense Graph Sparse Graph Operations on Deque and, or, not

Features:
a) Compare between BFS and DFS traversal. [6]
x > 5 and x < 20
1. insert_front(x) – insert x at front
• Grows/shrinks at runtime 2. insert_rear(x) – insert x at rear
• Efficient insertion and deletion 3. delete_front() – remove item from front
Feature BFS (Breadth First Search) DFS (Depth First Search) 4) Assignment Operators
• Memory used only when needed 4. delete_rear() – remove item from rear
Working Level-by-level traversal Goes deep before backtracking isEmpty() – check if empty
• Access is slower (no index) 5.
principle Used to assign values.
6. display() – show elements
Data structure Queue Stack / Recursion
used Examples:
Starting point Starts from root and visits all Starts from root and explores one path =, +=, -=, *=, /=
neighbors first completely
Comparison Table
Shortest path Finds shortest path in an unweighted Does NOT always find shortest path Applications of Deque a = 10
Feature Static (Array) Dynamic (Pointer) a += 5 # 15
graph
Memory usage High (stores many nodes in queue) Low (only current path stored) Memory Fixed Flexible • Browser history (forward/backward)
Suitable for Trees/Graphs where nearest solution Tree/Graph where deeper solution needed Size change Not possible Possible anytime • Undo/redo operations
needed • Palindrome checking 5) Membership Operators
Insertion Slow Fast
Traversal nature Horizontal movement Vertical movement • Job scheduling
Deletion Slow Fast • Implementing both stacks and queues Used to check membership in sequences.
Storage Contiguous Non-contiguous
Example (Simple idea):
a) Explain various operators in Python
Examples:
in, not in
• BFS → Visit nodes in levels: 1 → 2 → 3 → 4
• DFS → Visit nodes deep: 1 → 2 → 5 → 6 → backtrack → 3
c) Explain the concept of Doubly Ended Queue programming. [4] 5 in [1,2,3,5] # True

(Deque). [6] Python provides different categories of operators used for calculations, comparisons, and logical operations.
6) Identity Operators
b) Explain the static and dynamic representation A Doubly Ended Queue (Deque) is a queue where insertion and deletion can occur from both ends
Check if two variables refer to the same object.
of Linked List. [6]
(front and rear).
1) Arithmetic Operators
Key Features: Examples:
Used for mathematical calculations. is, is not
Static Representation
• Supports enqueue and dequeue from: a is b
c) Write a Python program to print factorial of a
Age: 20
2) Deletion
7) Bitwise Operators Remove an element from the array.
b) What is List? State any four built-in list given number. [4]
Used on bits.
functions with their use. [4]
[Link](20)
Program:
Examples:
&, |, ^, <<, >> num = int(input("Enter a number: "))
3) Accessing Elements (optional) List:
if num < 0:
print("Factorial not possible for negative numbers")
Retrieve element using index. A list is a mutable, ordered collection in Python that can store different types of data. else:

b) What is the difference between a Set and


fact = 1
print(a[2]) # 30 Example: for i in range(1, num + 1):
fact *= i
Dictionary? [4] numbers = [10, 20, 30] print("Factorial of", num, "is", fact)

4) Updating Elements (optional) Explanation:


Feature Set Dictionary
Definition Unordered collection of unique values Collection of key–value pairs Modify an existing value. Four built-in list functions:
• Multiply numbers from 1 to n
Syntax {10, 20, 30} {"name": "Raj", "age": 20}
a[0] = 99 • Store result in fact
Duplicates No Values can repeat, keys must be
a) What are Python’s parameter passing modes? [4]
Allowed? unique
Access Method
Use Case
Cannot access using index or key
Mathematical operations like union,
Access using keys
Store structured information
a) Explain how to create class and object in 1) append()

intersection Python. [4] Adds an item at the end of the list. In Python, arguments are passed to functions using a model called “pass by object reference” (also called
call by sharing).
[Link](40)
Example Set: Class: To understand it simply:
s = {1,2,3}
A class is a blueprint or template for creating objects. 2) insert() • If you pass an immutable object (like int, float, string, tuple) → it behaves like pass by value
It contains variables (attributes) and functions (methods). (original is not changed).
Example Dictionary: Inserts an item at a specific index. • If you pass a mutable object (like list, dict, set) → it behaves like pass by reference (changes
d = {"id": 101, "name": "Amit"} Object: inside function affect original).
[Link](1, 15)

An object is an instance of a class, created using the class name. Example with immutable (int):

c) Explain any two array operations. [4] 3) remove() def change(x):


x = x + 1
Example: Creating Class and Object Removes the first matching element.
Assume Python array using the array module. a = 5
[Link](20) change(a)
from array import array class Student: print(a) # still 5
a = array('i', [10, 20, 30]) def __init__(self, name, age): # constructor
[Link] = name
[Link] = age Example with mutable (list):
4) sort()
1) Insertion def display(self):
print("Name:", [Link])
# method
Sorts the list in ascending order.
def change(lst):
[Link](10)
print("Age:", [Link])
Add a new element at a specific position. [Link]() nums = [1, 2, 3]
# Creating an object change(nums)
[Link](1, 15) s1 = Student("Amit", 20) print(nums) # [1, 2, 3, 10]

# Calling method Other examples: So we can say:


Result: [Link]()
10, 15, 20, 30
pop(), reverse(), extend(), count(), index() (optional) • Python uses pass-by-object-reference
Output: • Immutable → cannot be changed
• Mutable → can be changed inside the function
Name: Amit

c) Write Python program for insert node at start


Prefix (Polish Notation) [Link]() # removes last pushed element

b) What is Queue? Explain types of Queue. [4] Order: Operator → Left → Right
3) peek() — View top element position of Linked List. [4]
• P * Q→* P Q
Queue (Definition)
• R * S→* R S Returns the top element without removing it. Python Program:
• Combine with + → + (* P Q) (* R S)
A Queue is a linear data structure that works on FIFO (First In First Out) principle. top = stack[-1] class Node:
Element inserted first is removed first. def __init__(self, data):
Prefix: [Link] = data
+ * P Q * R S
4) isEmpty() — Check if stack is empty
[Link] = None
Types of Queue:
class LinkedList:
Checks whether the stack has elements. def __init__(self):
[Link] = None
Postfix (Reverse Polish Notation) if len(stack) == 0:
1) Simple / Linear Queue # insert at start
print("Stack is empty")
Order: Left → Right → Operator def insert_start(self, data):
• Insertion (enqueue) at rear new_node = Node(data)
• Deletion (dequeue) from front new_node.next = [Link] # link new node to old head
→P Q *
b) Write the elements in BFS and DFS of the
• P * Q [Link] = new_node # update head
• Example: Line of people at ticket counter
• R * S→R S *
Combine with + at end → P Q * R S * +
following Binary Tree. [4]
• # display list
def display(self):
temp = [Link]
Postfix: while temp:
2) Circular Queue P Q * R S * + print([Link], end=" -> ")
Given Tree:
temp = [Link]

a) What is stack? Explain any four stack
Last position connects back to first position. print("None")
• Solves space wastage of simple queue. • 1 → 2, 3
• 2 → 4, 5 # Using the Linked List

operations in data structure using Python. [4] • 3 → 6, 7 ll = LinkedList()


ll.insert_start(30)
ll.insert_start(20)
3) Priority Queue Tree Diagram: ll.insert_start(10)
Stack Definition
1 [Link]()
• Each element has a priority. A stack is a linear data structure that follows the LIFO (Last In First Out) principle. / \
• Element with higher priority is removed first (not just the oldest one). The element inserted last is removed first. 2 3
/ \ / \ Output:
4 5 6 7
Python can implement a stack using a list. 10 -> 20 -> 30 -> None

a) Inorder, Preorder and Postorder traversal of the


4) Double Ended Queue (Deque)
BFS (Level Order Traversal)
Binary Search Tree [4]
• Insertion and deletion possible from both ends (front and rear).
Four Stack Operations (with Python code) Visit level by level:

1, 2, 3, 4, 5, 6, 7 Given tree:
c) Write Prefix and Postfix Expression of P * Q + R * S . [4] 1) push() — Insert element • 1 → 2, 3
Given infix expression: • 2 → 4, 5
Adds an element to the top of the stack.
DFS (Preorder Traversal: Root → Left → Right) • 3 → 6, 7
𝑃∗𝑄+𝑅∗𝑆 stack = []
[Link](10) # push 1, 2, 4, 5, 3, 6, 7 Tree Structure

This is: 1
/ \
2) pop() — Remove top element 2 3
(𝑃 ∗ 𝑄) + (𝑅 ∗ 𝑆) / \ / \
Removes the element at the top. 4 5 6 7
1) Inorder (Left → Root → Right) c) Explain any two ways of representation of a) What is Python? What are the benefits of using 6) Strong Community Support

Traversal:
4251637
graph. [4] Python? [6 Marks] Millions of developers contribute to Python packages, tutorials, and libraries.

Graphs can be represented in two common ways: What is Python?


7) Extensive Third-Party Libraries
Python is a high-level, interpreted, general-purpose programming language.
2) Preorder (Root → Left → Right) It is simple, readable, and widely used in web development, data science, AI, automation, and more. For example:
1) Adjacency Matrix
Traversal: • NumPy, Pandas → Data Science
1245367
• A 2D matrix of size V × V (V = number of vertices) • Django, Flask → Web
• 1 represents an edge, 0 means no edge. Benefits of Using Python: • TensorFlow → Machine Learning

Example:
3) Postorder (Left → Right → Root)
1) Easy to Learn and Read

Traversal:
For vertices A, B, C: Python has simple English-like syntax, making coding and understanding easier. b) What are the common built-in data types in
4526731 ABC Python? [6 Marks]
A0 1 0
B1 0 1 2) Interpreted Language Python has several built-in data types used to store different kinds of values.

b) Write Python program for stack using list. [4]


C0 1 0 Python executes programs line by line, helping in quick testing and debugging.

Advantages
stack = []
1) Numeric Types
# Push operation • Easy to check if an edge exists. 3) Large Standard Library
def push(item): • Simple representation. • int → whole numbers
[Link](item)
Provides many built-in modules like: • float → decimal values
print("Pushed:", item)
Disadvantages • complex → numbers with real & imaginary part
# Pop operation • math
def pop_item(): • Requires more memory (V² space). • datetime a = 10
b = 3.14
if not stack: • random c = 2 + 5j
print("Stack is empty") • os
else:
• json
print("Popped:", [Link]())

# Peek operation
2) Adjacency List These reduce development time. 2) Sequence Types
def peek():
if not stack: • Each vertex stores a list of its neighbours.
String (str)
print("Stack is empty") • Implemented using list or linked list.
else:
print("Top element:", stack[-1]) 4) Portable and Platform Independent A sequence of characters. Immutable.
Example:
# Display stack name = "Python"
def display(): A → B
Python runs on Windows, Mac, Linux without changing the code.
print("Stack:", stack) B → A, C
C → B List (list)
# Using the stack
push(10) Ordered and mutable collection.
push(20) Advantages 5) Supports Multiple Programming Paradigms
push(30)
colors = ["red", "blue", "green"]
display() • Uses less memory. • Object-Oriented
peek() • Efficient for sparse graphs. • Functional
pop_item()
• Procedural Tuple (tuple)
display()
Disadvantages
Ordered and immutable.
• Checking the existence of a specific edge is slower.

point = (10, 20)

3) Set Types Types of Linked List:


Set (set)

Unordered collection of unique items. 1) Singly Linked List


s = {10, 20, 30} Each node points to the next node only.

Frozen Set (frozenset) A → B → C → None

Immutable version of set. • Simple structure


• Traversal only in one direction

4) Mapping Type
2) Doubly Linked List
Dictionary (dict)
Each node has two pointers:
Stores data in key–value pairs.
• to the next node
student = {"name": "Amit", "age": 20} • to the previous node

None ← A ↔ B ↔ C → None

5) Boolean Type • Allows forward & backward traversal


• Uses more memory
Represents values True or False.

3) Circular Linked List


6) None Type
Last node points back to the first node.
Represents null or no value.
A → B → C → A
x = None
• No node contains None
• Useful in round-robin scheduling
c) What is Linked List? Explain types of Linked
List. [6 Marks]
4) Circular Doubly Linked List
Linked List (Definition)
Combination of circular and doubly linked list.
A linked list is a dynamic data structure made up of nodes, where each node contains:
A ↔ B ↔ C ↔ A

• data
• Supports two-way circular movement
• pointer to the next node

Nodes are connected using pointers, not stored in continuous memory.

You might also like