Skip to content

Commit da61266

Browse files
committed
all the complexities added with $ symbol as requested
1 parent 940b2bd commit da61266

10 files changed

+58
-58
lines changed

dsa-solutions/gfg-solutions/problems/BFS-traversal-of-graph.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ Consider the following graph:
3737

3838
Your task is to complete the function `bfs()`, which takes the graph, the number of vertices, and the source vertex as its arguments and prints the BFS traversal of the graph starting from the source vertex.
3939

40-
Expected Time Complexity: O(V + E), where V is the number of vertices and E is the number of edges in the graph.
41-
Expected Auxiliary Space: O(V).
40+
Expected Time Complexity: $O(V + E)$, where V is the number of vertices and E is the number of edges in the graph.
41+
Expected Auxiliary Space: $O(V)$.
4242

4343
## Constraints
4444

45-
- `1 <= number of vertices <= 10^3`
46-
- `0 <= value of vertices <= 10^3`
45+
- `$1 <= number of vertices <= 10^3$`
46+
- `$0 <= value of vertices <= 10^3$`
4747

4848
## Problem Explanation
4949

@@ -129,11 +129,11 @@ Here's the step-by-step breakdown of the BFS traversal process:
129129
130130
## Time Complexity
131131
132-
O(V + E), where V is the number of vertices and E is the number of edges in the graph. Each vertex and edge are visited only once.
132+
$O(V + E)$, where V is the number of vertices and E is the number of edges in the graph. Each vertex and edge are visited only once.
133133
134134
## Space Complexity
135135
136-
O(V), where V is the number of vertices. The space is used to store the visited array and the queue.
136+
$O(V)$, where V is the number of vertices. The space is used to store the visited array and the queue.
137137
138138
## Resources
139139

dsa-solutions/gfg-solutions/problems/Check-for-balanced-tree.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ Output: No
4646

4747
Your task is to complete the function `isBalanced()`, which takes the root of the binary tree as its argument and returns a boolean value indicating whether the tree is balanced or not.
4848

49-
Expected Time Complexity: O(N).
50-
Expected Auxiliary Space: O(h), where h is the height of the tree.
49+
Expected Time Complexity: $O(N)$.
50+
Expected Auxiliary Space: $O(h)$, where h is the height of the tree.
5151

5252
## Constraints
5353

54-
- `1 <= number of nodes <= 10^5`
55-
- `1 <= data of node <= 10^5`
54+
- `$1 <= number of nodes <= 10^5$`
55+
- `$1 <= data of node <= 10^5$`
5656

5757
## Problem Explanation
5858

@@ -131,11 +131,11 @@ Here's the step-by-step breakdown of the checking process:
131131
132132
## Time Complexity
133133
134-
O(N), where N is the number of nodes in the tree. The function visits each node once.
134+
$O(N)$, where N is the number of nodes in the tree. The function visits each node once.
135135
136136
## Space Complexity
137137
138-
O(h), where h is the height of the tree. This is due to the recursive stack space used during the depth-first traversal.
138+
$O(h)$, where h is the height of the tree. This is due to the recursive stack space used during the depth-first traversal.
139139
140140
## Resources
141141

dsa-solutions/gfg-solutions/problems/DFS-traversal-of-graph.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ Consider the following graph:
3737

3838
Your task is to complete the function `dfs()`, which takes the graph, the number of vertices, and the source vertex as its arguments and prints the DFS traversal of the graph starting from the source vertex.
3939

40-
Expected Time Complexity: O(V + E), where V is the number of vertices and E is the number of edges in the graph.
41-
Expected Auxiliary Space: O(V).
40+
Expected Time Complexity: $O(V + E)$, where V is the number of vertices and E is the number of edges in the graph.
41+
Expected Auxiliary Space: $O(V)$.
4242

4343
## Constraints
4444

45-
- `1 <= number of vertices <= 10^3`
46-
- `0 <= value of vertices <= 10^3`
45+
- `$1 <= number of vertices <= 10^3$`
46+
- `$0 <= value of vertices <= 10^3$`
4747

4848
## Problem Explanation
4949

@@ -111,11 +111,11 @@ Here's the step-by-step breakdown of the DFS traversal process:
111111
112112
## Time Complexity
113113
114-
O(V + E), where V is the number of vertices and E is the number of edges in the graph. Each vertex and edge are visited only once.
114+
$O(V + E)$, where V is the number of vertices and E is the number of edges in the graph. Each vertex and edge are visited only once.
115115
116116
## Space Complexity
117117
118-
O(V), where V is the number of vertices. The space is used to store the visited array.
118+
$O(V)$, where V is the number of vertices. The space is used to store the visited array.
119119
120120
## Resources
121121

dsa-solutions/gfg-solutions/problems/Delete-middle-of-linked-list.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ Output: 1 -> 2 -> 4
3636

3737
Your task is to complete the function `deleteMid()`, which takes the head of the linked list as its argument and returns the head of the modified list after the middle node has been deleted.
3838

