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

DS Miniproject

The document is a mini project report on 'Data Structures-1' submitted by students of Srinivas University Institute of Engineering and Technology for their Bachelor of Technology in Computer Science and Engineering. It covers various data structures including arrays, circular queues, and stacks, discussing their characteristics, operations, and applications in programming, particularly using Python. The report emphasizes the importance of selecting appropriate data structures for efficient data management and algorithm performance.

Uploaded by

naikrohith90
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)
3 views27 pages

DS Miniproject

The document is a mini project report on 'Data Structures-1' submitted by students of Srinivas University Institute of Engineering and Technology for their Bachelor of Technology in Computer Science and Engineering. It covers various data structures including arrays, circular queues, and stacks, discussing their characteristics, operations, and applications in programming, particularly using Python. The report emphasizes the importance of selecting appropriate data structures for efficient data management and algorithm performance.

Uploaded by

naikrohith90
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/ 27

SRINIVAS UNIVERSITY INSTITUTE

OF ENGINEERING AND TECHNOLOGY MUKKA,


MANGALURU-574146

Mini Project Report


On
“DATA STRUCTURES-1”
Submitted in the partial fulfillment of the requirements for the award of the degree of

BACHELOR OF TECHNOLOGY IN COMPUTER SCIENCE AND


ENGINEERING
Submitted
By
GOWTHAMI 01SU23CS068
GRISHA H D 01SU23CS069
HRIDYA MOHANAN 01SU23CS078
JAIBUNNISA SHAIKH 01SU23CS079

Submitted
To
Dr. J VENKATA KRISHNA
Associate Professor, Dept of CSE
2024-2025
SRINIVAS UNIVERSITY INSTITUTE
OF ENGINEERING AND TECHNOLOGY MUKKA,
MANGALURU – 574146

Department of Computer science

CERTIFICATE
This is to certify that the miniproject “DATA STRUCTURES-1” is a bonafide work carried out
by GOWTHAMI, GRISHA, HRYDYA MOHANAN, JAIBUNNISA SHAIKH. USN Number:
01SU23CS068, 01SU23CS069, 01SU23CS078, 01SU23CS079. In the partial fulfillment for the
award of Bachelor of Technology in Computer science of the Srinivas University, Institute of
Engineering & Technology during the year 2023-2024.It is certified that all
corrections/suggestions indicated for internal assessment have been incorporated in the report
deposited in the department library. The miniproject report has been approved as it satisfies the
academic requirements in respect of miniproject work prescribed for the said degree .

___________________

Dr J Venkata Krishana

(Miniproject Guide)
SRINIVAS UNIVERSITY INSTITUTE OF
ENGINEERING & TECHNOLOGY MUKKA,
MANGALURU – 574146

Department of Computer science

DECLARATION
We, GOWTHAMI, GRISHA, HRIDYA MOHANAN, JAIBUNNISA SHAIKH the student of
third semester, B.Tech in Computer science University, Mukka, hereby declare that the mini
project titled ”Employee Management System using Python“ has been successfully completed by
us in partial ulfillment of the requirements in Bachelor of Technology in Computer science of
Srinivas University, Institute of Engineering and Technology.

Date: 21/10/2024

Place: Mukka
ABSTRACT

Data structures are a fundamental concept in computer science, and Python, being a versatile and
powerful programming language, offers a wide array of built-in data structures such as lists,
dictionaries, tuples, and sets, along with the flexibility to implement custom data structures like
linked lists, stacks, queues, and trees. This abstract delves into the importance of data structures
in Python, exploring their efficiency in managing and organizing data, enabling optimized
searching, sorting, and manipulation operations. We highlight the significance of choosing the
right data structure to improve time complexity and storage requirements for algorithms,
emphasizing Python’s user-friendly syntax and dynamic nature that makes working with data
structures both efficient and intuitive. Furthermore, Python’s standard library, particularly
modules like collections and heapq, extends the capabilities of basic data structures, offering
specialized structures such as named tuples, deques, and priority queues, making Python a robust
tool for solving complex computational problems. This abstract provides an overview of data
structures in Python and their critical role in developing efficient and scalable applications.
ACKNOWLEDGEMENT

