Skip to content

Commit c8a465c

Browse files
committed
Update valid_checking_lru/README.md
1 parent fd9528d commit c8a465c

1 file changed

Lines changed: 29 additions & 26 deletions

File tree

valid_checking_lru/README.md

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -107,72 +107,72 @@ Move it to the front (MRU).
107107

108108
### Lookup (Hit/Miss Checking)
109109

110-
- Using HashMap<tag, Node>, checking if a block is present takes `O(1)`.
110+
- Using `HashMap<tag, Node>`, checking if a block is present takes $O(1)$.
111111

112112
<br>
113113

114114
### Insert New Block (On Miss)
115115

116116
Two scenarios for handling a miss:
117117

118-
1. Use an invalid block: O(N), worst-case requires searching all set entries.
119-
<br>
120-
2. Evict LRU block (if all are valid): O(1).
118+
1. Use an invalid block: $O(N)$, worst-case requires searching all set entries.
119+
120+
2. Evict LRU block (if all are valid): $O(1)$.
121121
<br><br>
122122

123123
**Case 1**: Use an invalid block
124-
Search for a valid=false block: O(N) (N = set_degree, worst case is that all blocks are valid).
125-
Update block's tag and set valid=true: O(1).
126-
Move block to head (most recently used): O(1).
124+
Search for a valid=false block: $O(N)$ (N = set_degree, worst case is that all blocks are valid).
125+
Update block's tag and set valid=true: $O(1)$.
126+
Move block to head (most recently used): $O(1)$.
127127

128-
Overall: O(N) + O(1) + O(1) = `O(N)`
128+
Overall: $O(N) + O(1) + O(1) = O(N)$
129129
(Worst case: scanning all blocks in the set to find an invalid one.)
130130

131131
<br>
132132

133133
**Case 2**: Evict LRU block (All blocks are valid=true)
134-
Find LRU block (always at the tail): O(1).
135-
Replace with new block, update tag, set valid=true: O(1).
136-
Move to head (most recently used): O(1).
134+
Find LRU block (always at the tail): $O(1)$.
135+
Replace with new block, update tag, set valid=true: $O(1)$.
136+
Move to head (most recently used): $O(1)$.
137137

138-
Overall: O(1) + O(1) + O(1) = `O(1)`
138+
Overall: $O(1) + O(1) + O(1) = O(1)$
139139

140140
<br>
141141

142142
### Move Block to Head (On Hit)
143143

144-
- Find in HashMap: O(1).
144+
- Find in HashMap: $O(1)$.
145145

146-
- Remove from current position: O(1).
146+
- Remove from current position: $O(1)$.
147147

148-
- Insert at the front: O(1).
148+
- Insert at the front: $O(1)$.
149149

150-
Overall: O(1) + O(1) + O(1) = `O(1)`.
150+
Overall: $O(1) + O(1) + O(1) = O(1)$.
151151

152152
<br>
153153

154154
### Eviction (When the set is full)
155155

156-
- Identify LRU block (always at the tail): O(1).
156+
- Identify LRU block (always at the tail): $O(1)$.
157157

158-
- Remove from doubly linked list: O(1).
158+
- Remove from doubly linked list: $O(1)$.
159159

160-
- Remove from HashMap: O(1).
160+
- Remove from HashMap: $O(1)$.
161161

162-
- Insert new block at head: O(1).
162+
- Insert new block at head: $O(1)$.
163163

164-
Overall: O(1) + O(1) + O(1) + O(1) = `O(1)`.
164+
Overall: $O(1) + O(1) + O(1) + O(1) = O(1)$.
165165

166166
<br>
167167

168168
### Summary
169169

170170
| Operation | Complexity |
171171
|---------------|--------------|
172-
|Lookup | O(1) |
173-
|Insert | O(N) |
174-
|Move to Head | O(1) |
175-
|Eviction | O(1) |
172+
|Lookup | $O(1)$ |
173+
|Insert | $O(N)$ |
174+
|Move to Head | $O(1)$ |
175+
|Eviction | $O(1)$ |
176176

177177
<br>
178178

@@ -187,8 +187,11 @@ Overall: O(1) + O(1) + O(1) + O(1) = `O(1)`.
187187
### Prerequisites
188188

189189
- [Rust](https://www.rust-lang.org/) (recommended 1.84.1 or higher)
190+
190191
- A terminal or command prompt to run `cargo`
191-
<br><br>
192+
193+
<br>
194+
192195
---
193196

194197
### Building and Running

0 commit comments

Comments
 (0)