Skip to content

Commit 1f95bea

Browse files
Better Comments added
1 parent 16e3b72 commit 1f95bea

17 files changed

+354
-131
lines changed

README.md

+55-52
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,14 @@ Keep coding! :)
5858
- <details>
5959
<summary>Available Methods</summary>
6060

61-
- delete()
62-
- insertAtFirst()
63-
- insertAtLast()
64-
- insertAtPosition()
65-
- length()
66-
- reversePrint()
67-
- show()
61+
- *delete()* - Delete an element
62+
- *deleteList* - Delete the entire doubly linked list
63+
- *insertAtFirst()* - Inserting at first
64+
- *insertAtLast()* - Insert node at last
65+
- *insertAtPosition()* - Insert at a certain position
66+
- *length()* - Count of nodes in our doubly linked list
67+
- *reversePrint()* - Print all the elements in reverse
68+
- *show()* - To print all the elements
6869
</details>
6970
<span></span>
7071

@@ -74,8 +75,8 @@ Keep coding! :)
7475
- <details>
7576
<summary>Available Methods</summary>
7677

77-
- rotateClockwise()
78-
- rotateAntiClocwise()
78+
- *rotateClockwise()* - Rotate Colockwise
79+
- *rotateAntiClocwise()* - Rotate AntiClockwise
7980
</details>
8081
<span></span>
8182

@@ -103,9 +104,9 @@ Keep coding! :)
103104
- <details>
104105
<summary>Available Methods</summary>
105106

106-
- add()
107-
- search()
108-
- show()
107+
- *add()* - Add words to trie
108+
- *search()* - Search elements in trie
109+
- *show()* - Display all words in trie
109110
</details>
110111
<span></span>
111112

@@ -116,37 +117,39 @@ Keep coding! :)
116117
- <details>
117118
<summary>Available Methods</summary>
118119

119-
- delete()
120-
- empty()
121-
- getDiffEvenOddRows()
122-
- getLevelOfNode()
123-
- height()
124-
- ifMirrorStructureTree()
125-
- ifMirrorTree()
126-
- ifSameStructureTree()
127-
- ifSameTree()
128-
- inorderUsingStack()
129-
- insert()
130-
- isFoldable()
131-
- isIdentical()
132-
- leftSideOfTree()
133-
- levelOrderTraversal()
134-
- levelOrderTraversalLineByLine()
135-
- levelWiseSum()
136-
- maxWidth()
137-
- mirrorTree()
138-
- noOfNodes()
139-
- postorder()
140-
- preorder()
141-
- printAtGivenLevel()
142-
- printBetweenTwoLevels()
143-
- printLeaves()
144-
- recursiveSearch()
145-
- reverseLevelOrderTraversal()
146-
- rightSideOfTree()
147-
- search()
148-
- spiralOrder()
149-
- sum()
120+
- *delete()* - Delete the entire tree
121+
- *empty()* - Checks empty or not
122+
- *getDiffEvenOddRows()* - Difference of even and odd rows
123+
- *getLevelOfNode()* -Get level of data
124+
- *height()* - Height of the tree
125+
- *ifMirrorStructureTree()* - If two trees are mirror structure or not
126+
- *ifMirrorTree()* - If two trees are mirror ot not
127+
- *ifSameStructureTree()* - If two trees are having same structure or not
128+
- *ifSameTree()* - If two trees are same or not
129+
- *inorder* - Inorder traversal
130+
- *inorderUsingStack()* - Inorder traversal using stack
131+
- *insert()* - Insert the data in a BST
132+
- *isFoldable()* - Is the tree foldable or not
133+
- *isIdentical()* - Two trees are identical or not
134+
- *leftSideOfTree()* -Left side of the tree
135+
- *levelOrderTraversal()* -Print values by level order
136+
- *levelOrderTraversalLineByLine()* - Level order traversal line by line
137+
- *levelWiseSum()* - Sum of all data in each level
138+
- *maxWidth()* - Get maximum width of the tree
139+
- *mirrorTree()* - Mirror the tree
140+
- *noOfNodes()* - No of nodes in the tree
141+
- *noofLeafNodes* - Number of leaf nodes
142+
- *postorder()* - Postorder traversal
143+
- *preorder()* - Preorder Traversal
144+
- *printAtGivenLevel()* - Print values only at a certain level
145+
- *printBetweenTwoLevels()* - Print data between any two levels
146+
- *printLeaves()* - Print leaf nodes
147+
- *recursiveSearch()* - Search using recursion
148+
- *reverseLevelOrderTraversal()* - Level order traversal in reverse
149+
- *rightSideOfTree()* - Right side of the tree
150+
- *search()* - Return true if an element exists
151+
- *spiralOrder()* -Print in spiral order
152+
- *sum()* - Sum of all the values
150153
</details>
151154
<span></span>
152155