It is our pleasure to acknowledge for all those who have provided guidance, inspiration and
encouragement for the successful completion of our mini project. We take this opportunity to
express our profound gratitude to our respected guide Dr J Venkata Krishna , Associate
Professor, Dept of CSE for her ever-inspiring guidance, constant encouragement and support.
We sincerely thank, Dr J Venkata Krishna, Associate Professor, Computer science &
Engineering, for being an inspiration and support throughout this miniproject. We are extremely
grateful to our respected Dean, Dr. N Ramakrishna Hegde for providing the facilities to carry
out the miniproject presentation. We would like to thank our Management, A. Shama Rao
Foundation, Mangalore, for providing the means of support. We also extend our thanks to all
teaching, non-teaching staff and management staff who have been helpful and cooperative
towards the completion of the miniproject.
TABLE OF CONTENTS

1. INTRODUCTION

2.
CHARACTERISTICS

3.
COMMON OPERATIONS

4. COMMON FACTORS

5. APPLICATIONS

6. CODE

7. OUTPUT

8. CONCLUSION
INTRODUCTION

Introduction to Data Structures: Array, Circular Queue, and Stack

1. Array:

An array is a fundamental data structure that stores elements in contiguous memory locations. It
allows for the storage of multiple items of the same type together. The primary operations that
can be performed on arrays include accessing elements by index, inserting, deleting, and
updating elements. Arrays are widely used due to their simplicity and efficiency in accessing
elements, as any element can be retrieved using its index in constant time.

2. Circular Queue:

A circular queue is an advanced form of a queue where the last position is connected back to the
first position to make a circle. Unlike a simple linear queue, when a circular queue reaches its
end, it can wrap around to the front and reuse empty spaces at the beginning (if any). This helps
in better space utilization. Circular queues are commonly used in scenarios where memory is
limited, such as buffering in streaming data or managing processes in operating systems.

3. Stack:

A stack is a linear data structure that follows the Last-In-First-Out (LIFO) principle, meaning the
last element added is the first one to be removed. It has two primary operations: push, which
adds an element to the top, and pop, which removes the top element. Stacks are often used in
scenarios like undo functionality in text editors, expression evaluation, and managing function
calls in programming (call stacks).

These data structures serve as building blocks for more complex algorithms and are essential for
efficient problem-solving in computing.
CHARACTERISTICS

1. Array:

Characteristics:

 Fixed Size: The size of an array is usually defined at the time of its creation and cannot
be changed.
 Homogeneous: Elements in an array are of the same data type (though Python lists can
contain mixed types).
 Random Access: Elements can be accessed directly using their index.
 Static vs. Dynamic: In some languages (like C or Java), arrays are static, meaning the
size is fixed at the time of declaration. In Python, lists can grow or shrink dynamically.
 Contiguous Memory: Elements in an array are stored in contiguous (adjacent) memory
locations, making access to any element very fast.
 Index-based Access: Direct access to elements using index, i.e., O(1) access time.

2. Circular Queue

Characteristics:

 Fixed Size: Like arrays, circular queues have a fixed size.


 Wrap Around: Once the end of the queue is reached, the next element is added to the
front if space is available.
 Efficient Space Utilization: Circular queues make efficient use of memory, as they can
reuse positions that have been dequeued. This is in contrast to simple queues that leave
unused positions in the front.
 Prevents Overflow: The structure ensures the queue won't overflow unless it is
completely full.

3. Stack:

Characteristics:

 LIFO Order: The last item added is the first to be removed.


 Dynamic Size: In Python, the size of a stack can grow or shrink as elements are added or
removed.
 Limited Access: Only the top element of the stack is accessible, making it distinct from
arrays where all elements can be accessed randomly.
 Recursive Nature: Stacks are inherently recursive, as each new element added is placed
on top of the previous one, similar to the recursive function calls.
 Overflow/Underflow: In fixed-size stacks, overflow occurs when you try to push an
element onto a full stack, and underflow happens when popping from an empty stack.

COMMON OPERATIONS
1. Array:

Common Operations on array:

 Access: Retrieve an element by its index.


 Traversal: Access each element in the array.
 Insertions/Deletions: Typically, insertions or deletions are inefficient because elements
may need to be shifted. The time complexity is O(n) for worst-case scenarios (like
inserting at the beginning).
 Search: Searching through an unsorted array takes O(n) time for a linear search and
O(log n) for binary search in a sorted array

2. Circular Queue:

