Skip to content

Commit ac06b1f

Browse files
committed
Fixed Typos
1 parent 48c7f69 commit ac06b1f

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

Ordered Set/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ An Ordered Set is a collection of unique items in sorted order. Items are usuall
33
For example, we could define "a" and "z" to have the same value (their lengths), but clearly "a" != "z".
44

55
## Why use an Ordered Set?
6-
Ordered Sets should be considered for use when you need to require keeping your collection sorted at all times, and do lookups on the collection much more freuqently than inserting or deleting items. A good example would be keeping track of the rankings of players in a scoreboard (see example 2 below). Many of the lookup operations for an Ordered Set are **O(1)**.
6+
Ordered Sets should be considered for use when you require keeping your collection sorted at all times, and do lookups on the collection much more freuqently than inserting or deleting items. A good example would be keeping track of the rankings of players in a scoreboard (see example 2 below). Many of the lookup operations for an Ordered Set are **O(1)**.
77

88
### These are Ordered Sets
99
```
@@ -26,7 +26,7 @@ This Set violates the sorted property
2626
```
2727

2828
## The Code
29-
We'll start by creating our internal representation for the Ordered Set. Since the idea of a set is similar to that of an array, we will use an array to represent our set. Furthermore, since we'll need to keep our set sorted, we need to compare the individual elemants. Thus, any type must conform to the [Comparable Protocol](https://developer.apple.com/library/watchos/documentation/Swift/Reference/Swift_Comparable_Protocol/index.html).
29+
We'll start by creating our internal representation for the Ordered Set. Since the idea of a set is similar to that of an array, we will use an array to represent our set. Furthermore, since we'll need to keep our set sorted, we need to compare the individual elements. Thus, any type must conform to the [Comparable Protocol](https://developer.apple.com/library/watchos/documentation/Swift/Reference/Swift_Comparable_Protocol/index.html).
3030

3131
``` swift
3232
public struct OrderedSet<T: Comparable> {
@@ -68,7 +68,7 @@ Lets take a look at the insert function first. The insert function first checks
6868
internalSet.append(item)
6969
}
7070
```
71-
The first part of the function checks if the item is already in the set.As we'll see later on, this has an efficiency of **O(log(n) + k)** where k is the number of items with the same value as the item we are inserting. The second part iterates through the interal array so that it can find a spot for our given item. This is at worse **O(n)**. The insert function for arrays has an efficiency of **O(log(n))**, thus making the insert function for our Ordered Set **O(log(n) + k)**.
71+
The first part of the function checks if the item is already in the set. As we'll see later on, this has an efficiency of **O(log(n) + k)** where k is the number of items with the same value as the item we are inserting. The second part iterates through the interal array so that it can find a spot for our given item. This is at worse **O(n)**. The insert function for arrays has an efficiency of **O(nlog(n))**, thus making the insert function for our Ordered Set **O(nlog(n))**.
7272

7373

7474
Next we have the `remove` function. First check if the item exists. If not, then return and no nothing. If it does exist, remove it.
@@ -83,7 +83,7 @@ Next we have the `remove` function. First check if the item exists. If not, then
8383
internalSet.removeAtIndex(findIndex(item))
8484
}
8585
```
86-
Again, because of the `exists` function, the efficiency for remove is **O(log(n) + k)**
86+
Again, because of the `removeAtIndex` function, the efficiency for remove is **O(nlog(n))**
8787

8888
The next function is the `findIndex` function which takes in an item of type `T` and returns the index of the item if it is in the set, otherwise returns -1.
8989

@@ -194,7 +194,7 @@ Since the set is sorted, the following operations are all **O(1)**:
194194
Below are a few examples that can be found in the playground file.
195195

196196
### Example 1
197-
Here we create a set with random Integers. Pringint the largest/smallest 5 numbers in the set is fairly easy.
197+
Here we create a set with random Integers. Printing the largest/smallest 5 numbers in the set is fairly easy.
198198
``` swift
199199
// Example 1 with type Int
200200
var mySet = OrderedSet<Int>()
@@ -248,7 +248,7 @@ func <(x: Player, y: Player) -> Bool {
248248
return x.points < y.points
249249
}
250250
```
251-
The set we create will hold players. One thing to note is that two `Player`'s can each have the same value, but are not guaranteed to be equal.
251+
The set we create will hold players. One thing to note is that two `Player`s can each have the same value, but are not guaranteed to be equal.
252252

253253
Inserting 20 random players and one player we will track of.
254254
``` swift
@@ -272,7 +272,7 @@ print(playerSet.max())
272272
print(playerSet.min())
273273
```
274274

275-
Next we use the findIndex function to find out what rank `anotherPlayer` in comparison to the other `Player`s.
275+
Next we use the findIndex function to find out what rank `anotherPlayer` is.
276276
``` swift
277277
// we'll find our player now
278278
print("'Another Player (\(anotherPlayer.name))' is ranked at level: \(playerSet.count - playerSet.findIndex(anotherPlayer)) with \(anotherPlayer.points) points")

0 commit comments

Comments
 (0)