-
Notifications
You must be signed in to change notification settings - Fork 12
Adds initial draft for algorithms topic #117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vulder
wants to merge
1
commit into
master
Choose a base branch
from
prog_des_algorithms
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,126 @@ | ||
| ## Program Design: Algorithms | ||
| ## Program Design: Algorithms {#algo} | ||
|
|
||
| _Skeleton descriptions are typeset in italic text,_ | ||
| _so please don't remove these descriptions when editing the topic._ | ||
|
|
||
| This topic is currently under construction and will soon be filled with information :) | ||
| ### Overview | ||
|
|
||
| _Provides a short natural language abstract of the module’s contents._ | ||
| _Specifies the different levels of teaching._ | ||
|
|
||
| ------------------------------------------------------------------------ | ||
| Level Objective | ||
| ----------------- ------------------------------------------------------ | ||
| Foundational Using algorithms | ||
|
|
||
| Main Writing generic algorithms | ||
|
|
||
| Advanced --- | ||
|
|
||
| ------------------------------------------------------------------------ | ||
|
|
||
| ### Motivation | ||
|
|
||
| _Why is this important?_ | ||
| _Why do we want to learn/teach this topic?_ | ||
|
|
||
| Algorithms make it possible to write code saying what you want done and not how you want it to be done. To make that happen, algorithms need to be small and composable building blocks. The C++ standard already offers a wide set of algorithms to choose from. These algorithms form an important part of the standard and get shipped alongside the compiler, so they are well tested and optimized. Hence, prefer to use the standard algorithms when applicable or if you build your own, follow the design principles behind the STL algorithms, so one's own code intertwines well with the standard algorithms. | ||
|
|
||
|
|
||
| ### Topic introduction | ||
|
|
||
| _Very brief introduction to the topic._ | ||
|
|
||
| ### Foundational: Using algorithms {#algo-found} | ||
|
|
||
| #### Background/Required Knowledge | ||
|
|
||
| A student: | ||
|
|
||
| * [[Program Design: Containers - Foundational]][1] | ||
| * [[Program Design: Iterators - Foundational]][2] | ||
|
|
||
| #### Student outcomes | ||
|
|
||
| _A list of things "a student should be able to" after the curriculum._ | ||
| _The next word should be an action word and testable in an exam._ | ||
| _Max 5 items._ | ||
|
|
||
| A student should be able to: | ||
|
|
||
| 1. find and use an appropriate algorithm from the standard library. | ||
| 2. combine multiple algorithms together to solve a problem. | ||
| 3. refactor traditional style for/while loops into algorithms. | ||
| 4. make an informed choice when using different algorithm flavors (mod/non-mod, iterator/range based, member/free-standing). | ||
|
|
||
|
|
||
| #### Caveats | ||
|
|
||
| _This section mentions subtle points to understand, like anything resulting in | ||
| implementation-defined, unspecified, or undefined behavior._ | ||
|
|
||
|
|
||
| #### Points to cover | ||
|
|
||
| _This section lists important details for each point._ | ||
|
|
||
| * Show how containers and algorithms are conceptually decoupled | ||
| * Discuss the tradeoffs between member algorithms and non-member (free functions) algorithms | ||
| * Flavors of algorithms: | ||
| * modifying/non modifying (e.g., transform vs accumulate) | ||
| * requirements on the type iterator (forward/random-access) | ||
| * iterator-based algorithms vs range-based algorithms | ||
| * Composability of algorithms: | ||
| * composing algorithms by making use of the returning iterator (i.e., find-erase idiom). | ||
| * sequential composability of algorithms (e.g., partition-based quicksort implementation) | ||
| * Customizability of algorithms | ||
| * exchanging default operations in algorithms with user-defined semantics (e.g., find_if or accumulate with another binary operation) [dep: lambdas] | ||
| * expressiveness of code using algorithm (functional programming patterns) | ||
| * std::accumulate | ||
| * write what you want done instead of how | ||
|
|
||
|
|
||
| ### Main: Writing generic algorithms {#algo-main} | ||
|
|
||
| #### Background/Required Knowledge | ||
|
|
||
| * [[Program Design: Concepts - Foundational/Main]][3] | ||
| * Callables | ||
| * [Optional] Foundational/Main: type-traits (templates) | ||
|
|
||
|
|
||
| #### Student outcomes | ||
|
|
||
| A student should be able to: | ||
|
|
||
| 1. write a generic algorithm, such as `std::copy` or `std::transform`. | ||
| 2. determine the time/space complexity of their algorithm. | ||
| 3. write an algorithm that is available to the largest set of applicable types. | ||
| 4. specify the interface and compile-time requirements of an algorithm using concepts. | ||
| 5. implement customization choices for an algorithm (e.g., specialize an algorithm’s implementation with regard to the given iterator type, policy class, type trait, …). | ||
|
|
||
|
|
||
| #### Caveats | ||
|
|
||
| * Reinventing the wheel: try not implement algorithms that already exist | ||
|
|
||
| #### Points to cover | ||
|
|
||
| * Try to use the smallest set of specified operations (e.g., iterators) to make algorithms apply to many cases. | ||
| * Patterns to implement customization choices | ||
| * policy classes | ||
| * type traits (link [optional] type traits) | ||
| * defining requirements/specializations and their connection to the design/implementation of the algorithm (e.g., `std::advance()` is different for forward/random-access iterators) | ||
| * When defining generic parameters, prefer concepts to specify the required interface of the generic type if possible (see: link to concepts). | ||
| * Algorithms should be composable building blocks: focus on a specific task and do it well compared to building one large algorithm that solves multiple problems (e.g., `std::sort` and `std::unique` and not `std::sort_unique`). | ||
|
|
||
| ### Advanced | ||
|
|
||
| _These are important topics that are not expected to be covered but provide | ||
| guidance where one can continue to investigate this topic in more depth._ | ||
|
|
||
| * Parallel algorithms through execution policies | ||
|
|
||
| [1]: ../program-design/containers.md | ||
| [2]: ../program-design/iterators.md | ||
| [3]: ../program-design/concepts.md | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"type iterator" should probably be "type of iterator" or perhaps more precisely "iterator category"