Common Operations on Circular Queue:

 Peek: Retrieve the front element without removing it.


 Enqueue/Dequeue: Both operations take O(1) time. The enqueue operation adds elements
to the rear, and dequeue removes elements from the front.
 Space Efficient: By using wrap-around logic, circular queues make better use of memory
than simple linear queues.
 Full and Empty Conditions: A circular queue is full when (rear + 1) % size ==front, and
it's empty when front == -1.

3. Stack:

Common Operations on Stack:

 Push/Pop: Both operations take O(1) time. Pushing adds an element to the top of the
stack, while popping removes the top element.
 isEmpty: Check if the stack is empty.
 Peek: Retrieves the top element without removing it (also an O(1) operation).
 Reversing/Backtracking: Stacks are often used for reversing data, such as in string
reversal or backtracking algorithms.

Common Factors
1.Linear Data Structures:

 Both arrays, circular queues, and stacks are linear data structures. This means their
elements are stored in a linear order (sequentially).

2.Memory Utilization:

 Array: Uses contiguous memory locations, which can lead to memory overflow if not
enough space is allocated.
 Circular Queue: Efficient memory usage since it reuses empty spaces left by dequeued
elements.
 Stack: Memory is only used for the elements in the stack. When elements are removed
(popped), memory is freed up.

3.Access Patterns:

 Array: Allows random access (O(1) for access and retrieval).


 Circular Queue: Only allows access to the front (for dequeuing) and rear (for
enqueuing).
 Stack: Only allows access to the top of the stack (O(1) for push, pop, and peek).
4.Fixed or Dynamic Size:

 Array: Typically has a fixed size, though Python lists are dynamic.
 Circular Queue: Fixed size.
 Stack: Can be fixed (array-based) or dynamic (list/linked list-based).

5.Complexity:

 Insertion/Deletion:
 Arrays: Insertion and deletion can be costly, with a time complexity of O(n) in the
worst case (inserting or deleting in the middle or beginning).
 Circular Queue and Stack: Insertions and deletions are constant time O(1).

6.Overflow/Underflow Conditions:

 Array: No overflow condition unless it's a statically sized array (like in C/C++).
 Circular Queue: Has both overflow (when full) and underflow (when empty) conditions.
 Stack: Can overflow (when full in fixed-size stacks) or underflow (when trying to pop
from an empty stack).

Summary of Key Differences and Usage

Data Order Access Insertion/Deletion Size Applications


Structure Time
Array Linear Random Insertion/Deletion Fixed/Dynamic Lookup tables,
(O(1)) O(n) matrices, lists
Circular Linear Front & Enqueue/Dequeue Fixed Buffering,
Queue with Rear O(1) scheduling, task
wrap- management
around

Stack LIFO Top only Push/Pop O(1) Fixed/Dynamic Undo operations,


(Last In expression
First Out) evaluation,
recursion
Applications of Arrays, Circular Queues, and Stacks:

Each data structure has specific applications where it excels due to its characteristics. Below, we
discuss practical use cases for arrays, circular queues, and stacks in real-world applications.

1.Array:

Arrays are one of the most fundamental data structures and are used in a wide range of
applications due to their simplicity and fast access times. Here are some key applications:

Applications of Arrays:

1. Data Storage and Lookup Tables:

 Arrays are often used to store a collection of elements like lookup tables, where
you need fast access to elements. For example, an array of prices for different
products in an e-commerce application.

2. Mathematical Computations:

o Arrays are used to store matrices and vectors in mathematical computations and
scientific calculations. For instance, in machine learning and scientific
computing, NumPy arrays are widely used.

3. Image Processing:

o Digital images are stored as 2D arrays (matrices) of pixels. Each pixel in the
array represents a color value (RGB, grayscale, etc.).

4. Database Systems:

o Arrays are used to store records in a contiguous block of memory, allowing for
fast retrieval of rows from a table.

5. Hash Tables:
o Arrays can serve as the underlying structure in hash tables, where each index
corresponds to a bucket.

6. Multidimensional Arrays:

o Arrays can represent higher-dimensional data, such as 3D arrays for simulation in


physics or 3D models in computer graphics.

Example Use Case:

 Storing Student Grades: An array can store the grades of students, allowing quick
access to a student’s grade using their index (position).

2. Circular Queue:

Circular queues have unique advantages over regular queues, especially when memory
utilization is crucial. Their wrap-around behavior allows efficient use of available space, making
them ideal in specific applications.