39-
Expected Time Complexity: O(N).
40-
Expected Auxiliary Space: O(1).
39+
Expected Time Complexity: $O(N)$.
40+
Expected Auxiliary Space: $O(1)$.
4141

4242
## Constraints
4343

44-
- `1 <= number of nodes <= 10^3`
45-
- `1 <= value of nodes <= 10^3`
44+
- `$1 <= number of nodes <= 10^3$`
45+
- `$1 <= value of nodes <= 10^3$`
4646

4747
## Problem Explanation
4848

@@ -124,11 +124,11 @@ Here's the step-by-step breakdown of the deletion process:
124124
125125
## Time Complexity
126126
127-
O(N), where N is the number of nodes in the list. The function traverses the list once to find the middle node.
127+
$O(N)$, where N is the number of nodes in the list. The function traverses the list once to find the middle node.
128128
129129
## Space Complexity
130130
131-
O(1), constant space complexity. The algorithm uses only a few additional pointers for traversal and modification, which does not depend on the input size.
131+
$O(1)$, constant space complexity. The algorithm uses only a few additional pointers for traversal and modification, which does not depend on the input size.
132132
133133
## Resources
134134

dsa-solutions/gfg-solutions/problems/Delete-without-head-pointer.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ Output: 10 4 30
4040

4141
Your task is to complete the function `deleteNode()`, which takes a reference to the node to be deleted and modifies the linked list directly. You should not return anything from the function.
4242

43-
Expected Time Complexity: O(1).
44-
Expected Auxiliary Space: O(1).
43+
Expected Time Complexity: $O(1)$.
44+
Expected Auxiliary Space: $O(1)$.
4545

4646
## Constraints
4747

48-
- `2 <= number of nodes <= 10^3`
49-
- `1 <= value of nodes <= 10^3`
48+
- `$2 <= number of nodes <= 10^3$`
49+
- `$1 <= value of nodes <= 10^3$`
5050

5151
## Problem Explanation
5252

@@ -92,11 +92,11 @@ Here's the step-by-step breakdown of the deletion process:
9292
9393
## Time Complexity
9494
95-
O(1), since the node is deleted in constant time by copying the data and updating pointers.
95+
$O(1)$, since the node is deleted in constant time by copying the data and updating pointers.
9696
9797
## Space Complexity
9898
99-
O(1), constant space complexity, as no extra space is used beyond a few pointers.
99+
$O(1)$, constant space complexity, as no extra space is used beyond a few pointers.
100100
101101
## Resources
102102

dsa-solutions/gfg-solutions/problems/Implement-two-stacks-in-an-array.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ Your task is to complete the class `TwoStacks` which should contain the followin
5151
- `int pop1()`: Pops the top element from the first stack and returns it. Returns `-1` if the first stack is empty.
5252
- `int pop2()`: Pops the top element from the second stack and returns it. Returns `-1` if the second stack is empty.
5353

54-
Expected Time Complexity: O(1) for all the operations.
55-
Expected Auxiliary Space: O(1) for all the operations.
54+
Expected Time Complexity: $O(1)$ for all the operations.
55+
Expected Auxiliary Space: $O(1)$ for all the operations.
5656

5757
## Constraints
5858

59-
- `1 <= N <= 100`
60-
- `1 <= x <= 100`
59+
- `$1 <= N <= 100$`
60+
- `$1 <= x <= 100$`
6161

6262
## Problem Explanation
6363

@@ -188,11 +188,11 @@ Here's the step-by-step breakdown of implementing two stacks in a single array:
188188
189189
## Time Complexity
190190
191-
O(1) for all the operations, as the operations of push and pop involve a fixed number of steps.
191+
$O(1)$ for all the operations, as the operations of push and pop involve a fixed number of steps.
192192
193193
## Space Complexity
194194
195-
O(1) auxiliary space, as the additional space used does not depend on the input size and is constant.
195+
$O(1)$ auxiliary space, as the additional space used does not depend on the input size and is constant.
196196
197197
## Resources
198198

dsa-solutions/gfg-solutions/problems/Intersection-of-two-sorted-linked-lists.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ Output: Empty List
3838

3939
Your task is to complete the function `findIntersection()`, which takes the heads of both linked lists as arguments and returns the head of the new linked list representing their intersection.
4040

41-
Expected Time Complexity: O(N + M), where N and M are the lengths of the two linked lists.
42-
Expected Auxiliary Space: O(1).
41+
Expected Time Complexity: $O(N + M)$, where N and M are the lengths of the two linked lists.
42+
Expected Auxiliary Space: $O(1)$.
4343

4444
## Constraints
4545

46-
- `1 <= number of nodes <= 10^5`
47-
- `1 <= value of nodes <= 10^5`
46+
- `$1 <= number of nodes <= 10^5$`
47+
- `$1 <= value of nodes <= 10^5$`
4848

4949
## Problem Explanation
5050