@@ -158,15 +161,15 @@ Keep coding! :)
158161
159162
# Dynamic Programming
160163

161-
- [Edit distance](dynamic_programming/edit_distance.py)
162-
- [Egg drop](dynamic_programming/egg_drop.py)
163-
- [Fibanocci sequence](dynamic_programming/fibanocci_sequence.py)
164-
- [Generate parenthesis](dynamic_programming/generate_parenthesis.py)
165-
- [Kadane algorithm](dynamic_programming/kadane_algorithm.py)
166-
- [Knapsack 0/1](dynamic_programming/knapsack01.py)
167-
- [Longest common subsequence](dynamic_programming/longest_common_subsequence.py)
168-
- [Min no of coins](dynamic_programming/min_no_of_coins.py)
169-
- [Range sum query](dynamic_programming/range_sum_query.py)
164+
- [Edit distance](dynamic_programming/edit_distance.py) - Number of edit distance required to change one string to another
165+
- [Egg drop](dynamic_programming/egg_drop.py) - Minimum no of trials needed in worst case to find the floor where the egg breaks
166+
- [Fibanocci sequence](dynamic_programming/fibanocci_sequence.py) - Generate fibanocci sequence
167+
- [Generate parenthesis](dynamic_programming/generate_parenthesis.py) - Generate matched parenthesis with n number of open and closed brackets
168+
- [Kadane algorithm](dynamic_programming/kadane_algorithm.py) - Largest sub array problem
169+
- [Knapsack 0/1](dynamic_programming/knapsack01.py) - knapsack 0/1 problem
170+
- [Longest common subsequence](dynamic_programming/longest_common_subsequence.py) - Longest common subsequence of two strings
171+
- [Min no of coins](dynamic_programming/min_no_of_coins.py) - Minimum number of coins needed to make the given amount
172+
- [Range sum query](dynamic_programming/range_sum_query.py) - Return the sum between two indices
170173

171174
# Searches
172175

dynamic_programming/egg_drop.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Egg dropping problem
2-
# Minimum no of trials needed in worst case to find the floor
2+
# Minimum no of trials needed in worst case to find the floor where the egg breaks
33
def egg_drop(eggs, floors):
44
INT_MAX = 32767
55
dp = [[0] * (floors + 1) for _ in range(eggs + 1)]

dynamic_programming/fibanocci_sequence.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Generate fibanocci sequence
12
def fibanocci_sequence(n: int) -> int:
23
if n<=1:
34
return n

dynamic_programming/min_no_of_coins.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Minimum number of coins needed to make the given amount
12
def min_no_of_coins(amount:int, coins: list) -> int:
23
# DP stores the number of coin used for each amount
34
# Initialize all values to amount + 1 as a dummy value

