Click on Subject/Paper under Semester to enter.
Professional English Discrete Mathematics Environmental Sciences
Professional English - - II - HS3252 - MA3354 and Sustainability -
I - HS3152 GE3451
Digital Principles and
Statistics and Probability and
Computer Organization
Matrices and Calculus Numerical Methods - Statistics - MA3391
- CS3351
- MA3151 MA3251
3rd Semester
1st Semester
4th Semester
2nd Semester
Database Design and Operating Systems -
Engineering Physics - Engineering Graphics
Management - AD3391 AL3452
PH3151 - GE3251
Physics for Design and Analysis of Machine Learning -
Engineering Chemistry Information Science Algorithms - AD3351 AL3451
- CY3151 - PH3256
Data Exploration and Fundamentals of Data
Basic Electrical and
Visualization - AD3301 Science and Analytics
Problem Solving and Electronics Engineering -
BE3251 - AD3491
Python Programming -
GE3151 Artificial Intelligence
Data Structures Computer Networks
- AL3391
Design - AD3251 - CS3591
Deep Learning -
AD3501
Embedded Systems
Data and Information Human Values and
and IoT - CS3691
5th Semester
Security - CW3551 Ethics - GE3791
6th Semester
7th Semester
8th Semester
Open Elective-1
Distributed Computing Open Elective 2
- CS3551 Project Work /
Elective-3
Open Elective 3 Intership
Big Data Analytics - Elective-4
CCS334 Open Elective 4
Elective-5
Elective 1 Management Elective
Elective-6
Elective 2
All Computer Engg Subjects - [ B.E., M.E., ] (Click on Subjects to enter)
Programming in C Computer Networks Operating Systems
Programming and Data Programming and Data Problem Solving and Python
Structures I Structure II Programming
Database Management Systems Computer Architecture Analog and Digital
Communication
Design and Analysis of Microprocessors and Object Oriented Analysis
Algorithms Microcontrollers and Design
Software Engineering Discrete Mathematics Internet Programming
Theory of Computation Computer Graphics Distributed Systems
Mobile Computing Compiler Design Digital Signal Processing
Artificial Intelligence Software Testing Grid and Cloud Computing
Data Ware Housing and Data Cryptography and Resource Management
Mining Network Security Techniques
Service Oriented Architecture Embedded and Real Time Multi - Core Architectures
Systems and Programming
Probability and Queueing Theory Physics for Information Transforms and Partial
Science Differential Equations
Technical English Engineering Physics Engineering Chemistry
Engineering Graphics Total Quality Professional Ethics in
Management Engineering
Basic Electrical and Electronics Problem Solving and Environmental Science and
and Measurement Engineering Python Programming Engineering
lOMoARcPSD|45333583
[Link]
AD3271
DATA STRUCTURES DESIGN LABORATORY
SEM-II
REGULATION 2021
DEPARTMENT OF
ARTIFICIAL INTELLIGENCE AND DATA SCIENCE
PREPARED BY
[Link] M.E.,
AP/CSE
EXNO:1 Implement simple ADTs as Python classes
class Stack:
def __init__(self):
[Link] = []
def is_empty(self):
return [Link] == []
def push(self, data):
[Link](data)
def pop(self):
return [Link]()
s = Stack()
while True:
print('push <value>')
print('pop')
print('quit')
do = input('What would you like to do? ').split()
operation = do[0].strip().lower()
if operation == 'push':
[Link](int(do[1]))
elif operation == 'pop':
if s.is_empty():
print('Stack is empty.')
[Link] 1
lOMoARcPSD|45333583
[Link]
else:
print('Popped value: ', [Link]())
elif operation == 'quit':
break
OUTPUT:
push <value>
pop
quit
What would you like to do? push 7
push <value>
pop
quit
What would you like to do? push 5
push <value>
pop
quit
What would you like to do? push 9
push <value>
pop
quit
What would you like to do? pop
Popped value: 9
push <value>
pop
quit
What would you like to do? pop
Popped value: 5
EXNO:2 Implement recursive algorithms in Python
Program:
class mine:
def recur(self, num):
print(num, end="")
if num > 1:
print(" + ",end="")
return num + [Link](self, num-1)
print(" =")
return 1
def main():
a = mine()
print([Link](mine, 10))
main()
OUTPUT:10 + 9 + 8 + 7 + 6 + 5 + 4 + 3 + 2 + 1 =
55
[Link] 2
lOMoARcPSD|45333583
[Link]
EXNO:3 ARRAY IMPLEMENTATION OF LIST
Program:
class ArrayList:
def __init__(self):
[Link] = 10 # initial capacity of the array
[Link] = 0 # current number of elements in the list
[Link] = [None] * [Link] # array to store the elements
def __len__(self):
return [Link]
def is_empty(self):
return [Link] == 0
def __getitem__(self, index):
if not 0 <= index < [Link]:
raise IndexError("Index out of range")
return [Link][index]
def append(self, element):
if [Link] == [Link]:
self._resize(2 * [Link]) # double the capacity if the array is full
[Link][[Link]] = element
[Link] += 1
def insert(self, index, element):
if not 0 <= index <= [Link]:
raise IndexError("Index out of range")
if [Link] == [Link]:
self._resize(2 * [Link])
for i in range([Link], index, -1):
[Link][i] = [Link][i - 1]
[Link][index] = element
[Link] += 1
def remove(self, element):
for i in range([Link]):
if [Link][i] == element:
self._shift_left(i)
[Link] -= 1
if [Link] <= [Link] // 4:
self._resize([Link] // 2)
return
raise ValueError("Element not found")
[Link] 3
lOMoARcPSD|45333583
[Link]
def _shift_left(self, start_index):
for i in range(start_index, [Link] - 1):
[Link][i] = [Link][i + 1]
[Link][[Link] - 1] = None
def _resize(self, new_capacity):
new_array = [None] * new_capacity
for i in range([Link]):
new_array[i] = [Link][i]
[Link] = new_array
[Link] = new_capacity
my_list = ArrayList()
my_list.append(10)
my_list.append(20)
my_list.append(30)
print(len(my_list))
print(my_list[1])
my_list.insert(1, 15)
print(my_list[1])
my_list.remove(20)
print(len(my_list))
Output:
3
20
15
3
EXNO:4 Linked list implementations of List
class Node:
def __init__(self, data):
[Link] = data
[Link] = None
class LinkedList:
def __init__(self):
[Link] = None
[Link] = None
[Link] 4
lOMoARcPSD|45333583
[Link]
[Link] = 0
def __len__(self):
return [Link]
def is_empty(self):
return [Link] == 0
def append(self, data):
new_node = Node(data)
if self.is_empty():
[Link] = new_node
[Link] = new_node
else:
[Link] = new_node
[Link] = new_node
[Link] += 1
def insert(self, index, data):
if not 0 <= index <= [Link]:
raise IndexError("Index out of range")
if index == 0:
new_node = Node(data)
new_node.next = [Link]
[Link] = new_node
if [Link] is None:
[Link] = new_node
elif index == [Link]:
[Link](data)
else:
new_node = Node(data)
prev_node = self._get_node(index - 1)
new_node.next = prev_node.next
prev_node.next = new_node
[Link] += 1
def remove(self, data):
if self.is_empty():
raise ValueError("List is empty")
if [Link] == data:
if [Link] == [Link]:
[Link] = None
[Link] = [Link]
[Link] -= 1
return
prev_node = [Link]
curr_node = [Link]
while curr_node is not None:
if curr_node.data == data:
prev_node.next = curr_node.next
if curr_node == [Link]:
[Link] 5
lOMoARcPSD|45333583
[Link]
[Link] = prev_node
[Link] -= 1
return
prev_node = curr_node
curr_node = curr_node.next
raise ValueError("Element not found")
def __getitem__(self, index):
if not 0 <= index < [Link]:
raise IndexError("Index out of range")
node = self._get_node(index)
return [Link]
def _get_node(self, index):
node = [Link]
for _ in range(index):
node = [Link]
return node
my_list = LinkedList()
my_list.append(10)
my_list.append(20)
my_list.append(30)
print(len(my_list))
print(my_list[1])
Output:
3
20
Ex no :5a Implementation of Stack ADTs
[Link] 6
lOMoARcPSD|45333583
[Link]
class Stack:
def __init__(self):
[Link] = []
def is_empty(self):
return len([Link]) == 0
def push(self, item):
[Link](item)
def pop(self):
if self.is_empty():
raise ValueError("Stack is empty")
return [Link]()
def peek(self):
if self.is_empty():
raise ValueError("Stack is empty")
return [Link][-1]
def size(self):
return len([Link])
my_stack = Stack()
print(my_stack.is_empty())
my_stack.push(10)
my_stack.push(20)
my_stack.push(30)
print(my_stack.size())
print(my_stack.peek())
print(my_stack.pop())
print(my_stack.size())
Output:
True
3
30
30
2
[Link] 7
lOMoARcPSD|45333583
[Link]
Ex no: 5b Implementation of Queue ADTs
class Queue:
def __init__(self):
[Link] = []
def is_empty(self):
return len([Link]) == 0
def enqueue(self, item):
[Link](item)
def dequeue(self):
if self.is_empty():
raise ValueError("Queue is empty")
return [Link](0)
def front(self):
if self.is_empty():
raise ValueError("Queue is empty")
return [Link][0]
def size(self):
return len([Link])
my_queue = Queue()
print(my_queue.is_empty())
my_queue.enqueue(10)
my_queue.enqueue(20)
my_queue.enqueue(30)
print(my_queue.size())
print(my_queue.front())
print(my_queue.dequeue())
print(my_queue.size())
Output:
True
3
10
10
2
[Link] 8
lOMoARcPSD|45333583
[Link]
EX NO:6a APPLICATION OF LIST - IMPLEMENT DYNAMIC ARRAY
class DynamicArray:
def __init__(self):
[Link] = []
def size(self):
return len([Link])
def is_empty(self):
return [Link]() == 0
def append(self, value):
[Link](value)
def insert(self, index, value):
if index < 0 or index > [Link]():
raise IndexError("Index out of range")
[Link](index, value)
def remove(self, index):
if index < 0 or index >= [Link]():
raise IndexError("Index out of range")
return [Link](index)
def __str__(self):
return str([Link])
my_array = DynamicArray()
print(my_array.is_empty()) # True
my_array.append(10)
my_array.append(20)
my_array.append(30)
print(my_array.size())
print(my_array)
print(my_array.is_empty())
my_array.insert(1, 15)
print(my_array)
my_array.remove(0)
print(my_array)
OUTPUT:
True
3
[10, 20, 30]
False
[10, 15, 20, 30]
[15, 20, 30]
[Link] 9
lOMoARcPSD|45333583
[Link]
EX NO 6B APPLICATION OF STACK - BALANCED SYMBOLS
def is_balanced(expression):
stack = []
opening_brackets = ['(', '[', '{']
closing_brackets = [')', ']', '}']
bracket_pairs = {'(': ')', '[': ']', '{': '}'}
for char in expression:
if char in opening_brackets:
[Link](char)
elif char in closing_brackets:
if len(stack) == 0:
return False
top = [Link]()
if bracket_pairs[top] != char:
return False
return len(stack) == 0
expressions = ["(())", "[{()}]", "({[}])", "((())", "{[()}]"]
for exp in expressions:
if is_balanced(exp):
print(f"{exp} is balanced.")
else:
print(f"{exp} is not balanced.")
OUTPUT:
(()) is balanced.
[{()}] is balanced.
({[}]) is not balanced.
((()) is not balanced.
{[()}] is not balanced.
[Link] 10
lOMoARcPSD|45333583
[Link]
EXNO 6C APPLICATIONS OF QUEUE-BREADTH FIRST TRAVERSAL
from collections import deque
class Graph:
def __init__(self):
self.adj_list = {}
def add_edge(self, vertex, neighbor):
if vertex not in self.adj_list:
self.adj_list[vertex] = []
self.adj_list[vertex].append(neighbor)
def bfs(self, start_vertex):
visited = set()
queue = deque([start_vertex])
[Link](start_vertex)
while queue:
current_vertex = [Link]()
print(current_vertex, end=" ") # Process the vertex
if current_vertex in self.adj_list:
for neighbor in self.adj_list[current_vertex]:
if neighbor not in visited:
[Link](neighbor)
[Link](neighbor)
graph = Graph()
graph.add_edge('A', 'B')
graph.add_edge('A', 'C')
graph.add_edge('B', 'D')
graph.add_edge('B', 'E')
graph.add_edge('C', 'F')
[Link]('A')
OUTPUT:
ABCDEF
[Link] 11
lOMoARcPSD|45333583
[Link]
EX NO:7A. Implementation of sorting algorithms-SELECTION SORT
def selection_sort(arr):
n = len(arr)
for i in range(n):
min_index = i
for j in range(i+1, n):
if arr[j] < arr[min_index]:
min_index = j
arr[i], arr[min_index] = arr[min_index], arr[i]
my_array = [64, 34, 25, 12, 22, 11, 90]
print("Original array:", my_array)
selection_sort(my_array)
print("Sorted array:", my_array)
OUTPUT:
Original array: [64, 34, 25, 12, 22, 11, 90]
Sorted array: [11, 12, 22, 25, 34, 64, 90]
EXNO:7B IMPLEMENTATION OF SEARCHING ALGORITHM-LINEAR SEARCH
def linear_search(arr, target):
[Link] 12
lOMoARcPSD|45333583
[Link]
for i in range(len(arr)):
if arr[i] == target:
return i
return -1
my_array = [4, 2, 7, 1, 9, 5]
target_element = 7
result = linear_search(my_array, target_element)
if result != -1:
print("Element", target_element, "found at index", result)
else:
print("Element", target_element, "not found in the array.")
OUTPUT:
Element 7 found at index 2
EXNO :8 Implementation of Hash tables
class HashTable:
def __init__(self, size):
[Link] = size
[Link] = [[] for _ in range(size)]
def _hash_function(self, key):
return hash(key) % [Link]
def insert(self, key, value):
index = self._hash_function(key)
for item in [Link][index]:
if item[0] == key:
item[1] = value # Update value if key already exists
return
[Link][index].append((key, value)) # Add new key-value pair
def delete(self, key):
index = self._hash_function(key)
bucket = [Link][index]
for i in range(len(bucket)):
if bucket[i][0] == key:
del bucket[i] # Remove key-value pair if found
return
def search(self, key):
index = self._hash_function(key)
[Link] 13
lOMoARcPSD|45333583
[Link]
for item in [Link][index]:
if item[0] == key:
return item[1]
return None
hash_table = HashTable(10)
hash_table.insert("apple", 5)
hash_table.insert("banana", 2)
hash_table.insert("cherry", 8)
print(hash_table.search("apple"))
print(hash_table.search("banana"))
print(hash_table.search("grape"))
hash_table.delete("banana")
print(hash_table.search("banana"))
OUTPUT:
5
2
NONE
NONE
EXNO:9 Tree representation and traversal algorithms
class Node:
def __init__(self, data):
[Link] = data
[Link] = None
[Link] = None
def in_order_traversal(node):
if node is not None:
in_order_traversal([Link])
print([Link], end=" ")
in_order_traversal([Link])
def pre_order_traversal(node):
if node is not None:
print([Link], end=" ")
pre_order_traversal([Link])
pre_order_traversal([Link])
def post_order_traversal(node):
if node is not None:
post_order_traversal([Link])
[Link] 14
lOMoARcPSD|45333583
[Link]
post_order_traversal([Link])
print([Link], end=" ")
root = Node(1)
[Link] = Node(2)
[Link] = Node(3)
[Link] = Node(4)
[Link] = Node(5)
print("In-order traversal:")
in_order_traversal(root)
print()
print("Pre-order traversal:")
pre_order_traversal(root)
print()
print("Post-order traversal:")
post_order_traversal(root)
print()
OUTPUT:
In-order traversal:
42513
Pre-order traversal:
12453
Post-order traversal:
45231
EX NO:10. Implementation of Binary Search Trees
class TreeNode:
def __init__(self, key):
[Link] = key
self.l = None
self.r = None.
def new_key_insert(root, new_key):
if the root is None:
root = TreeNode(new_key)
return root
if new_key < [Link]:
root.l = new_key_insert(root.l, new_key)
else:
root.r = new_key_insert(root.r, new_key)
return root
[Link] 15
lOMoARcPSD|45333583
[Link]
def display(root):
if root:
display(root.l)
print([Link])
display(root.r
r = TreeNode(50)
r = new_key_insert(r, 30)
r = new_key_insert(r, 20)
r = new_key_insert(r, 40)
r = new_key_insert(r, 70)
r = new_key_insert(r, 60)
r = new_key_insert(r, 80)
display(r)
OUTPUT:
20
30
40
50
60
70
80
EXNO:11 Implementation of Heaps
def min_heapify(A,k):
l = left(k)
r = right(k)
if l < len(A) and A[l] < A[k]:
smallest = l
else:
smallest = k
if r < len(A) and A[r] < A[smallest]:
smallest = r
if smallest != k:
[Link] 16
lOMoARcPSD|45333583
[Link]
A[k], A[smallest] = A[smallest], A[k]
min_heapify(A, smallest)
def left(k):
return 2 * k + 1
def right(k):
return 2 * k + 2
def build_min_heap(A):
n = int((len(A)//2)-1)
for k in range(n, -1, -1):
min_heapify(A,k)
A = [3,9,2,1,4,5]
build_min_heap(A)
print(A)
OUTPUT: [1, 3, 2, 9, 4, 5]
EXNO:12A. Graph representation
graph = dict()
def addEdge(node1, node2):
# create an empty list for a key node
if node1 not in graph:
graph[node1] = []
if node2 not in graph:
graph[node2] = []
graph[node1].append(node2)
def main():
addEdge('A', 'B')
addEdge('A', 'C')
addEdge('B', 'D')
addEdge('B', 'E')
addEdge('C', 'D')
addEdge('D', 'A')
addEdge('D', 'E')
for key, val in [Link]():
print(f"{key}-->{val}")
if __name__=="__main__":
main()
EX NO:12B Traversal algorithms
class Graph:
def __init__(self):
self.adj_list = {}
def add_edge(self, vertex, neighbor):
if vertex not in self.adj_list:
self.adj_list[vertex] = []
[Link] 17
lOMoARcPSD|45333583
[Link]
self.adj_list[vertex].append(neighbor)
def dfs(self, start_vertex):
visited = set()
self._dfs_helper(start_vertex, visited)
def _dfs_helper(self, vertex, visited):
[Link](vertex)
print(vertex, end=" ")
if vertex in self.adj_list:
for neighbor in self.adj_list[vertex]:
if neighbor not in visited:
self._dfs_helper(neighbor, visited)
graph = Graph()
graph.add_edge('A', 'B')
graph.add_edge('A', 'C')
graph.add_edge('B', 'D')
graph.add_edge('B', 'E')
graph.add_edge('C', 'F')
[Link]('A') OUTPUT: A B D E C
EXNO:13. Implementation of single source shortest path algorithm
import heapq
class Graph:
def __init__(self):
[Link] = {}
def add_vertex(self, vertex):
[Link][vertex] = {}
def add_edge(self, source, destination, weight):
[Link][source][destination] = weight
def dijkstra(self, start_vertex):
distances = {vertex: float('inf') for vertex in [Link]}
distances[start_vertex] = 0
heap = [(0, start_vertex)]
while heap:
current_distance, current_vertex = [Link](heap)
if current_distance > distances[current_vertex]:
continue
for neighbor, weight in [Link][current_vertex].items():
distance = current_distance + weight
if distance < distances[neighbor]:
distances[neighbor] = distance
[Link](heap, (distance, neighbor))
return distances
graph = Graph()
graph.add_vertex("A")
graph.add_vertex("B")
graph.add_vertex("C")
graph.add_vertex("D")
[Link] 18
lOMoARcPSD|45333583
[Link]
graph.add_vertex("E")
graph.add_edge("A", "B", 4)
graph.add_edge("A", "C", 2)
graph.add_edge("B", "E", 3)
graph.add_edge("C", "D", 2)
graph.add_edge("D", "E", 3)
graph.add_edge("C", "E", 1)
start_vertex = "A"
distances = [Link](start_vertex)
for vertex, distance in [Link]():
print(f"Shortest distance from {start_vertex} to {vertex}: {distance}")
OUTPUT:
Shortest distance from A to A: 0
Shortest distance from A to B: 4
Shortest distance from A to C: 2
Shortest distance from A to D: 4
Shortest distance from A to E: 3
EXNO:14 Implementation of minimum spanning tree algorithms
import heapq
class Graph:
def __init__(self):
[Link] = {}
def add_vertex(self, vertex):
[Link][vertex] = {}
def add_edge(self, source, destination, weight):
[Link][source][destination] = weight
[Link][destination][source] = weight
def prim(self):
visited = set()
min_heap = []
minimum_spanning_tree = []
start_vertex = next(iter([Link]))
[Link](start_vertex)
for neighbor, weight in [Link][start_vertex].items():
[Link](min_heap, (weight, start_vertex, neighbor))
while min_heap:
weight, source, destination = [Link](min_heap)
if destination in visited:
continue
[Link](destination)
minimum_spanning_tree.append((source, destination, weight))
[Link] 19
lOMoARcPSD|45333583
[Link]
for neighbor, weight in [Link][destination].items():
if neighbor not in visited:
[Link](min_heap, (weight, destination, neighbor))
return minimum_spanning_tree
graph = Graph()
graph.add_vertex("A")
graph.add_vertex("B")
graph.add_vertex("C")
graph.add_vertex("D")
graph.add_vertex("E")
graph.add_edge("A", "B", 4)
graph.add_edge("A", "C", 2)
graph.add_edge("B", "E", 3)
graph.add_edge("C", "D", 2)
graph.add_edge("D", "E", 3)
graph.add_edge("C", "E", 1)
minimum_spanning_tree = [Link]()
print("Minimum Spanning Tree:")
for edge in minimum_spanning_tree:
source, destination, weight = edge
print(f"{source} -- {destination} : {weight}")
OUTPUT: Minimum Spanning Tree:
A -- C : 2
C -- E : 1
C -- D : 2
D -- E : 3
[Link] 20
Click on Subject/Paper under Semester to enter.
Professional English Discrete Mathematics Environmental Sciences
Professional English - - II - HS3252 - MA3354 and Sustainability -
I - HS3152 GE3451
Digital Principles and
Statistics and Probability and
Computer Organization
Matrices and Calculus Numerical Methods - Statistics - MA3391
- CS3351
- MA3151 MA3251
3rd Semester
1st Semester
4th Semester
2nd Semester
Database Design and Operating Systems -
Engineering Physics - Engineering Graphics
Management - AD3391 AL3452
PH3151 - GE3251
Physics for Design and Analysis of Machine Learning -
Engineering Chemistry Information Science Algorithms - AD3351 AL3451
- CY3151 - PH3256
Data Exploration and Fundamentals of Data
Basic Electrical and
Visualization - AD3301 Science and Analytics
Problem Solving and Electronics Engineering -
BE3251 - AD3491
Python Programming -
GE3151 Artificial Intelligence
Data Structures Computer Networks
- AL3391
Design - AD3251 - CS3591
Deep Learning -
AD3501
Embedded Systems
Data and Information Human Values and
and IoT - CS3691
5th Semester
Security - CW3551 Ethics - GE3791
6th Semester
7th Semester
8th Semester
Open Elective-1
Distributed Computing Open Elective 2
- CS3551 Project Work /
Elective-3
Open Elective 3 Intership
Big Data Analytics - Elective-4
CCS334 Open Elective 4
Elective-5
Elective 1 Management Elective
Elective-6
Elective 2
All Computer Engg Subjects - [ B.E., M.E., ] (Click on Subjects to enter)
Programming in C Computer Networks Operating Systems
Programming and Data Programming and Data Problem Solving and Python
Structures I Structure II Programming
Database Management Systems Computer Architecture Analog and Digital
Communication
Design and Analysis of Microprocessors and Object Oriented Analysis
Algorithms Microcontrollers and Design
Software Engineering Discrete Mathematics Internet Programming
Theory of Computation Computer Graphics Distributed Systems
Mobile Computing Compiler Design Digital Signal Processing
Artificial Intelligence Software Testing Grid and Cloud Computing
Data Ware Housing and Data Cryptography and Resource Management
Mining Network Security Techniques
Service Oriented Architecture Embedded and Real Time Multi - Core Architectures
Systems and Programming
Probability and Queueing Theory Physics for Information Transforms and Partial
Science Differential Equations
Technical English Engineering Physics Engineering Chemistry
Engineering Graphics Total Quality Professional Ethics in
Management Engineering
Basic Electrical and Electronics Problem Solving and Environmental Science and
and Measurement Engineering Python Programming Engineering