0% found this document useful (0 votes)
5 views12 pages

Data Structure Using Python Observation

The document outlines laboratory records for students at Hindusthan Polytechnic College, detailing various Python programming tasks including list operations, singly linked lists, stacks, queues, binary trees, sorting algorithms, and search algorithms. Each section includes the aim, program code, and confirms successful execution of the programs. The document serves as a practical examination record for the academic year 2025-2026.

Uploaded by

Kishor S
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)
5 views12 pages

Data Structure Using Python Observation

The document outlines laboratory records for students at Hindusthan Polytechnic College, detailing various Python programming tasks including list operations, singly linked lists, stacks, queues, binary trees, sorting algorithms, and search algorithms. Each section includes the aim, program code, and confirms successful execution of the programs. The document serves as a practical examination record for the academic year 2025-2026.

Uploaded by

Kishor S
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

HINDUSTHAN POLYTECHNIC COLLEGE

COIMBATORE – 641 032

LABORATORY RECORD

NAME

[Link]

CLASS

YEAR / SEMESTER YEAR : SEMESTER :

Certified that this is the bonafide record of work done by the above student for

the_______________________________________________________________Laboratory

during the year 2025 -2026

INTERNAL MARK

Staff in-Charge Head of the Department

Submitted for the Practical Examination Held on ______________________________

Internal Examiner External Examiner


Index
List Operations in Python

Aim

To implement a Python data structure (list) and perform the


following operations:
A) Create B) Add elements C) Access elements D) Remove elements

Program

numbers = []

[Link] (10)

[Link] (20)

[Link] (30)

print ("First number:", numbers[0])

print ("All numbers:", numbers)

[Link] (20)

print ("After removing 20:", numbers)

Sample output

Result

Thus the program is executed successfully.


Singly linked list

Aim

To implement a singly linked list in Python and perform operations: a)


Create b) Add element c) Remove element

program

class Node:

def init (self, data):

[Link] = data

[Link] = None

class LinkedList:

def init (self):

[Link] = None

def add(self, data):

new = Node(data)

if not [Link]:

[Link] = new

else:

temp = [Link]

while [Link]:

temp = [Link]

[Link] = new

def remove(self, key):

temp = [Link]

if temp and [Link] == key:

[Link] = [Link]

return
while temp and [Link]:

if [Link] == key:

[Link] = [Link]

return

temp = [Link]

def show(self):

temp = [Link]

while temp:

print([Link], end=" -> ")

temp = [Link]

print("None")

ll = LinkedList()

[Link](10)

[Link](20)

[Link](30)

print("List after adding:")

[Link]()

[Link](20)

print("List after removing 20:")

[Link]()

Sample output

Result

Thus the program is executed successfully.


Implement stack
Aim

To implement a stack data structure in Python and perform the basic


operations:

 Create
 Push (add element)
 Pop (remove element)
 Peek (access top element)

Program

stack = []

[Link](10)

[Link](20)

[Link](30)

print("Stack after push:", stack)

print("Top element:", stack[-1])

[Link]()

print("Stack after pop:", stack)

Sample output

Result

Thus the program is executed successfully.


Implement queue

Aim

To implement a queue data structure in Python and perform the basic


operations:

 Create a queue
 Enqueue (add elements)
 Dequeue (remove elements)
 Access/Peek (see the front element)

Program

queue = []

[Link](10)

[Link](20)

[Link](30)

print("Queue after enqueue:", queue)

print("Front element:", queue[2])

[Link](0) # removes the first element

print("Queue after dequeue:", queue)

Sample output

Result

Thus the program is executed successfully.


Pre-order traversal of a binary tree

Aim

To implement a binary tree in Python and perform pre-order traversal


(Root → Left → Right).

Program

class Node:

def init (self, data):

[Link] = data

[Link] = None

[Link] = None

def preorder(root):

if root:

print([Link], end=" ") # Visit root

preorder([Link]) # Traverse left subtree

preorder([Link]) # Traverse right subtree

root = Node(1)

[Link] = Node(2)

[Link] = Node(3)

[Link] = Node(4)

[Link] = Node(5)

print("Pre-order Traversal of Binary Tree:")

preorder(root)

Sample output

Result

Thus the program is executed successfully.


Implement Bubble Sort

Aim

To implement the Bubble Sort algorithm in Python to arrange a list of


numbers in ascending order.

Program

def bubble_sort(arr):

for i in range(len(arr)):

for j in range(len(arr) - i - 1):

if arr[j] > arr[j + 1]:

arr[j], arr[j + 1] = arr[j + 1], arr[j]

numbers = [5, 3, 8, 4, 2]

print("Original List:", numbers)

bubble_sort(numbers)

print("Sorted List:", numbers)

Sample output

Result

Thus the program is executed successfully.


Implement Linear Search

Aim

To implement the Linear Search algorithm in Python to find the


position of a given element in a list.

Program

def linear_search(arr, key):

for i in range(len(arr)):

if arr[i] == key:

return i # return index if found

return -1 # return -1 if not found

numbers = [10, 20, 30, 40, 50]

print("List:", numbers)

key = 30

result = linear_search(numbers, key)

if result != -1:

print(f"Element {key} found at index {result}")

else:

print(f"Element {key} not found in the list")

Sample output

Result

Thus the program is executed successfully.


Implement Binary Search

Aim

To implement the Binary Search algorithm in Python to find the


position of a given element in a sorted list.

Program

def binary_search(arr, key):

low, high = 0, len(arr) - 1

while low <= high:

mid = (low + high) // 2

if arr[mid] == key:

return mid

elif arr[mid] < key:

low = mid + 1

else:

high = mid - 1

return -1

numbers = [10, 20, 30, 40, 50]

print("List:", numbers)

key = 30

result = binary_search(numbers, key)

if result != -1:

print("Element found at index:", result)

else:

print("Element not found")


Sample output

Result

Thus the program is executed successfully.

You might also like