mirror of
https://github.com/prdlk/leetcode.git
synced 2026-11-02 21:22:43 +00:00
docs(docs): restructure and expand documentation with new phases and content
This commit is contained in:
1 parent
9d58f2e5bb
commit
cc7815e9c4
20 files changed
+321
-411
No files matched your search
@@ -0,0 +1,65 @@
|
||||
---
|
||||
title: 'Arrays and Strings'
|
||||
description: 'In algorithms, arrays and strings are very similar. They are both ordered collections of elements. The difference is that arrays are mutable, while strings are immutable.'
|
||||
sidebar:
|
||||
label: Arrays & Strings
|
||||
---
|
||||
|
||||
|
||||
Technically, an array can't be resized. A dynamic array, or list, can be. In the context of algorithm problems, usually when people talk about arrays, they are referring to dynamic arrays. In this entire course, we will be talking about dynamic arrays/lists, but we will just use the word "array".
|
||||
|
||||
## Time Complexity
|
||||
|
||||
Arrays and strings are both ordered collections of elements. The difference is that arrays are mutable, while strings are immutable.
|
||||
|
||||
| Operation | Array/List | String(Immutable) |
|
||||
| --------- | ---------- | ----------------- |
|
||||
| Appending to end | *O(1) | O(n) |
|
||||
| Popping from end | O(1) | O(n) |
|
||||
| Insertion, not from end | O(n) | O(n) |
|
||||
| Deletion, not from end | O(n) | O(n) |
|
||||
| Modifying an element | O(1) | O(n) |
|
||||
| Random access | *O(1) | O(n) |
|
||||
| Checking if an element exists | O(1) | O(n) |
|
||||
|
||||
:::note[Clarification 1]
|
||||
Appending to the end of a list is amortized O(1) time complexity. This means that the time complexity of appending to the end of a list is the same as the time complexity of appending to the end of an array.
|
||||
:::
|
||||
|
||||
:::note[Clarification 2]
|
||||
Random access in this context means that you can access an element at any index in constant time.
|
||||
:::
|
||||
|
||||
## Patterns
|
||||
|
||||
<Columns cols={2}>
|
||||
<Column>
|
||||
<Tile
|
||||
title="Two Pointers"
|
||||
description="Ship your first page in minutes."
|
||||
href="/arrays-and-strings/two-pointers"
|
||||
>
|
||||
<Icon icon="rocket" size={28} />
|
||||
</Tile>
|
||||
</Column>
|
||||
<Column>
|
||||
<Tile
|
||||
title="Sliding Window"
|
||||
description="Ship your first page in minutes."
|
||||
href="/docs/quickstart"
|
||||
>
|
||||
<Icon icon="rocket" size={28} />
|
||||
</Tile>
|
||||
</Column>
|
||||
<Column>
|
||||
<Tile
|
||||
title="Prefix Sum"
|
||||
description="Ship your first page in minutes."
|
||||
href="/docs/quickstart"
|
||||
>
|
||||
<Icon icon="rocket" size={28} />
|
||||
</Tile>
|
||||
</Column>
|
||||
</Columns>
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
---
|
||||
title: 'Hashing'
|
||||
description: 'In algorithms, arrays and strings are very similar. They are both ordered collections of elements. The difference is that arrays are mutable, while strings are immutable.'
|
||||
sidebar:
|
||||
label: Hashing
|
||||
---
|
||||
|
||||
|
||||
Technically, an array can't be resized. A dynamic array, or list, can be. In the context of algorithm problems, usually when people talk about arrays, they are referring to dynamic arrays. In this entire course, we will be talking about dynamic arrays/lists, but we will just use the word "array".
|
||||
|
||||
## Time Complexity
|
||||
|
||||
Arrays and strings are both ordered collections of elements. The difference is that arrays are mutable, while strings are immutable.
|
||||
|
||||
| Operation | Array/List | String(Immutable) |
|
||||
| --------- | ---------- | ----------------- |
|
||||
| Appending to end | *O(1) | O(n) |
|
||||
| Popping from end | O(1) | O(n) |
|
||||
| Insertion, not from end | O(n) | O(n) |
|
||||
| Deletion, not from end | O(n) | O(n) |
|
||||
| Modifying an element | O(1) | O(n) |
|
||||
| Random access | *O(1) | O(n) |
|
||||
| Checking if an element exists | O(1) | O(n) |
|
||||
|
||||
:::note[Clarification 1]
|
||||
Appending to the end of a list is amortized O(1) time complexity. This means that the time complexity of appending to the end of a list is the same as the time complexity of appending to the end of an array.
|
||||
:::
|
||||
|
||||
:::note[Clarification 2]
|
||||
Random access in this context means that you can access an element at any index in constant time.
|
||||
:::
|
||||
|
||||
Reference in new issue
Block a user