hashing/hash_table.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def get_hash(self, key):
1010
for char in key:
1111
hash += ord(char) # Ord returns the ASCII value of character
1212
return hash % self.size # Mod of total hash vs size is the final hash
13-
13+
# ------------------------------------------------------------------------------------------
1414
# https://docs.python.org/3/reference/datamodel.html#emulating-container-types
1515
# By using __setitem__, __delitem__, __getitem__ we can easily work with hash objects
1616
def __setitem__(self, key, val):
@@ -22,13 +22,13 @@ def __setitem__(self, key, val):
2222
found = True
2323
if not found: # If not found append at last
2424
self.arr[h].append((key, val))
25-
25+
# ------------------------------------------------------------------------------------------
2626
def __delitem__(self, key):
2727
h = self.get_hash(key)
2828
for idx, element in enumerate(self.arr[h]): # Find the position in sepearte chains and delete at that position
2929
if element[0] == key:
3030
del self.arr[h][idx]
31-
31+
# ------------------------------------------------------------------------------------------
3232
def __getitem__(self, key):
3333
h = self.get_hash(key)
3434
for element in self.arr[h]:

linked_list/doubly_linked_list.py

+1-11
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
1-
# ### Author: [BHARATHI KANNAN N](https://github.com/bharathikannann)
1+
# Author: BHARATHI KANNAN N - Github: https://github.com/bharathikannann, linkedin: https://linkedin.com/in/bharathikannann
22
#
33
# ## Doubly Linked List
44
# - A doubly linked list is a linked data structure that consists of a set of sequentially linked records called nodes. Each node contains three fields: two link fields (references to the previous and to the next node in the sequence of nodes) and one data field.
55
# - The two node links allow traversal of the list in either direction.
6-
#
7-
# ### Available methods
8-
#
9-
# - insertAtFirst()
10-
# - insertAtLast()
11-
# - insertAtPosition()
12-
# - show()
13-
# - delete()
14-
# - length()
15-
# - reversePrint()
166

177
#Structure of the node for our doubly linked list
188
class Node(object):

linked_list/linked_list.py

+6-33
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
# ### Author: [BHARATHI KANNAN N](https://github.com/bharathikannann)
2-
#
1+
# Author: BHARATHI KANNAN N - Github: https://github.com/bharathikannann, linkedin: https://linkedin.com/in/bharathikannann
32
# ## Linked List
43
#
5-
# - Linked list is a linear collection of data elements whose order is not given by their physical placement in memory. Instead, each element points to the next.<br>
6-
# - In its most basic form, each node contains: data, and a reference<br>
7-
# - This structure allows for efficient insertion or removal of elements from any position in the sequence during iteration.<br>
4+
# - Linked list is a linear collection of data elements whose order is not given by their physical placement in memory. Instead, each element points to the next.
5+
# - In its most basic form, each node contains: data, and a reference
6+
# - This structure allows for efficient insertion or removal of elements from any position in the sequence during iteration.
87
# - Linked lists are among the simplest and most common data structures. They can be used to implement several other common abstract data types, including lists, stacks, queues, etc..,
98
#
109
# ### Time Complexity:
@@ -15,29 +14,6 @@
1514
# - Deletion: O(1)
1615
# - Indexing: O(n)
1716
# - Searching: O(n)
18-
#
19-
# ## Available methods
20-
#
21-
# - insertAtFirst()
22-
# - insertAtPosition()
23-
# - insertAtLast()
24-
# - delete()
25-
# - show()
26-
# - ifNodeExists()
27-
# - length()
28-
# - rotateCloclwise()
29-
# - rotateAntiClockwise()
30-
# - reverse()
31-
# - reverseRecursion()
32-
# - getMiddleElement()
33-
# - isFirstSecondHalfMatch()
34-
# - isPalindrome()
35-
# - deleteGreaterValuesOnRight()
36-
# - pairwiseSwapElements()
37-
# - deleteAlternateNodes()
38-
# - moveLastNodeToFront()
39-
# - getCountOfValue()
40-
# - deleteList()
4117

4218
#Structure of the node for our linked list
4319
class Node():
@@ -117,7 +93,7 @@ def insertAtPosition(self, data, position):
11793
temp.next = newNode
11894

11995
# ------------------------------------------------------------------------------------------
120-
# Deleting the data at any position
96+
# Deleting the data at any position
12197
# Steps
12298
# 1. If head is the data to be deleted and if is none return none and if it the element to be deleted
12399
# change the head to the next of head by using temp node
@@ -534,7 +510,4 @@ def getCountOfValue(self, n):
534510
2
535511
Delete entire list
536512
No element present in the list
537-
'''
538-
539-
540-
# <big> To refer all of these implementations in java [click here](https://github.com/bharathikannann/Data-Structures-and-Algorithms/blob/master/LinkedList/LinkedList.java) </big>
513+
'''

