An open API service indexing awesome lists of open source software.

https://github.com/rohitpawar001/structures-and-algorithms

This repository containns all the builtin data structures and derived data structure, and various algorithms of searching and sorting in python.
https://github.com/rohitpawar001/structures-and-algorithms

dsa dsa-algorithm python

Last synced: 5 months ago
JSON representation

This repository containns all the builtin data structures and derived data structure, and various algorithms of searching and sorting in python.

Awesome Lists containing this project

README

          

# Structures and Algorithms in python

1.list


Lists are ordered collections of data, It allows different types of elements in the list. The costly operation is inserting or deleting the element from the beginning of the List as all the elements are needed to be shifted.

2. tuple


tuple are same as list except they are immutable. immutable means once the tuple is created cannot add or remove elements from the tuple
to remove the element from the tuple we have to first typecast it into the another datatype.


tuple are enclosed within the () braces and elements are seperated by commas and it can store different datatypes

3. sets

Sets are unordered collections of unique elements. In Python, you can create sets using curly braces {} or the set() constructor.
(~ # Create sets
set_a = {1, 2, 3}
set_b = {3, 4, 5}

**Union**
union_result = set_a | set_b
print("Union:", union_result)

**Intersection**
intersection_result = set_a & set_b
print("Intersection:", intersection_result)

**Difference**
difference_result = set_a - set_b
print("Difference:", difference_result)

**Membership testing**
print(2 in set_a) # True
print(6 in set_a) # False
~)

4.Stack


stack follows LIFO (last in last out ) priciple ie the lastly inserted elemetn is get removed first.

in python the stack can be implemented using list.



the element insertation and deletion done at the same end.

we can perform two operation in stack ther are
1.push
2.pop

5.Queue


A queue in Python is a linear data structure that follows the First In First Out (FIFO) principle, meaning the first element added to the queue will be the first one to be removed. Think of it like a line of people waiting for a service, where the person who arrives first is served first.

There are several ways to implement a queue in Python:

1.using lists
2.using queue.Queue
3.using

bytearray


A binary array in Python typically refers to an array that contains binary data, which is data represented in the form of 0s and 1s. There are several ways to work with binary arrays in Python, depending on your specific needs. Here are a few common methods:

1.using numpy
2.using array module
3.using lists
4.using bytearray

6.Dictionary



A dictionary in Python is a collection of key-value pairs. Each key is unique and maps to a specific value. Dictionaries are mutable, meaning you can change, add, or remove items after the dictionary is created. They are also ordered as of Python 3.7, meaning the items have a defined order.


**Dictionary method**


Here are some useful dictionary methods:

keys(): Returns a view object of all keys.

values(): Returns a view object of all values.

items(): Returns a view object of all key-value pairs.

update(): Updates the dictionary with key-value pairs from another dictionary or an iterable of key-value pairs.

7.Linked List


A linked list is a linear data structure where each element, called a node, contains a data part and a reference (or link) to the next node in the sequence. Linked lists are useful for dynamic memory allocation and efficient insertions and deletions.

**Types of Linked Lists**

Singly Linked List: Each node points to the next node.

Doubly Linked List: Each node points to both the next and the previous node.

Circular Linked List: The last node points back to the first node.

**Node Class:** Defines the structure of a node with data and next attributes.

**LinkedList Class:** Contains methods to insert nodes at the beginning and end, delete nodes, search for nodes, and print the list.

**Example Usage:** Demonstrates how to create a linked list, insert nodes, search for a node, delete a node, and print the list.