Applications of Circular Queues:

1. CPU Scheduling (Round Robin):

o Operating systems use circular queues in round-robin CPU scheduling


algorithms. When multiple processes need to be executed, the circular queue
ensures that each process gets a fair share of CPU time.

2. Buffer Management:
o Circular queues are widely used in buffering scenarios, such as handling
streaming data (audio/video streaming). The queue maintains a circular buffer to
ensure continuous data flow without overflow or underflow.
3. Network Packet Scheduling:
o In network routers and switches, circular queues are used to manage packets. Data
packets are enqueued at the rear and dequeued from the front in a circular manner.
4. I/O Buffers:
o Circular buffers are often used in hardware I/O operations where data is read and
written simultaneously (e.g., in printers, sound cards). It helps maintain a smooth
flow of data between the producer and consumer.
5. Real-Time Systems:
o In embedded systems and real-time operating systems, circular queues manage
tasks, ensuring smooth task switching and resource management without using
excessive memory.

Example Use Case:

 Keyboard Buffer: When typing, the characters you input are stored temporarily in a
circular queue before being processed by the CPU.

3. Stack:

Stacks are used extensively in computer science due to their LIFO (Last In First Out) property.
They are essential for various algorithms and system-level operations.

Applications of Stacks:

1. Expression Evaluation and Conversion:


o Stacks are used to evaluate arithmetic expressions, such as converting infix
expressions to postfix (or prefix) and evaluating postfix expressions. They handle
operator precedence and parentheses correctly.
2. Undo/Redo Operations:
o Text editors, image editors, and even word processors use stacks to implement
undo and redo functionality. Each user action is pushed onto the stack, and
popping elements from the stack undoes them.
3. Function Call Management (Call Stack):
o Programming languages use a stack to manage function calls. Each time a
function is called, the current state is pushed onto the call stack. When the
function returns, its state is popped off the stack. This is essential for recursion,
where each recursive call adds a new frame to the stack.
4. Backtracking Algorithms:
o Stacks are used in algorithms that require backtracking, such as maze-solving
algorithms, depth-first search (DFS) in graph traversal, and puzzles like Sudoku.
5. Browser History:
o When navigating a web browser, each visited page is pushed onto the history
stack. When the user clicks the "back" button, the most recent page is popped off
the stack, and the browser navigates to the previous page.
6. Parenthesis Matching:
o Stacks are used to check for balanced parentheses in expressions (e.g., during
compilation of code). As each opening parenthesis is encountered, it is pushed
onto the stack, and closing parentheses are matched by popping from the stack.
7. Memory Management:
o In low-level programming, stacks are used for memory management, particularly
in managing local variables and return addresses for function calls.

Example Use Case:

 Reversing a String: You can use a stack to reverse a string by pushing each character
onto the stack and then popping them off in reverse order.

Summary of Applications:

Data Applications
Structure

Array Data storage, lookup tables, mathematical computations, image processing,


database systems, hash tables, multidimensional arrays
Circular CPU scheduling (round robin), buffer management (audio/video streaming),
Queue network packet scheduling, I/O buffers, real-time systems

Stack Expression evaluation, undo/redo functionality, function call management (call


stack), backtracking algorithms, browser history, parenthesis matching, recursion
Each of these data structures has specialized use cases that make them indispensable tools in
computer science. Arrays offer fast access, circular queues provide efficient space utilization,
and stacks allow for precise control over operations like function calls and expression evaluation.
Understanding when and how to use each one is essential for efficient programming and
algorithm design.

1.PROGRAM ON ARRAY:

def insert(arr, n):


ele = int(input("Enter Element: "))
pos = int(input("Enter Position: "))
# Check if position is valid
if pos < 1 or pos > n + 1:
print("Invalid Position!")
else:
arr.insert(pos - 1, ele) # Insert element at position
n += 1
return n
def delete(arr, n):
pos = int(input("Enter the Position to delete the element: "))
# Check if position is valid
if pos < 1 or pos > n:
print("Invalid Position!")
else:
del arr[pos - 1] # Delete element at position
n -= 1
return n
def display(arr, n):
print("Array Elements: ", end="")
for i in range(n):
print(arr[i], end=" ")
print()
def main():
arr = []
n = int(input("Enter Initial size of Array: "))
# Input the initial array elements
print("Enter Array Elements: ")
for i in range(n):
arr.append(int(input()))
while True:
print("\nMenu")
print("1. Insert\n2. Delete\n3. Display\n4. Exit")
ch = int(input("Enter your choice: "))
if ch == 1:
n = insert(arr, n)
elif ch == 2:
n = delete(arr, n)
elif ch == 3:
display(arr, n)
elif ch == 4:
print("Exiting...")
break
else:
print("Invalid choice, please try again.")
if __name__ == "__main__":
main()
OUTPUT:
2.PROGRAM ON CIRCULAR QUEUE:

