Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Mooophy committed Apr 6, 2015
1 parent 8827cee commit bbd7222
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions ch02/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
2 Getting Started
--------------------------------------------------------
##Ex2.1-1
```cpp
algorithm begin:
Expand All @@ -9,10 +11,8 @@ algorithm begin:
end

```
##Ex2.1-2
##Ex2.1-2 [insertion_sort](src/insertion_sort.hpp) | [test](test/test_insertion_sort.cpp)
* A functor for comparison can be passed in to specify order direction, such as `std::greater<T>` or `std::less<T>`
* Implementation: `insertion_sort.hpp`
* Test: `test_insertion_sort.cpp`
##Ex2.1-3
* Pseudocode:
Expand Down Expand Up @@ -51,7 +51,7 @@ I and M and T ->
this algorithm is correct.
```

##Ex2.1-4
##Ex2.1-4 [add_binary_numbers](src/add_binary_numbers.hpp) | [test](test/test_add_binary_numbers.cpp)
* Problem description:
```cpp
Input: two arrays lhs and rhs which store two n-bit binary numbers respectively
Expand All @@ -68,15 +68,13 @@ Add-Binary-Numbers(lhs, rhs)
6 sum[0] = carry
7 return sum
```
* Implementation : `add_binary_numbers.hpp`
* Test : `test_add_binary_numbers.cpp`

##Ex2.2-1
```cpp
\theta(n^3)
```

##Ex2.2-2
##Ex2.2-2 [selection_sort](src/selection_sort.hpp) | [test](test/test_selection_sort.cpp)
* Pseudocode:
```cpp
Selection-Sort(arr)
Expand All @@ -101,8 +99,6 @@ Also items in range [0, i) have been sorted.
For best case, time complexity for line 5 equals to 0. Total time required : \theta(n^2)
For worst case, time complexity for line 5 equals to c5 x (n - 2) x (n / 2 - 1). Total time required : \theta(n^2)
```
* Implementaion: `selection_sort.hpp`
* Test: `test_selection_sort.cpp`
##Ex2.2-3
* n/2 elements need to be checked on average.
Expand All @@ -121,9 +117,7 @@ Not sure about this question.Perhaps a precheck can be carried out to see if the
{3} {41} {52} {26} {38} {57} {9} {49}
```

##Ex2.3-2
* Implementation: `merge_sort.hpp`
* Test: `test_merge_sort.cpp`
##Ex2.3-2 [merge_sort](src/merge_sort.hpp) | [test](test_merge_sort.cpp)

##Ex2.3-3
```cpp
Expand Down Expand Up @@ -310,8 +304,7 @@ I.M.T -> LI holds.
* d. time complexity = theta(n^2). Insertion-Sort is better. Because for average case and best case Insertion-Sort doesn't have to carry out theta(n) for its nested loop. whereas Bubble-Sort has to do so for any case.
##Problem 2-3 Horner’s rule
* code : `polynomial.hpp`, `test_polynomial.hpp`
##Problem 2-3 Horner’s rule [implementation](src/polynomial.hpp)|[test])(test/test_polynomial.hpp)
* Time complexity : theta(n)
* pseudocode
```python
Expand Down Expand Up @@ -364,7 +357,7 @@ L.I. holds.
* As shown above, this code fragment correctly evaluates a polynomial.
##Problem 2-4 Inversions
##Problem 2-4 Inversions [implementation](find_inversions.hpp)|[test](test_find_inversions.cpp)
* Five inversions:
```cpp
{2,1}, {3,1}, {8,1}, {6,1}, {8,6}
Expand All @@ -383,4 +376,3 @@ Modify Merge-Sort as following:
1 Pass count as a reference or a pointer into procedure Merge and Merge-Sort
2 add statement : count += n1 - i into Merge between line 16 and line 17
```
* code : `find_inversions.hpp` and `test_find_inversions.cpp`.

0 comments on commit bbd7222

Please sign in to comment.