@@ -126,11 +126,11 @@ Here's the step-by-step breakdown of finding the intersection:
126126
127127
## Time Complexity
128128
129-
O(N + M), where N and M are the lengths of the two linked lists. The function visits each node in both linked lists once.
129+
$O(N + M)$, where N and M are the lengths of the two linked lists. The function visits each node in both linked lists once.
130130
131131
## Space Complexity
132132
133-
O(1), constant space complexity. The algorithm uses only a few additional pointers for traversal and modification, which does not depend on the input size.
133+
$O(1)$, constant space complexity. The algorithm uses only a few additional pointers for traversal and modification, which does not depend on the input size.
134134
135135
## Resources
136136

dsa-solutions/gfg-solutions/problems/Reverse-a-doubly-linked-list.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ Output: 196 59 122 75
3535

3636
Your task is to complete the given function reverseDLL(), which takes head reference as argument and this function should reverse the elements such that the tail becomes the new head and all pointers are pointing in the right order. You need to return the new head of the reversed list. The printing and verification is done by the driver code.
3737

38-
Expected Time Complexity: O(n).
39-
Expected Auxiliary Space: O(1).
38+
Expected Time Complexity: $O(n)$.
39+
Expected Auxiliary Space: $O(1)$.
4040

4141
## Constraints
4242

43-
- `1 <= number of nodes <= 10^4`
44-
- `0 <= value of nodes <= 10^4`
43+
- `$1 <= number of nodes <= 10^4$`
44+
- `$0 <= value of nodes <= 10^4$`
4545

4646
## Problem Explanation
4747

@@ -116,11 +116,11 @@ def reverse_doubly_linked_list(head):
116116

117117
## Time Complexity
118118

119-
O(n), where n is the number of nodes in the list. This is because the loop iterates through each node once.
119+
$O(n)$, where n is the number of nodes in the list. This is because the loop iterates through each node once.
120120

121121
## Space Complexity
122122

123-
O(1), constant space complexity. The algorithm uses only a few additional pointers for temporary storage, which does not depend on the input size.
123+
$O(1)$, constant space complexity. The algorithm uses only a few additional pointers for temporary storage, which does not depend on the input size.
124124

125125
## Resources
126126

dsa-solutions/gfg-solutions/problems/Reverse-a-linked-list.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ elements are 10->9->8->7->2.
4242

4343
The task is to complete the function reverseList() with head reference as the only argument and should return new head after reversing the list.
4444

45-
Expected Time Complexity: O(N).
46-
Expected Auxiliary Space: O(1).
45+
Expected Time Complexity: $O(N)$.
46+
Expected Auxiliary Space: $O(1)$.
4747

4848
## Constraints
4949

50-
`1 <= N <= 10^4`
50+
- `$1 <= N <= 10^4$`
5151

5252
## Problem Explanation
5353

@@ -128,11 +128,11 @@ By repeating these steps, you traverse the linked list, reverse the links in pla
128128

129129
1. Reversing a linked list involves iterating through the list to manipulate the pointers between nodes. In the worst case, you need to visit every single node in the list to reverse the connections.
130130

131-
2. Any efficient reversal algorithm will require at least one pass through the entire list. This takes O(n) time.
131+
2. Any efficient reversal algorithm will require at least one pass through the entire list. This takes $O(n)$ time.
132132

133133
## Space Complexity:
134134

135-
The space complexity is typically denoted as O(1), which signifies constant space. This means the extra memory usage doesn't depend on the input size.
135+
The space complexity is typically denoted as $O(1)$, which signifies constant space. This means the extra memory usage doesn't depend on the input size.
136136

137137
## References
138138

dsa-solutions/gfg-solutions/problems/Square-root.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ Explanation: The square root of 8 is 2.82842..., and since we want the floor val
3636

3737
Your task is to complete the function `sqrt()`, which takes an integer x as an argument and returns the floor value of its square root.
3838

39-
Expected Time Complexity: O(log x).
40-
Expected Auxiliary Space: O(1).
39+
Expected Time Complexity: $O(log x)$.
40+
Expected Auxiliary Space: $O(1)$.
4141

4242
## Constraints
4343

44-
- `0 <= x <= 10^9`
44+
- `$0 <= x <= 10^9$`
4545

4646
## Problem Explanation
4747

@@ -122,11 +122,11 @@ Here's the step-by-step breakdown of finding the square root:
122122
123123
## Time Complexity
124124
125-
O(log x), where x is the input number. The binary search approach reduces the search space logarithmically.
125+
$O(log x)$, where x is the input number. The binary search approach reduces the search space logarithmically.
126126
127127
## Space Complexity
128128
129-
O(1), constant space complexity. The algorithm uses a fixed amount of extra space regardless of the input size.
129+
$O(1)$, constant space complexity. The algorithm uses a fixed amount of extra space regardless of the input size.
130130
131131
## Resources
132132

0 commit comments

Comments
 (0)