linked_list/merge_two_sorted_linked_lists.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# ### Author: [BHARATHI KANNAN N](https://github.com/bharathikannann)
1+
# Author: BHARATHI KANNAN N - Github: https://github.com/bharathikannann, linkedin: https://linkedin.com/in/bharathikannann
22
#
3-
# <big>Merging Two Sorted Linked lists</big><br>
3+
# Merging Two Sorted Linked lists
44
# Merge sort algorithm
55
class Node():
66
def __init__(self, data, next=None):

linked_list/reversing_linked_list.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# ### Author: [BHARATHI KANNAN N](https://github.com/bharathikannann)
1+
# Author: BHARATHI KANNAN N - Github: https://github.com/bharathikannann, linkedin: https://linkedin.com/in/bharathikannann
22
#
3-
# <big>Sorting in Linked lists</big><br>
3+
# Sorting in Linked lists
44
# Merge sort algorithm
55

66
class Node():

linked_list/rotating_linked_list.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# ### Author: [BHARATHI KANNAN N](https://github.com/bharathikannann)
1+
# Author: BHARATHI KANNAN N - Github: https://github.com/bharathikannann, linkedin: https://linkedin.com/in/bharathikannann
22
#
3-
# <big>Sorting in Linked lists</big><br>
3+
# Sorting in Linked lists
44
# Merge sort algorithm
55

66
class Node():

linked_list/sorting_linked_list.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# ### Author: [BHARATHI KANNAN N](https://github.com/bharathikannann)
1+
# Author: BHARATHI KANNAN N - Github: https://github.com/bharathikannann, linkedin: https://linkedin.com/in/bharathikannann
22
#
3-
# <big>Sorting in Linked lists</big><br>
3+
# Sorting in Linked lists
44
# Merge sort algorithm
55

66
class Node():

queue/queue.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
# ### Author: [BHARATHI KANNAN N](https://github.com/bharathikannann)
1+
# Author: BHARATHI KANNAN N - Github: https://github.com/bharathikannann, linkedin: https://linkedin.com/in/bharathikannann
22
#
33
# ### Queue
4-
#
54
# A queue is a collection of entities that are maintained in a sequence and can be modified by the addition of entities at one end of the sequence and the removal of entities from the other end of the sequence.
6-
#
75
# The operation of adding an element to the rear of the queue is known as `enqueue`, and the operation of removing an element from the front is known as `dequeue`.
86

97
#Structure of the node for our linked list
@@ -19,7 +17,7 @@ def __init__(self):
1917
self.front = self.rear = None
2018
# Size for our queue
2119
self.size = 0
22-
20+
# ------------------------------------------------------------------------------------------
2321
def enqueue(self, data):
2422
# Create new node
2523
newNode = Node(data)
@@ -34,7 +32,7 @@ def enqueue(self, data):
3432
self.rear = self.rear.next
3533
# Increment size
3634
self.size += 1
37-
35+
# ------------------------------------------------------------------------------------------
3836
def dequeue(self):
3937
# If queue is empty
4038
if(self.rear == None):

stack/stack.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
# ### Author: [BHARATHI KANNAN N](https://github.com/bharathikannann)
1+
# Author: BHARATHI KANNAN N - Github: https://github.com/bharathikannann, linkedin: https://linkedin.com/in/bharathikannann
22
#
33
# ### Stack
44
#
55
# A stack is an abstract data type that serves as a collection of elements, with two main principal operations:
6-
#
76
# - Push, which adds an element to the collection, and
87
# - Pop, which removes the most recently added element.
9-
#
108
# The order in which elements come off a stack gives rise to its alternative name, LIFO (last in, first out).
119
#Structure of the node for our linked list
1210
class Node:

0 commit comments

Comments
 (0)