GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fixed space complexities · letscode-17/coding-problems@e68357f

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • Arrays
    • kth_smallest.py
    • reverse_array.py
  • Linked Lists
    • remove_nth_ll.py
  • Math
    • unique_paths.py
  • Other
    • find_min_path.py
    • generate_parentheses.py
    • power.py
    • river_sizes.py
  • Strings
    • zigzag_conversion.py
  • Trees
    • unival_trees.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎Arrays/kth_smallest.py‎

Copy file name to clipboardExpand all lines: Arrays/kth_smallest.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
This solution is based on the quick sort algorithm (pivoting, divide and conquer).
1717
More precisly in-place quick sort. Recursive solution.
1818
Time Complexity: O(N) , O(N + N/2 + N/4 + N/8 + ... + 1 = 2*N = N)
19-
Space Complexity: O(LogN) , because of the recursion stack (if this doesn't count, then O(1))
19+
Space Complexity: O(LogN) , because of the recursion stack
2020
Completely the same algorithm as the previous one, but without recursion. This solution is cleaner.
2121
Time Complexity: O(N)
2222
Space Complexity: O(1)
Collapse file

‎Arrays/reverse_array.py‎

Copy file name to clipboardExpand all lines: Arrays/reverse_array.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
99
=========================================
1010
Reverse the whole array by swapping pair letters in-place (first with last, second with second from the end, etc).
11-
Exist 2 more "Pythonic" ways of reversing arrays/strings:
11+
Exist 2 more "Pythonic" ways of reversing arrays/strings (but not in-place, they're creating a new list):
1212
- reversed_arr = reversed(arr)
1313
- reversed_arr = arr[::-1]
1414
But I wanted to show how to implement a reverse algorithm step by step so someone will know how to implement it in other languages.
Collapse file

‎Linked Lists/remove_nth_ll.py‎

Copy file name to clipboardExpand all lines: Linked Lists/remove_nth_ll.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
Space Complexity: O(1)
1313
Recursive solution.
1414
Time Complexity: O(N)
15-
Space Complexity: O(N) (Because of the stack of recursive calls)
15+
Space Complexity: O(N) , because of the recursive calls stack
1616
'''
1717

1818

Collapse file

‎Math/unique_paths.py‎

Copy file name to clipboardExpand all lines: Math/unique_paths.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def unique_paths(n, m):
4545
comb /= i
4646
lvl -= 1
4747

48-
return int(comb + 0.001) # 0.001 just in case because of overflow
48+
return int(comb + 0.001) # 0.001 just in case, because of overflow
4949

5050

5151
###########
Collapse file

‎Other/find_min_path.py‎

Copy file name to clipboardExpand all lines: Other/find_min_path.py
+1-5Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,7 @@ def find_min_path(board, start, end):
3838
m = len(board[0])
3939

4040
# create a visited array
41-
visited = []
42-
for row in range(n):
43-
visited.append([])
44-
for el in range(m):
45-
visited[row].append(False)
41+
visited = [[False for el in range(m)] for row in range(n)]
4642

4743
queue = deque()
4844
queue.append((start, 0))
Collapse file

‎Other/generate_parentheses.py‎

Copy file name to clipboardExpand all lines: Other/generate_parentheses.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.
55
66
Input: 3
7-
Output:
7+
Output:
88
[
99
'((()))',
1010
'(()())',
@@ -16,7 +16,7 @@
1616
=========================================
1717
This problem could be solved in several ways (using stack, queue, or just a simple list - see letter_combinations.py), all of them have the same complexity.
1818
I'll solve it using simple recursive algorithm.
19-
Time Complexity: O(4^N) , O(2^(2*N)) = O(2^N)
19+
Time Complexity: O(4^N) , O(2^(2*N)) = O(4^N)
2020
Space Complexity: O(4^N)
2121
'''
2222

Collapse file

‎Other/power.py‎

Copy file name to clipboardExpand all lines: Other/power.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
=========================================
77
Using divide and conquer approach.
88
Time Complexity: O(LogB)
9-
Space Complexity: O(LogB) , because of recursion call stack
9+
Space Complexity: O(LogB) , because of recursion calls stack
1010
'''
1111

1212
############
Collapse file

‎Other/river_sizes.py‎

Copy file name to clipboardExpand all lines: Other/river_sizes.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
This problem can be solved using DFS or BFS.
2222
If 1 is found, find all horizontal or vertical neighbours (1s), and mark them as 0.
2323
Time Complexity: O(N*M)
24-
Space Complexity: O(R) , R = num of rivers
24+
Space Complexity: O(N*M) , because of recursion calls stack
2525
'''
2626

2727

Collapse file

‎Strings/zigzag_conversion.py‎

Copy file name to clipboardExpand all lines: Strings/zigzag_conversion.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
Go row by row and using the steps logic build the new string by jumping chars.
1616
Middle rows have 2 times more elements than the first and last row.
1717
Time Complexity: O(N)
18-
Space Complexity: O(1)
18+
Space Complexity: O(N)
1919
'''
2020

2121

Collapse file

‎Trees/unival_trees.py‎

Copy file name to clipboardExpand all lines: Trees/unival_trees.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
=========================================
1818
Simple tree traversal solution.
1919
Time Complexity: O(N)
20-
Space Complexity: O(1)
20+
Space Complexity: O(N) , because of the recursion stack (but this is if the tree is one branch), O(LogN) if the tree is balanced.
2121
'''
2222

2323

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.