MAX = 10
def cqinsert(queue, rear, count):
if count == MAX:
print("Queue is Full")
else:
ele = input("Enter a Character: ")
rear = (rear + 1) % MAX
queue[rear] = ele
count += 1
return rear, count
def cqdelete(queue, front, count):
if count == 0:
print("Queue is Empty")
else:
print(f"Deleted Character is {queue[front]}")
front = (front + 1) % MAX
count -= 1
return front, count
def display(queue, front, count):
if count == 0:
print("Queue is Empty")
else:
print("The Characters are:")
for i in range(count):
print(queue[front], end='\t')
front = (front + 1) % MAX
print()
def menu():
queue = [''] * MAX
front = 0
rear = -1
count = 0
while True:
print("\nMenu")
print("1. Insert")
print("2. Delete")
print("3. Display")
print("4. Exit")
ch = int(input("Enter your choice: "))
if ch == 1:
rear, count = cqinsert(queue, rear, count)
elif ch == 2:
front, count = cqdelete(queue, front, count)
elif ch == 3:
display(queue, front, count)
elif ch == 4:
print("Exiting...")
break
else:
print("Invalid choice, please try again.")
if __name__ == "__main__":
menu()
OUTPUT:
3.PROGRAM ON STACK:

MAX = 20

def stack_full(top):

return top == MAX - 1

def stack_empty(top):

return top == -1

def push(stack, top, ele):

if stack_full(top):

print("Stack Full")

return top

else:

stack.append(ele)

return top + 1

def pop(stack, top):

if stack_empty(top):

print("Stack Empty")

return top, None

else:

ele = stack.pop()

return top - 1, ele

def display(stack, top):

if stack_empty(top):

print("Stack Empty")

else:

print("Stack elements are:", " ".join(map(str, stack)))


def menu():

stack = []

top = -1

while True:

print("\nMenu")

print("1. Push")

print("2. Pop")

print("3. Stack Status")

print("4. Display")

print("5. Exit")

ch = int(input("Enter your choice: "))

if ch == 1:

if stack_full(top):

print("Stack Full")

else:

ele = int(input("Enter an element: "))

top = push(stack, top, ele)

elif ch == 2:

if stack_empty(top):

print("Stack Empty")

else:

top, ele = pop(stack, top)

if ele is not None:

print(f"Deleted Element is {ele}")

elif ch == 3:
if stack_empty(top):

print("Stack Empty")

elif stack_full(top):

print("Stack Full")

else:

print(f"Stack contains {top + 1} elements")

elif ch == 4:

display(stack, top)

elif ch == 5:

print("Exiting...")

break

else:

print("Invalid choice, please try again.")

if _name_ == "_main_":

menu()

OUTPUT:
Conclusion
Arrays, circular queues, and stacks are essential data structures with distinct characteristics that
make them suitable for specific tasks in computer science and programming.

 Arrays provide fast random access to elements and are ideal for storing collections of
data where quick retrieval is important. They are widely used in situations such as data
storage, image processing, and lookup tables, but their fixed size and inefficiency in
insertions and deletions can be limiting.
 Circular Queues are optimal for scenarios that require efficient space utilization and
continuous data flow, like buffering in streaming systems, task scheduling, and real-time
processing. Their ability to reuse space through wrap-around behavior makes them more
efficient than linear queues in many applications.
 Stacks are perfect for managing tasks that follow a LIFO (Last In First Out) order. They
are essential in areas like recursion, function call management, backtracking algorithms,
and undo/redo functionalities in software applications.

Each data structure has its advantages, and choosing the right one depends on the specific needs
of the problem. Mastering these data structures allows developers to write more efficient and
optimized code, improving both performance and resource management in various computing
applications.

You might also like