Skip to content

Commit

Permalink
some changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mustafaansarii committed Aug 18, 2024
1 parent fd48656 commit f25f3dc
Show file tree
Hide file tree
Showing 85 changed files with 421 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Heaps & Hashing/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Heaps & Hashing/.idea/Heaps & Hashing.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions Heaps & Hashing/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Heaps & Hashing/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Heaps & Hashing/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Heaps & Hashing/Hard/Find_Median_In_A_Stream.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Problem URL: https://practice.geeksforgeeks.org/problems/find-median-in-a-stream/0
class Solution:
def solve(self, *args, **kwargs):
pass
pass
34 changes: 33 additions & 1 deletion Heaps & Hashing/Heap data structure.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,39 @@
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"source": [
"class Solution:\n",
" # Heapify function to maintain heap property.\n",
" def heapify(self, arr, n, i):\n",
" smallest = i\n",
" left = 2 * i + 1\n",
" right = 2 * i + 2\n",
" \n",
" if left < n and arr[left] > arr[smallest]:\n",
" smallest = left\n",
" \n",
" if right < n and arr[right] > arr[smallest]:\n",
" smallest = right\n",
" \n",
" if smallest != i:\n",
" arr[i], arr[smallest] = arr[smallest], arr[i]\n",
" self.heapify(arr, n, smallest)\n",
" \n",
" # Function to build a Heap from array.\n",
" def buildHeap(self, arr, n):\n",
" for i in range(n // 2 - 1, -1, -1):\n",
" self.heapify(arr, n, i)\n",
" \n",
" # Function to sort an array using Heap Sort.\n",
" def HeapSort(self, arr, n):\n",
" # Step 1: Build a max heap\n",
" self.buildHeap(arr, n)\n",
" \n",
" # Step 2: Extract elements from the heap one by one\n",
" for i in range(n-1, 0, -1):\n",
" arr[0], arr[i] = arr[i], arr[0] # Move current root to end\n",
" self.heapify(arr, i, 0) # Heapify the reduced heap\n"
]
},
{
"cell_type": "code",
Expand Down
31 changes: 31 additions & 0 deletions Heaps & Hashing/Heap_Sort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
def heapify(arr,n,i):
while True:
left=2*i+1
right=2*i+2
smallest=i

if left < n and arr[left] > arr[smallest]:
smallest=left

if right < n and arr[right] > arr[smallest]:
smallest=right

if smallest==i:
break
arr[smallest],arr[i]=arr[i],arr[smallest]
i=smallest


def HeapSort(arr,n):
for i in range(n//2-1,-1,-1):
heapify(arr,n,i)

for i in range(n-1,0,-1):
arr[0],arr[i]=arr[i],arr[0]
heapify(arr,i,0)


if __name__=="__main__":
arr=[2,3,23,12,45,67,97,89,76]
HeapSort(arr,len(arr))
print(arr)
4 changes: 4 additions & 0 deletions LINKED-LIST problems/Concept/Uses_of_Linked_List_Real_Life.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# No URL provided
class Solution:
def solve(self, *args, **kwargs):
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Problem URL: https://practice.geeksforgeeks.org/problems/add-1-to-a-number-represented-as-linked-list/1
class Solution:
class Node:
def __init__(self,data) -> None:
self.next=None
self.data=data

def __init__(self) -> None:
self.head=None

def insert(self,value):
new_node=self.Node(value)
if self.head==None:
head=new_node
return
new_node.next=self.head
self.head=new_node

def display(self):
n=self.head
if n:
while n:
print(n.data, end=' ')
n=n.next
def solve(self, *args, **kwargs):
pass


if __name__=="__main__":
obj=Solution()
obj.insert(10)
print(obj.display())

4 changes: 4 additions & 0 deletions LINKED-LIST problems/Easy/Arrays_vs_Linked_List.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Problem URL: https://leetcode.com/problems/middle-of-the-linked-list/
class Solution:
def solve(self, *args, **kwargs):
pass
4 changes: 4 additions & 0 deletions LINKED-LIST problems/Easy/Circular_Linked_List.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Problem URL: https://practice.geeksforgeeks.org/problems/circular-linked-list/1
class Solution:
def solve(self, *args, **kwargs):
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Problem URL: https://leetcode.com/problems/convert-binary-number-in-a-linked-list-to-integer/
class Solution:
def solve(self, *args, **kwargs):
pass
4 changes: 4 additions & 0 deletions LINKED-LIST problems/Easy/Intersection_of_Two_Linked_Lists.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Problem URL: https://leetcode.com/problems/intersection-of-two-linked-lists/
class Solution:
def solve(self, *args, **kwargs):
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Problem URL: https://practice.geeksforgeeks.org/problems/intersection-of-two-sorted-linked-lists/1
class Solution:
def solve(self, *args, **kwargs):
pass
4 changes: 4 additions & 0 deletions LINKED-LIST problems/Easy/Merge_Two_Sorted_Lists.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Problem URL: https://leetcode.com/problems/merge-two-sorted-lists/
class Solution:
def solve(self, *args, **kwargs):
pass
4 changes: 4 additions & 0 deletions LINKED-LIST problems/Easy/Middle_of_the_Linked_List.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Problem URL: https://leetcode.com/problems/middle-of-the-linked-list/
class Solution:
def solve(self, *args, **kwargs):
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Problem URL: https://www.geeksforgeeks.org/move-last-element-to-front-of-a-given-linked-list/
class Solution:
def solve(self, *args, **kwargs):
pass
4 changes: 4 additions & 0 deletions LINKED-LIST problems/Easy/Nth_Node_from_End_of_Linked_List.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Problem URL: https://practice.geeksforgeeks.org/problems/nth-node-from-end-of-linked-list/1
class Solution:
def solve(self, *args, **kwargs):
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Problem URL: https://practice.geeksforgeeks.org/problems/remove-duplicate-element-from-sorted-linked-list/1
class Solution:
def solve(self, *args, **kwargs):
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Problem URL: https://leetcode.com/problems/remove-duplicates-from-sorted-list/
class Solution:
def solve(self, *args, **kwargs):
pass
4 changes: 4 additions & 0 deletions LINKED-LIST problems/Easy/Remove_Linked_List_Elements.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Problem URL: https://leetcode.com/problems/remove-linked-list-elements/
class Solution:
def solve(self, *args, **kwargs):
pass
4 changes: 4 additions & 0 deletions LINKED-LIST problems/Easy/Representation_of_Linked_List.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Problem URL: https://leetcode.com/problems/delete-node-in-a-linked-list/
class Solution:
def solve(self, *args, **kwargs):
pass
4 changes: 4 additions & 0 deletions LINKED-LIST problems/Easy/Reverse_Linked_List.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Problem URL: https://leetcode.com/problems/reverse-linked-list/
class Solution:
def solve(self, *args, **kwargs):
pass
4 changes: 4 additions & 0 deletions LINKED-LIST problems/Easy/Reverse_a_Doubly_Linked_List.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Problem URL: https://practice.geeksforgeeks.org/problems/reverse-a-doubly-linked-list/1
class Solution:
def solve(self, *args, **kwargs):
pass
4 changes: 4 additions & 0 deletions LINKED-LIST problems/Easy/Reverse_a_Linked_List.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Problem URL: https://www.geeksforgeeks.org/reverse-a-linked-list/
class Solution:
def solve(self, *args, **kwargs):
pass
File renamed without changes.
4 changes: 4 additions & 0 deletions LINKED-LIST problems/Easy/Sort_Linked_List_of_0s_1s_2s.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Problem URL: https://www.geeksforgeeks.org/sort-a-linked-list-of-0s-1s-or-2s/
class Solution:
def solve(self, *args, **kwargs):
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Problem URL: https://www.geeksforgeeks.org/flatten-a-linked-list-with-next-and-child-pointers/
class Solution:
def solve(self, *args, **kwargs):
pass
4 changes: 4 additions & 0 deletions LINKED-LIST problems/Hard/Flattening_a_Linked_List.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Problem URL: https://www.geeksforgeeks.org/flattening-a-linked-list/
class Solution:
def solve(self, *args, **kwargs):
pass
4 changes: 4 additions & 0 deletions LINKED-LIST problems/Hard/LRU_Cache_Implementation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Problem URL: https://practice.geeksforgeeks.org/problems/lru-cache/1
class Solution:
def solve(self, *args, **kwargs):
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Problem URL: https://www.geeksforgeeks.org/a-linked-list-with-next-and-arbit-pointer/
class Solution:
def solve(self, *args, **kwargs):
pass
4 changes: 4 additions & 0 deletions LINKED-LIST problems/Hard/Merge_Sort_for_Linked_List.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Problem URL: https://www.geeksforgeeks.org/merge-sort-for-linked-list/
class Solution:
def solve(self, *args, **kwargs):
pass
4 changes: 4 additions & 0 deletions LINKED-LIST problems/Hard/Merge_k_Sorted_Lists.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Problem URL: https://leetcode.com/problems/merge-k-sorted-lists/
class Solution:
def solve(self, *args, **kwargs):
pass
4 changes: 4 additions & 0 deletions LINKED-LIST problems/Hard/Quick_Sort_on_Linked_List.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Problem URL: https://practice.geeksforgeeks.org/problems/quick-sort-on-linked-list/1
class Solution:
def solve(self, *args, **kwargs):
pass
4 changes: 4 additions & 0 deletions LINKED-LIST problems/Hard/Quick_Sort_on_Singly_Linked_List.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Problem URL: https://www.geeksforgeeks.org/quicksort-on-singly-linked-list/
class Solution:
def solve(self, *args, **kwargs):
pass
4 changes: 4 additions & 0 deletions LINKED-LIST problems/Hard/Reverse_Nodes_in_k-Group.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Problem URL: https://leetcode.com/problems/reverse-nodes-in-k-group/
class Solution:
def solve(self, *args, **kwargs):
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# No URL provided
class Solution:
def solve(self, *args, **kwargs):
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Problem URL: https://practice.geeksforgeeks.org/problems/add-two-numbers-represented-by-linked-lists/1
class Solution:
def solve(self, *args, **kwargs):
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Problem URL: https://practice.geeksforgeeks.org/problems/check-if-linked-list-is-pallindrome/1
class Solution:
def solve(self, *args, **kwargs):
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Problem URL: https://practice.geeksforgeeks.org/problems/clone-a-linked-list-with-next-and-random-pointer/1
class Solution:
def solve(self, *args, **kwargs):
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Problem URL: https://leetcode.com/problems/reverse-linked-list/
class Solution:
def solve(self, *args, **kwargs):
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Problem URL: https://leetcode.com/problems/copy-list-with-random-pointer/
class Solution:
def solve(self, *args, **kwargs):
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Problem URL: https://www.geeksforgeeks.org/given-only-a-pointer-to-a-node-to-be-deleted-in-a-singly-linked-list-how-do-you-delete-it/
class Solution:
def solve(self, *args, **kwargs):
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Problem URL: https://www.geeksforgeeks.org/delete-nodes-which-have-a-greater-value-on-right-side/
class Solution:
def solve(self, *args, **kwargs):
pass
4 changes: 4 additions & 0 deletions LINKED-LIST problems/Medium/Design_Browser_History.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Problem URL: https://leetcode.com/problems/design-browser-history/
class Solution:
def solve(self, *args, **kwargs):
pass
4 changes: 4 additions & 0 deletions LINKED-LIST problems/Medium/Design_HashMap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Problem URL: https://leetcode.com/problems/design-hashmap/
class Solution:
def solve(self, *args, **kwargs):
pass
4 changes: 4 additions & 0 deletions LINKED-LIST problems/Medium/Detect_Loop_in_Linked_List.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Problem URL: https://practice.geeksforgeeks.org/problems/detect-loop-in-linked-list/1
class Solution:
def solve(self, *args, **kwargs):
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Problem URL: https://www.geeksforgeeks.org/detect-and-remove-loop-in-a-linked-list/
class Solution:
def solve(self, *args, **kwargs):
pass
4 changes: 4 additions & 0 deletions LINKED-LIST problems/Medium/Doubly_Linked_List_and_STLs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Problem URL: https://leetcode.com/problems/design-hashset/
class Solution:
def solve(self, *args, **kwargs):
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Problem URL: https://www.geeksforgeeks.org/find-first-node-of-loop-in-a-linked-list/
class Solution:
def solve(self, *args, **kwargs):
pass
4 changes: 4 additions & 0 deletions LINKED-LIST problems/Medium/Flattening_of_a_Linked_List.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Problem URL: https://practice.geeksforgeeks.org/problems/flattening-a-linked-list/1
class Solution:
def solve(self, *args, **kwargs):
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Problem URL: https://practice.geeksforgeeks.org/problems/intersection-point-in-y-shapped-linked-lists/1
class Solution:
def solve(self, *args, **kwargs):
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Problem URL: https://www.geeksforgeeks.org/write-a-function-to-get-the-intersection-point-of-two-linked-lists/
class Solution:
def solve(self, *args, **kwargs):
pass
4 changes: 4 additions & 0 deletions LINKED-LIST problems/Medium/LRU_Cache.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Problem URL: https://leetcode.com/problems/lru-cache/
class Solution:
def solve(self, *args, **kwargs):
pass
4 changes: 4 additions & 0 deletions LINKED-LIST problems/Medium/Linked_List_Cycle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Problem URL: https://leetcode.com/problems/linked-list-cycle/
class Solution:
def solve(self, *args, **kwargs):
pass
4 changes: 4 additions & 0 deletions LINKED-LIST problems/Medium/Linked_List_Cycle_II.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Problem URL: https://leetcode.com/problems/linked-list-cycle-ii/
class Solution:
def solve(self, *args, **kwargs):
pass
Loading

0 comments on commit f25f3dc

Please sign in to comment.