fix(guide): simplify directory structure

This commit is contained in:
Mrugesh Mohapatra
2018-10-16 21:26:13 +05:30
parent f989c28c52
commit da0df12ab7
35752 changed files with 0 additions and 317652 deletions

View File

@@ -0,0 +1,27 @@
---
title: Assembly Language
---
## Assembly Language
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
Assembly Language is the interface between higher level languages (C++, Java, etc) and machine code (binary). For a compiled language, the compiler transforms higher level code into assembly language code.
Every family of CPUs define their own Instruction Set Architeture (ISA), a set of basic instructions that the CPU can execute without needing further translation or transformation.
The compiler decomposes composite higher level composite instructions into operations available in the ISA.
Some of the more common ISAS in use today include MIPS, ARM, Intel x86, RISC-V.
Assemblers decompose Assembly instructions into their respective binary representations and replace the generic addresses of assembly code with explicit register and memory addresses of your computer.
Code where execution time and control is crucial can be written directly in assembler. This however comes at the cost of prolonging development time, and making development harder. It should also be noted that there has been a large amount of research going into making compilers optimize the code that is generated automatically.
Assembly language is primarily used in the following situations:
* There is a need to use CPU instructions not available in higher-level languages.
* There is no high-level language to program a certain types of processors.
* Implementing a compiler for a higher level language on a new ISA.
![Image of Levels of Code](https://raw.githubusercontent.com/colbybanbury/assemblyPicture/master/Screenshot%20from%202017-10-14%2014-03-06.png)
#### More Information:
<!-- Please add any articles you think might be helpful to read before writing the article -->

View File

@@ -0,0 +1,65 @@
---
title: Compiled Versus Interpreted Languages
---
## Compiled Versus Interpreted Languages
Every program is a set of instructions, whether it's to add two numbers or send a request over the internet. Compilers and interpreters take human-readable code and convert it to computer-readable machine code. In a compiled language, the target machine directly translates the program. In an interpreted language, the source code is not directly translated by the target machine. Instead, a *different* program, aka the interpreter, reads and executes the code.
### Okay... but what does that *actually* mean?
So let's say you have an hummus recipe that you want to make, but it's in Ancient Greek. There are two ways you, as a non-Ancient-Greek speaker, could follow its directions.
The first is if someone had translated it into English for you already. You (and anyone else who could speak English) could get the English version and make hummus. This is the compiled version.
The second is if you had a friend who knows Ancient Greek. Your friend can sit next to you and translate the Ancient Greek into English, line by line, as you go. In this case, your friend is the interpreter. This is the interpreted version.
### Compiled Languages
Compiled languages are converted directly into machine code that the processor can execute. As a result, they tend to be faster and more efficient to execute than interpreted languages. They also give the developer more control over hardware aspects, like memory management and CPU usage.
Compiled languages need a "build" step - they need to be manually compiled first. You need to "rebuild" the program every time you need to make a change. In our hummus example, the entire translation is written before it gets to you. If the original author decided he wanted to use a different kind of olive oil, the entire recipe would need to be translated again and then sent to you.
Examples of pure compiled languages are C, C++, Erlang, Haskell, Rust, and Go.
### Interpreted Languages
Interpreters will run through a program line by line and execute each command. Now, if the author decided he wanted to use a different kind of olive oil, he could scratch the old one out and add the new one. Your translator friend can then convey that change to you as it happens.
Interpreted languages were once known to be significantly slower than compiled languages. But, with the development of <a href='https://guide.freecodecamp.org/computer-science/just-in-time-compilation' target='_blank' rel='nofollow'>just-in-time compilation</a>, that gap is shrinking.
Examples of common interpreted languages are PHP, Ruby, Python, and JavaScript.
### A Small Caveat
Most programming languages can have both compiled and interpreted implementations. The language itself is not necessarily compiled or interpreted. However, for simplicity's sake, they're typically referred to as such.
Strictly speaking, the terms interpreted language and compiled language are not well defined because, in theory, any programming language can be either interpreted or compiled. In modern programming language implementation it is increasingly popular for a platform to provide both options.
e.g. Python can be executed either as a compiled program, or as an interpreted language in interactive mode.
**Most command line tools, CLIs, and shells can theoretically be classified as interpreted languages.**
### Advantages and Disadvantages
#### Advantages of Compiled Languages
* Programs compiled into native code at compile time usually tend to be faster than those translated at run time, due to the overhead of the translation process.
* All the errors are provided to you at once. This allows the programmer to correct all the mistakes at once and recompile the code for execution.
#### Disadvantages of Compiled Languages
The most notable disadvantages are :-
* Additional time needed to complete the entire compilation step before testing, and
* Platform dependence of the generated binary code.
#### Advantages of Interpreted Languages
An Interpreted language gives implementations some additional flexibility over compiled implementations. Because interpreters execute the source program code themselves, the code itself is platform independent (Java's byte code, for example). Other features include dynamic typing, and smaller executable program size.
#### Disadvantages of Interpreted Languages
* The most notable disadvantage is typical execution speed compared to compiled languages.
* The program stops executing when the first error is encountered; the program (script) continues to execute until the next error is encountered or till program termination.
#### More Information:
<a href='https://en.wikipedia.org/wiki/Compiled_language' target='_blank' rel='nofollow'>Wikipedia - Compiled language</a>
<a href='https://en.wikipedia.org/wiki/Interpreted_language' target='_blank' rel='nofollow'>Wikipedia - Interpreted language</a>
<a href='http://www.programmerinterview.com/index.php/general-miscellaneous/whats-the-difference-between-a-compiled-and-an-interpreted-language/' target='_blank' rel='nofollow'>programmerinterview.com article - Whats the difference between a compiled and interpreted language?</a>

View File

@@ -0,0 +1,59 @@
---
title: Compilers
---
## Compilers
### Programming
At its heart, a barebones computer (aka a stored program computer) is nothing but a machine which knows how to read steps written in a fixed instruction set and execute the same. The set of instructions a computer understands is very specific to it. This is also known as machine language (**opcodes**). Machine Language is often referred to as Binary Code.
Humans interact with computers using **Programs**. A program is simply a sequence of opcodes provided to the computer along with data that is necessary for executing the opcodes.
For example,
```
ADD 10, 20 // ADD is the Opcode
// and 10, 20 are the two operands(data)
// needed for the ADD instruction to be executed successfully
```
Humans develop programs to solve complex problems. Looking at how simple opcodes are, if we try to develop programs using opcodes alone, it will be very cumbersome and difficult to debug. To solve this problem, high level languages like C/C++, Python, Java, Javascript, etc were developed.
Now, high level languages aren't suitable for execution by computers. Hence, the need arose for a translator that can digest the high-level language programs and convert them to machine language instructions suitable for execution by a computer.
#### [HUMANS] -> [Highlevel language programs] -> [Translator] -> [Machine Language] -> [Computer]
A **compiler** is a type of translator program, that translates high level languages into binary code, which is nothing but 1s and 0s. When you run your source code, a compiler translates all the code first, then produces the binary code. Then the computer takes the binary code and runs it.
If there are errors in your source code, the compiler detects and flags them. This stops the compilation process. Once all errors are fixed, the compiler converts the code and generates an executable program.
## Parts of a compiler
Most compilers break down into three primary stages: Parsing, Transformation, and Code Generation
1. *Parsing* is taking raw code and turning it into a more abstract representation of the code.
2. *Transformation* takes this abstract representation and manipulates to do whatever the compiler wants it to.
3. *Code Generation* takes the transformed representation of the code and turns it into new code.
#### Parsing
Parsing typically gets broken down into two phases: **Lexical Analysis** and **Syntactic Analysis**.
*Lexical Analysis* takes the raw code and splits it apart into these things called tokens by a thing called a tokenizer (or lexer).
```
Tokens are an array of tiny little objects that describe an isolated piece of the syntax.
They could be numbers, labels, punctuation, operators, etc.
```
*Syntactic Analysis* takes the tokens and reformats them into a representation that describes each part of the syntax
and their relation to one another. This is known as an intermediate representation or Abstract Syntax Tree.
```
An Abstract Syntax Tree, or AST for short, is a deeply nested object.
It represents code in a way that is both easy to work with and tells us a lot of information.
```
#### Transformation
The next type of stage for a compiler is transformation. Again, this just takes the AST from the last step and makes changes to it.
It can manipulate the AST in the same language or it can translate it into an entirely new language.
#### Code Generation
The final phase of a compiler is code generation. Sometimes compilers will do things that overlap with transformation, but for the most part code generation just takes the AST and converts it to binary code.
All compilers need to perform these steps. Most modern compilers also carry out other steps such as checking for type errors and optimizing the resulting compiled code.
#### More Information:
<a href='https://medium.freecodecamp.org/a-gentler-introduction-to-programming-707453a79ee8' target='_blank' rel='nofollow'>Matt Adesanya's "A Gentler Introduction to Programming"</a> covers compilers vs. interpreters, along with other basic programming concepts.

View File

@@ -0,0 +1,13 @@
---
title: Data Mining
---
## Data Mining
This is a stub. <a href='https://github.com/freecodecamp/guides/tree/master/src/pages/computer-science/databases/index.md' target='_blank' rel='nofollow'>Help our community expand it</a>.
<a href='https://github.com/freecodecamp/guides/blob/master/README.md' target='_blank' rel='nofollow'>This quick style guide will help ensure your pull request gets accepted</a>.
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
#### More Information:
<!-- Please add any articles you think might be helpful to read before writing the article -->

View File

@@ -0,0 +1,39 @@
---
title: Bloom Filter
---
## Description
A Bloom filter is a data structure which is similar to a set. The Bloom filter allows for the question _Is this item a member of the set?_ to be answered quickly. The filter will never return _No_ if the item is in the set; but, it may return _Yes_ if the item is not in the set. This is one downside to using a Bloom filter, there is a chance for false positive results when checking if an item is in the set. An upside to using a Bloom filter is that adding an item to the set and checking if the item is in the set is a constant time [O(n)](https://guide.freecodecamp.org/algorithms/algorithm-performance) operation.
## Example
The following example uses a Bloom filter to create a friend list. The example implementation uses three [hashing functions](https://guide.freecodecamp.org/miscellaneous/hash-tables-and-hashing-functions). The hashing functions ingest a string (a friend name) and calculate a single value for the string based on the number of spots in the Bloom filter.
Create filter as an array of 10 indices. A `0` indicates no item is at that index.
`[0,0,0,0,0,0,0,0,0,0]`
A user adds David to the friend list. The string (`'David'`) is put through several hashing functions which return `0`, `4`, and `8`, respectively. The values from the hashing functions are used to update the filter array at those indices.
The filter indices are updated using those hashed values. A `1` indicates an item has been added at that index.
`[1,0,0,0,1,0,0,0,1,0]`
A user adds Rosie to the friend list. The hashing functions return `3`, `4`, and `6` for `'Rosie'`. The filter indices are updated using the hashed values.
`[1,0,0,1,1,0,1,0,1,0]`
There is a check if Chuck is a member of the friend list. The string `'Chuck'` is put through the hashing functions returning `1`, `3`, and `6`. When the filter array is checked at those indices, it returns `0`, `1`, and `1`. Because one index has a `0` value, Chuck is _definitely_ not a member of the list.
There is a check if Maja is a member of the friend list. The string `'Maja'` is put through the hashing functions, returning `0`, `6`, and `8`. When the filter array is checked at those indices, it returns `1`, `1`, and `1`. Because all three indices have a value of `1`, Maja _may_ already be a member of the list. This is a false positive result.
## Considerations
Bloom filters allow for quick look up to determine if a value is _possibly_ a member of the set or _definitely_ not a member of the set. The more items added to the Bloom filter the rate of false positive results when checking if an item is a member of the set will increase. One way to decrease the rate of false positive results is to increase the size of the array. Although this is a compromise because the larger the array, the greater memory it will occupy. It is necessary to determine an acceptable rate of false positive results for a given array size.
## Further Reading
[Medium's Post Recommendation Algorithm](https://blog.medium.com/what-are-bloom-filters-1ec2a50c68ff)
[Wikipedia on Bloom filters](https://en.wikipedia.org/wiki/Bloom_filter)

View File

@@ -0,0 +1,225 @@
---
title: Dictionaries
---
## Dictionaries
Let's assume we have a homogeneous list. We want to count how many times each item occurs in the list. How can we do that, without using Python's built-in methods such as count or Counter from the Python collections module? A Google search for "How to count the occurrences of an item in a list?" will return Stack Overflow answers pointing you to the count method and the collections module, but for learning purposes let's try to solve the problem without using these tools.
Here's the list we'll be working with:
```python
ice_cream = ["strawberry",
"vanilla",
"vanilla",
"chocolate",
"chocolate",
"chocolate",
"banana",
"rum raisin",
"banana"]
```
This code, using nested for loops, produces the right answer, storing the answer in the list "count":
```python
count = []
for flavor in ice_cream:
found = False
for entry in count:
if entry[0] == flavor:
entry[1] += 1
found = True
if not found:
count.append([flavor, 1])
# Print.
for (entry, total) in count:
print (entry, total)
```
Although this code gives the correct answer, there are two things wrong with it. First, it is complex. The more nested loops a program contains, the harder it is to understand, fix, and extend. Moreover, it is inefficient. This may not be a problem in this small example, but imagine a list with thousands or millions of items. Scanning the list of entries each time we make an observation would take a very, very long time, no matter how fast the computer. This is a topic addressed more fully when studying topics such as big O notation and comparing searching and sorting algorithms.
A better answer is to use another data structure known as a **dictionary** or **map**. This data structure is an *unordered, mutable* collection of *key / value* pairs. Think of a dictionary like a phonebook, where the key is the person's name, and the value is the phone number. Keys in a dictionary form a set, meaning they can only appear once, and they cannot be changed (they are immutable), although the values associated with a key can be changed.
Dictionaries are created by putting key/value pairs inside of braces. To get the value associated with a key, you put the key in square brackets.
Here are some code examples:
```python
ice_cream = {'chocolate' : 3, 'strawberry' : 1}
print (ice_cream)
>> {'chocolate' : 3, 'strawberry' : 1}
print (ice_cream['strawberry'])
>> 1
```
To test whether a key is in a dictionary, use k in d:
```python
ice_cream = {'chocolate' : 3, 'strawberry' : 1}
if 'chocolate' in ice_cream:
print ('chocolate is in the list')
...
del ice_cream['chocolate']
if 'chocolate' in ice_cream:
print ('oops: why is chocolate still there?')
```
**Updating and Membership**
To update dictionaries, just assign a value to a key. If the key is already in the dictionary, this changes the value associated with it.
If the key was not present, it is added, along with the value:
```python
ice_cream = {}
ice_cream['chocolate'] = 33
ice_cream['vanilla'] = 999 # oops
print (ice_cream)
>> {'chocolate' : 33, vanilla' : 999}
ice_cream['vanilla'] = 9
print (ice_cream)
>> {'chocolate' : 33, vanilla' : 9}
```
Use *del d[k]*, to remove an entry from a dictionary, where *d* is the dictionary name and *k* is the key being removed. Only entries that are present can be removed; trying to remove one that isnt there causes an error:
```python
ice_cream = {'chocolate' : 33, vanilla' : 9}
del ice_cream['chocolate']
print (ice_cream)
>> {'vanilla' : 9}
del ice_cream['strawberry']
>> Traceback (most recent call last):
File "<stdin>", line 5, in <module>
KeyError: 'strawberry'
```
**Loops**
Since dictionaries are collections (along with lists, tuples, and sets), were going to want to loop over their
contents. We do this with a for loop, which assigns each of the keys in the dictionary to the loop variable in turn:
```python
ice_cream = {'chocolate' : 183,
'vanilla' : 71,
'strawberry' : 63,
'banana', 1}
for flavor in ice_cream:
print (flavor, ice_cream[flavor])
>> 'banana' 1
'vanilla' 71
'chocolate' 183
'strawberry' 63
```
As with set elements, Python loops over the entries in the dictionary in an arbitrary order. There is no guarantee that they will be seen alphabetically or in the order, they were added to the dictionary. Notice, by the way, that looping over dictionaries is slightly different from looping over lists. When Python loops over a list, the values in the list are assigned to the loop variable. When it loops over a dictionary, on the other hand, it assigns the keys. Pythons designers chose to do this because:
- looping over the indices of a list isnt very interesting, since the
program would always get the sequence 0, 1, 2, ...; and
- its a lot easier to go from a dictionary key to the associated value
than it is to take the value and find the associated key.
**Dictionary Methods**
Dictionaries are objects, just like lists, tuples and sets. A few common dictionary methods are:
- *d.clear()* - clear a dictionary
- *d.get(x, 99)* - Returns the value associated with a key, or a default value if the key is not present.
- *d.keys()* - return keys
- *d.items()* - return list of key, value pairs
- *d.values()* - return values as a list, values may not be unique
- *d.update()* - update the dictionary with the contents of another
One common use of items is to loop over the keys and values in a dictionary together:
for (key, value) in dictionary.items():
...do something with the key and value...
This is inefficient for large dictionaries since items() actually constructs a list of (key, value) pairs. A similar method called *iteritems()* hands these pairs back one by one on demand:
for (key, value) in dictionary.iteritems():
...do something with the key and value...
Let's go back to the original example - how do we count the number of items in the ice_cream list using a dictionary?
```python
# Count all the flavors.
ice_cream = ["strawberry",
"vanilla",
"vanilla",
"chocolate",
"chocolate",
"chocolate",
"banana",
"rum raisin",
"banana"]
count = {}
for flavor in ice_cream:
if flavor in count:
count[flavor] = count[flavor] + 1
else:
count[flavor] = 1
# Print.
for b in count:
print (b, count[b])
```
To do this, we create a dictionary that is initially empty. Each time we loop through the ice_cream list, we check
to see whether that flavor is already in the count dictionary. If it is, we add one to its count.
If it isnt, we add the name to the dictionary with the value 1.
We can shorten this program a bit using the method *dict.get()*. This returns either the value associated with a key or some default value that we provide. In this case, we get either the number of times weve already seen a flavor or zero, add one to whichever value the method returns, and store that back in the dictionary:
```python
# Count all the flavors.
count = {}
for flavor in ice_cream:
count[flavor] = count.get(flavor, 0) + 1
# Print.
keys = count.keys()
keys.sort()
for b in keys:
print (b, count[b])
# Print.
for key in sorted(count):
print (key, count[key])
```
Note that we're using two separate ways to print the key and the value: one uses Python's sorted method, and the other does not.
If we wanted to print the flavors in order of frequency, we need to **invert the dictionary**. This means we need to use the values as keys, and the keys as values. Since there is no guarantee that the values are unique, we need to take steps to avoid *collisions*.
The solution is to use some sort of collection, such as a list, to store the inverted dictionarys values. If we go this route, the inverse of the dictionary shown earlier would be {1:[a,b,c]}. Heres a program to do what we want:
```python
ice_cream = ["strawberry",
"vanilla",
"vanilla",
"chocolate",
"chocolate",
"chocolate",
"banana",
"rum raisin",
"banana"]
# Count all the flavors.
count = {}
for flavor in ice_cream:
count[flavor] = count.get(flavor, 0) + 1
# Invert the dictionary.
freq = {}
for (flavor, times) in count.items():
if times in freq:
freq[times].append(flavor)
else:
freq[times] = [flavor]
# Print.
for key in freq:
for flavor in sorted(freq[key]):
print (key,":", " ", flavor)
```
#### More Information:
<!-- Please add any articles you think might be helpful to read before writing the article -->

View File

@@ -0,0 +1,57 @@
---
title: Graphs
---
## Graphs
A graph is a data-structure you can use to solve routing problems, such as "Are these two components connected?" and "What is the shortest path from point a to b?"
A graph consists of nodes and edges.
A node (i.e. vertex) is an object in your graph.
A node can contain information such as the name of the node and which edges it is attached to.
An edge is a link that connects two nodes.
The edge can contain information such as the weight of the edge.
If two nodes are connected by an edge, they are neighbours (i.e. adjacent).
Depending on the problem you can use either two-way (undirected) or one-way (directed) edges.
If you have a undirected edge from a to b, there is also a way from b to a.
If you have a directed edge from a to b, there is not necessarily an edge from b to a.
You can use graphs to formulate situations such as:
* Geographical maps
* Each city in your country is a node
* If two cities are connected by a road there is a edge between them
* Roads can be one- or two-way (both directed and undirected edges)
* the weight can be the lenght of the road
* Flow of water
* Each floodgate is a node
* Each canal is an edge
* water will only flow in one direction so the edges are directed
* the weight can be the maximum water capacity of the flow
Example: a graph that has as nodes the capitals of the Nordic countries, and as (undirected) edges the driving distance to cities connected by direct road.
```
. +---------+
. |Reykjavik|
. +---------+
.
.
. 529 km +---------+ 1760 km +--------+
. +------------+|Stockholm|+---------+|Helsinki|
. | +---------+ +--------+
. + +
. +----+ 1991 km |
. |Oslo|+-------------------------------------+
. +----+
. +----------+
. |Copenhagen|
. +----------+
```
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
#### More Information:
<!-- Please add any articles you think might be helpful to read before writing the article -->
<a href='https://github.com/freecodecamp/guides/tree/master/src/pages/algorithms/graph-algorithms/breadth-first-search/index.md' target='_blank' rel='nofollow'>Breadth First Search (BFS)</a>
<a href='https://github.com/freecodecamp/guides/tree/master/src/pages/algorithms/graph-algorithms/depth-first-search/index.md' target='_blank' rel='nofollow'>Depth First Search (DFS)</a>

View File

@@ -0,0 +1,131 @@
---
title: Hash Tables
---
## Hash Tables
Hash table (or Hash Map) is a data structure that can map keys to values.A hash table uses a hash function to compute an index
into an array of buckets, from which the desired values can be found.Time complexity of a well defined Hash function can be O(1).
A hash table (hash map) is a data structure which implements an associative array abstract data type, a structure that can map keys to values. A hash table uses a hash function to compute an index into an array of buckets or slots, from which the desired value can be found.
![an example of a hash table](https://github.com/TomerPacific/fccGuideImages/blob/master/315px-Hash_table_3_1_1_0_1_0_0_SP.svg.png?raw=true)
Some Important properties of Hash Table -
1) Values are not stored in sorted order.
2) In a hash table, one must also handle potential collisions.
This is often done by chaining, which means to create a linked list of all the values whose keys map to a particular index.
Implementation of Hash Table
A hash table is traditionally implemented with an array of linked lists.
When we want to insert a key/Value pair, we map the key to an index in the array using the hash function.
The value is then inserted into the linked list at that position.
The idea of hashing is to distribute the entries (key/value pairs) across an array of buckets.
Given a key, the algorithm computes an index that suggests where the entry can be found:
```
index = f(key, array_size)
```
Often this is done in two steps:
```
hash = hashfunc(key)
index = hash % array_size
```
In this method, the hash is independent of the array size, and it is then reduced to an index (a number between 0 and array_size 1) using the modulo operator (%).
Let us consider string S. You are required to count the frequency of all the characters in this string.
```
string S = “ababcd”
```
The simplest way to do this is to iterate over all the possible characters and count their frequency one by one.
The time complexity of this approach is O(26*N) where N is the size of the string and there are 26 possible characters.
```
void countFre(string S)
{
for(char c = a;c <= z;++c)
{
int frequency = 0;
for(int i = 0;i < S.length();++i)
if(S[i] == c)
frequency++;
cout << c << << frequency << endl;
}
}
```
Output
```
a 2
b 2
c 1
d 1
e 0
f 0
z 0
```
Let us apply hashing to this problem. Take an array frequency of size 26 and hash the 26 characters with indices of the array by using the hash function.
Then, iterate over the string and increase the value in the frequency at the corresponding index for each character.
The complexity of this approach is O(N) where N is the size of the string.
```
int Frequency[26];
int hashFunc(char c)
{
return (c - a);
}
void countFre(string S)
{
for(int i = 0;i < S.length();++i)
{
int index = hashFunc(S[i]);
Frequency[index]++;
}
for(int i = 0;i < 26;++i)
cout << (char)(i+a) << << Frequency[i] << endl;
}
```
Output
```
a 2
b 2
c 1
d 1
e 0
f 0
z 0
```
### Hash Collisions
When you are using a hash map you have to assume that hash collisions are unavoidable, since you will be using a hash map which is significantly smaller in size than the amount of data you have. The two main approaches to solving these collisions are Chaining and Open Addressing.
#### Chaining
One way you can resolve hash collisions is using chaining. What this means is for each key-value mapping in the hash table, the value field will not hold only one cell of data, but rather a linked list of data. In the example shown in the image below, you can see that Sandra Dee is added as another element to key 152 after John Smith.
![an example of chaining in a hash table](https://github.com/TomerPacific/fccGuideImages/blob/master/620px-Hash_table_5_0_1_1_1_1_0_LL.svg.png?raw=true)
The major setback regarding chaining is the increase in time complexity. This means, that instead of the O(1) properties of a regular hash table, each action will now take greater time as we need to traverse the linked list.
#### Open Addressing
Another way you can resolve hash collisions is using open addressing. In this method once a value is mapped to a key that is already occupied, you move along the adjacent keys of the hash table in a preordained determined fashion, until you find a key with an empty value. In the example shown in the image below, Sandra Dee is mapped to key 153, even though her value is supposed to be mapped to 152.
![an example of open addressing in a hash table](https://github.com/TomerPacific/fccGuideImages/blob/master/380px-Hash_table_5_0_1_1_1_1_0_SP.svg.png?raw=true)
The major setback of open addressing lies in the fact that when needing to look for values, they might not be in the place you expect them to be (the key mapping). Therefore you have to traverse parts of the hash table in order to find the value you are looking for, thus resulting in increased time complexity.
#### Time Complexity
It is very important to note that hash tables have amortised constant complexity i.e. on an average case the complexity will be O(1).
In worst case, If too many elements were hashed into the same key, it can have a time complexity of O(n).
### More Information:
<!-- Please add any articles you think might be helpful to read before writing the article -->
[More Info on Hash Tables - Wiki](https://en.wikipedia.org/wiki/Hash_table)<br>
[Comparison Between Hash Table and STL-map](http://www.geeksforgeeks.org/hash-table-vs-stl-map/)
#### Source
[Basics of Hash Tables - HackerEarth](https://www.hackerearth.com/practice/data-structures/hash-tables/basics-of-hash-tables/tutorial/)

View File

@@ -0,0 +1,21 @@
---
title: Data Structures
---
## Data Structures
Data Structure is a way of collecting and organising data in such a way that we can perform operations on these data in an effective way. Data Structures is about rendering data elements in terms of some relationship, for better organization and storage. For example, we have data player's name "Virat" and age 26. Here "Virat" is of String data type and 26 is of integer data type.
We can organize this data as a record like Player record. Now we can collect and store player's records in a file or database as a data structure. For example: "Dhoni" 30, "Gambhir" 31, "Sehwag" 33
In simple language, Data Structures are structures programmed to store ordered data, so that various operations can be performed on it easily. It represents the knowledge of data to be organized in memory. It should be designed and implemented in such a way that it reduces the complexity and increases the effieciency.
<!-- Data Structures in memory-->
In Computer memory i.e RAM, different data structures are created like stack, queue, linklist, heaps, etc according to the requirement of the program so to use the memory efficiently.
#### More Information:
<!-- Please add any articles you think might be helpful to read before writing the article -->
* [Data Structures](http://www.studytonight.com/data-structures/introduction-to-data-structures)
* [Geek for Geek](http://www.geeksforgeeks.org/data-structures/)
* [Tutorials Point](https://www.tutorialspoint.com/data_structures_algorithms/data_structure_overview.htm)
* [Data Structures](http://www.studytonight.com/data-structures/introduction-to-data-structures)

View File

@@ -0,0 +1,424 @@
---
title: Linked Lists
---
## Linked Lists
#### A Linked List is a simple *linear-access* data structure.
A linked list is a simple data structure, but it can be used to implement more complicated Data Structures like Queues, Stacks, etc. There are three types of Linked Lists:
1. Simple Linked List
2. Doubly Linked List (or Double Ended Linked List)
3. Circular Linked Lists (Ring Buffer)
Linked List | (Introduction)
Like arrays, Linked List is a linear data structure. Unlike arrays, linked list elements are not stored at contiguous location; the elements are linked using pointers or like in the example using Javascript, a reference to the next node.
If you want to understand Linked Lists, it helps to understand **Arrays**.
To recap, an array is traditionally a **static** **linear** data structure that supports constant time random access. Insertions and Deletions are not always constant time.
Advantages over arrays
1) Dynamic size
2) Ease of insertion/deletion
```
static = size fixed at creation time
linear = stored linearly in memory as a single block
```
#### Arrays have the following disadvantages:-
1. Arrays are static structures and therefore cannot be easily extended or reduced to fit the data set.
2. Arrays are also expensive to maintain new insertions and deletions.
Linked Lists address some of the limitations of arrays. Unlike an array, where all the elements are stored in a contiguous block of memory, in a linked list each element is a separate object and has a **link** to the next element in sequence. This allows a linked list to start with space for only one element, and grow to accomodate an arbitrary number of elements by allocating memory as and when needed.
Deleting elements is also simply handled by manipulating links.
Once you understand the Simple Linked List (which from here on will be referred as **'List'**), you can move on to the Doubly Linked List.
A List as illustrated below is made up of the following components:-
```
head
|
|
+---+---+ +---+---+ +----+------+
| 1 | o----->| 2 | o-----> | 3 | φ |
+---+---+ +---+---+ +----+------+
|
|
tail
```
| Node | Significance |
| ----------|-------------|
| HEAD | Beginning of the List|
| Node(s) | Dynamically allocated self-referential block contain 1 Data element and a link to the next node |
| TAIL | End of the List |
Most common operations available on List are,
1. AddFirst - Inserts an element at the front of the List.
2. AddLast - Inserts an element at the tail of the List.
3. InsertAfter - Inserts an element after an existing element in the List.
4. InsertBefore - Inserts an element before an existing element in the List.
5. Remove - Remove an existing element from the List.
6. Access / Peek - Access an existing element from the List.
7. Size / Count - Returns the number of elements currently present in the List.
8. IsEmpty - Check whether the List is empty or not.
#### Implementation of a Simple Linked List in C++
```cpp
#include<iostream>
using namespace std;
struct Number
{
int num;
struct Number *tail;
};
typedef struct Number N;
class List
{
private:
N *head,*end;
int count;
public:
void display();
void insertBefore(int);
List();
};
List :: List()
{
head=NULL;
end=NULL;
count=0;
}
void List :: insertBefore(int data)
{
N *node;
node= new N;
node->num=data;
node->tail=NULL;
if(!head){
head=end=node;
}
else{
node->tail=head;
head=node;
}
count++;
}
void List :: display()
{
cout<<"Number of nodes in the list = "<<count<<endl;
N *node;
node=head;
while(node)
{
cout<<node->num<<endl;
node=node->tail;
}
}
int main()
{
List l1;
l1.insertBefore(10);
l1.insertBefore(20);
l1.insertBefore(30);
l1.insertBefore(40);
l1.insertBefore(50);
l1.display();
return 0;
}
```
#### OUTPUT
```
Number of nodes in the list = 5
50
40
30
20
10
```
#### Explanation
```cpp
struct Number
{
int num;
struct Number *tail;
};
```
Declaration of a structure(node) with 2 data members
* `num` holds the integer data value
* `*tail` pointer points to the next node in the List
```cpp
class List
{
private:
N *head,*end;
int count;
public:
void display();
void insertBefore(int);
List();
};
```
The List class declares the Linked List.
* `*head` points to the first node in the List
* `*end` points to the last node in the List
* `count` holds the value for number of nodes in the list
* `display()` is used to print the complete list on the console
* `insertBefore()` is used to insert a new node
* `List()` is a defualt constructor
```cpp
List :: List()
{
head=NULL;
end=NULL;
count=0;
}
```
The default constructor is used to initialize the data members of the List class with default values
```cpp
void List :: insertBefore(int data)
{
N *node;
node= new N;
node->num=data;
node->tail=NULL;
if(!head){
head=end=node;
}
else{
node->tail=head;
head=node;
}
count++;
}
```
* A new node is created.
* `num` is assigned the value of `data`.
* `tail` is pointing to Null.
* The `if(!head)` condition is true only when there are no elements in the List.
* When this is the case, `head` and `end` are both pointing to the newly created node.
* Control will move to the `else` section, when there is at least one node in the list.
* In this case, `tail` pointer in the newly created node is made to point to the `head`(first) node.
* The `head` pointer then points to the newly created node to make it the first node in the list.
* `count` is incremented by 1 as each new node is added.
```cpp
void List :: display()
{
N *node;
node=head;
while(node)
{
cout<<node->num<<endl;
node=node->tail;
}
}
```
The display function is used to run through the list and print the total number of nodes and values of `num` on the console.
#### Applications
* Base Data Structure for Vector, Array, Queue, Stack, etc
* Polynomial Representation
* Ring Buffer
Drawbacks:
1) Random access is not allowed. We have to access elements sequentially starting from the first node. So we cannot do binary search with linked lists.
2) Extra memory space for a pointer is required with each element of the list
Types:
1) (Singly) linked lists contain nodes which have a data field as well as a 'next' field, which points to the next node in line of nodes. Operations that can be performed on singly linked lists include insertion, deletion and traversal.
2) (Doubly) In a 'doubly linked list', each node contains, besides the next-node link, a second link field pointing to the 'previous' node in the sequence. The two links may be called 'forward('s') and 'backwards', or 'next' and 'prev'('previous').
Example in Javascript:
```
function LinkedList () {
this.head = null;
this.tail = null;
}
// Node has three properties value, next, prev
function Node (value, next, prev) {
this.value = value;
// A 'pointer' referencing to the next Node (if present) otherwise null
this.next = next;
// A 'pointer' referencing the previous Node, otherwise null
this.prev = prev;
}
LinkedList.prototype.addToHead = function(value) {
let newNode = new Node(value, this.head, null);
if (this.head) this.head.prev = newNode;
else this.tail = newNode;
this.head = newNode;
}
```
Now Execute code
```
let LL = new LinkedList();
LL.addToHead(100);
LL.addToHead(200);
console.log(LL);
```
Representation in C:
A linked list is represented by a pointer to the first node of the linked list. The first node is called head. If the linked list is empty, then value of head is NULL.
Each node in a list consists of at least two parts:
1) data
2) pointer to the next node
In C, we can represent a node using structures. Below is an example of a linked list node with an integer data.
In Java, LinkedList can be represented as a class and a Node as a separate class. The LinkedList class contains a reference of Node class type
```C
// A linked list node
struct Node
{
int data;
struct Node *next;
};
```
# Linked List with three elements
```c
// A simple C program to introduce
// a linked list
#include<stdio.h>
#include<stdlib.h>
struct Node
{
int data;
struct Node *next;
};
// Program to create a simple linked
// list with 3 nodes
int main()
{
struct Node* head = NULL;
struct Node* second = NULL;
struct Node* third = NULL;
// allocate 3 nodes in the heap
head = (struct Node*)malloc(sizeof(struct Node));
second = (struct Node*)malloc(sizeof(struct Node));
third = (struct Node*)malloc(sizeof(struct Node));
/* Three blocks have been allocated dynamically.
We have pointers to these three blocks as first, second and third
head second third
| | |
| | |
+---+-----+ +----+----+ +----+----+
| # | # | | # | # | | # | # |
+---+-----+ +----+----+ +----+----+
# represents any random value.
Data is random because we havent assigned anything yet */
head->data = 1; //assign data in first node
head->next = second; // Link first node with the second node
/* data has been assigned to data part of first block (block
pointed by head). And next pointer of first block points to
second. So they both are linked.
head second third
| | |
| | |
+---+---+ +----+----+ +-----+----+
| 1 | o----->| # | # | | # | # |
+---+---+ +----+----+ +-----+----+
*/
second->data = 2; //assign data to second node
second->next = third; // Link second node with the third node
/* data has been assigned to data part of second block (block pointed by
second). And next pointer of the second block points to third block.
So all three blocks are linked.
head second third
| | |
| | |
+---+---+ +---+---+ +----+----+
| 1 | o----->| 2 | o-----> | # | # |
+---+---+ +---+---+ +----+----+ */
third->data = 3; //assign data to third node
third->next = NULL;
/* data has been assigned to data part of third block (block pointed
by third). And next pointer of the third block is made NULL to indicate
that the linked list is terminated here.
We have the linked list ready.
head
|
|
+---+---+ +---+---+ +----+------+
| 1 | o----->| 2 | o-----> | 3 | NULL |
+---+---+ +---+---+ +----+------+
Note that only head is sufficient to represent the whole list. We can
traverse the complete list by following next pointers. */
return 0;
}
```
#### More Information:
* <a href='http://www.geeksforgeeks.org/linked-list-set-1-introduction/' target='_blank' rel='nofollow'>Introduction to Linked Lists</a>
* <a href='https://www.youtube.com/watch?v=njTh_OwMljA' target='_blank' rel='nofollow'>Linked Lists (YouTube video)</a>

View File

@@ -0,0 +1,81 @@
---
title: Queues
---
## Queues
Queue is a First In First Out (FIFO) Data Structure. Many algorithms use Queues at their core for improving performance.
Queue is one of the fundamental Abstract Data Types (ADT). It is similar to queues we have in movies or supermarkets. The first person to arrive will be served first right? Similarly, the first element to be inserted will be removed first. There are several types of queues such as,
1. Simple Queue (or Queue)
2. Circular Queue
3. Priority Queue
4. Dequeue (Double Ended Queue)
If you can understand the simple queue (which from here on will be referred as 'Queue') then all the others are just as easy, with little modifications.
Most common operations available on queue are,
1. Add / Offer - Inserts an element into the end of the queue.
2. Remove / Poll - Remove an element from the beginning of the queue.
3. Peek - Returns element at the beginning of the queue but will not remove it.
4. Size / Count - Returns the number of elements currently present in the queue.
5. IsEmpty - Check whether the queue is empty or not.
Implementation of a queue is possible using either arrays or linked lists. The following is a simple array implementation of the queue data structure with its most common operations.
```JavaScript
var Queue = function() {
var queue = [];
var front = 0;
var back = 0;
return {
isEmpty: function() {
return front >= back || queue.length === 0;
},
add: function(elem) {
/* You can also do queue.push(elem) in JavaScript.
This is how they do it in other languages */
queue[back++] = elem;
},
remove: function() {
if (!this.isEmpty()) {
return queue[front++]; // or queue.shift()
}
else {
throw new Error("Queue is Empty.");
}
},
peek: function() {
if (!this.isEmpty()) {
return queue[front];
}
}
}
};
var queue = new Queue();
console.log(queue.isEmpty()); // true
queue.add(1);
queue.add(2);
console.log(queue.remove()); // 1
console.log(queue.peek()); // 2
console.log(queue.remove()); // 2
console.log(queue.remove()); // exception
```
#### Applications
* Simulation
* Scheduling (Job Scheduling, Disk Scheduling)
* Shared Resource Management
* Keyboard Buffer
* Breadth First Search
* To handle congestion in network
#### More Information:
* <a href='http://www.geeksforgeeks.org/queue-data-structure/' target='_blank' rel='nofollow'>More Info on Queues - GeeksForGeeks</a>
* <a href='https://www.hackerrank.com/domains/data-structures/queues' target='_blank' rel='nofollow'>Solve Challenges using Queues - Hackerrank</a>
* <a href="https://www.youtube.com/watch?v=wjI1WNcIntg" target ="_blank" rel="nofollow">HackerRank Stacks and Queues Video</a>

View File

@@ -0,0 +1,114 @@
---
title: Stacks
---
## Stacks
A stack is a First In Last Out (FILO) or Last In First Out (LIFO) Data Structure. It is a linear data structure.
You can imagine a stack as the way plates were organized in buffet restaurant. You can only pick the plate at the top otherwise the stack will collapse. Generally, the last item to be inserted will be removed first.
Some basics operations of stack are:
1. Push - Inserts an item at the top of the stack.
2. Pop - Removes an item at the top of the stack.
3. isEmpty - Check whether the stack is empty or not
4. Size - Return the number of items in the stack
(All the operations can be done in O(1) time)
Implementation of a stack is possible using either arrays or linked lists. The following is a simple array implementation of the stack data structure with its most common operations.
```C++
//Stack implementation using array in C++
//You can also include<stack> and then use the C++ STL Library stack class.
#include <bits/stdc++.h>
using namespace std;
class Stack {
int t;
int arr[MaxN];
public:
Stack() {
t = 0;
}
int size() {
return t;
}
bool isEmpty() {
return t < 1;
}
int top() {
return arr[t];
}
void push(int x) {
if (++t >= MaxN) {
cout << "Stack is full" << '\n';
return;
}
arr[t] = x;
}
void pop() {
arr[t--] = 0;
}
};
int main() {
Stack st;
st.push(4);
st.push(3);
st.push(5);
while (!st.isEmpty()) {
cout << st.size() << ' ' << st.top() << '\n';
st.pop();
}
return 0;
}
```
#### Using Arrays as Stacks
In some programming languages an array has stack functionality, allowing the developer to perform **push** and **pop** operations without the need for a custom stack data structure.
For example, an array in JavaScript has **push** and **pop** methods allowing one to easily implement stack functionality in an application.
```js
stack = [];
let i = 0;
while(i < 5)
stack.push(i++);
while(stack.length) {
stack.pop();
}
```
A List in Python can also perform stack functionality in an application. Instead of **push**, one can use the **append** method.
```python
stack = []
for i in range(5):
stack.append(i)
while len(stack):
stack.pop()
```
#### Applications
* Turn recursion into loop.
* Redo-Undo features.
* Sudoku solver
* Depth First Search.
* Tree traversals
* Infix expression -> Prefix/Postfix expression
* Valid Parentheses
#### More Information:
* [More Info on Stacks - GeeksForGeeks](http://www.geeksforgeeks.org/stack-data-structure/)
* [Stack - Wikipedia](https://en.wikipedia.org/wiki/Stack_(abstract_data_type)
* [Tower of Hanoi Problem and how the solution uses stacks and recursions](https://en.wikipedia.org/wiki/Tower_of_Hanoi)
* [HackerRank Stacks and Queues Video](https://www.youtube.com/watch?v=wjI1WNcIntg)

View File

@@ -0,0 +1,97 @@
---
title: Trees
---
# Trees
A tree data structure can be defined recursively (locally) as a collection of nodes (starting at a root node), where each node is a data structure consisting of a value, together with a list of references to nodes (the "children"), with the constraints that no reference is duplicated, and none points to the root. A tree with no nodes is called a null or empty tree.
A binary tree is a non linear data structure consisting nodes, where each node has the following 3 components:
**Data element**: Stores any kind of data in the node
**Left pointer**: Points to the sub-tree on the left side of node
**Right pointer**: Points to the sub-tree on the right side of the node
As the name suggests, the data element stores any kind of data in the node.
The left and right pointers point to binary trees on the left and right side of the node respectively.
If a tree is empty, it is represented by a null pointer.
## Terminology used in trees:
**Root** :
The top node in a tree.
**Child**:
A node directly connected to another node when moving away from the Root.
**Parent**:
The converse notion of a child.
**Siblings**:
A group of nodes with the same parent.
**Descendant**:
A node reachable by repeated proceeding from parent to child.
**Ancestor**:
A node reachable by repeated proceeding from child to parent.
**Branch**(internal node):
A node of a tree that has child nodes.
**Leaf**(less commonly called External node):
A node with no children.
**Degree**:
The number of subtrees of a node.
**Edge**:
The connection between one node and another.
**Path**:
A sequence of nodes and edges connecting a node with a descendant.
**Level**:
The level of a node is defined by 1 + (the number of connections between the node and the root).
**Height of tree**:
The height of a tree is the height of its root node.
**Depth**:
The depth of a node is the number of edges from the tree's root node to the node.
**Forest**:
A forest is a set of n ≥ 0 disjoint trees.
### Some Popular Types of Trees:
* Binary Tree
* Binary Search Tree
* AVL Tree
* Red Black Tree
* Splay Tree
* Huffmann Tree
### Common uses
* Representing hierarchical data
* Storing data in a way that makes it easily searchable
* Representing sorted lists of data
* Routing algorithms
### Code of a tree node
``` c++
struct node
{
int data; //Data element
struct node * left; //Pointer to left node
struct node * right; //Pointer to right node
};
```
#### More Information:
* [CMU lesson notes](http://www.cs.cmu.edu/~clo/www/CMU/DataStructures/Lessons/lesson4_1.htm)
* [Wikipedia](https://en.wikipedia.org/wiki/Tree_(data_structure))

View File

@@ -0,0 +1,23 @@
---
title: ACID
---
## ACID
In computer science, ACID (Atomicity, Consistency, Isolation, Durability) is a set of properties for database modifications. They help guarantee the validity of a transaction, even with errors or failures.
A **transaction** is any sequence of database operations that satisfies the ACID properties and could be viewed as a single logical operation on the data. An example is a transfer of funds from one bank account to another. This involves multiple changes, such as debiting one account and crediting another, but is considered to be a single transaction.
### Atomicity
This means that a complex transaction is either processed completely, or not at all. If one part of the transaction fails, then the entire transaction does not complete and the database is unchanged. This way, if there's a crash, power failure, or error, the database doesn't end up in a state where only parts of a transaction are done.
### Consistency
This means that data will be consistent. Any data entered into the database must be valid and permitted based on any constraints you specify. It makes sure that any transaction changes the database from one valid state to another valid state.
### Isolation
This means that if two transactions execute at the same time, one transaction can't read data from a transaction that hasn't yet completed. Each transaction will see the database as if the transactions were executing sequentially. If one transaction needs to read data that the other is writing, it has to wait until the other transaction is finished. The effects of an incomplete transaction will not affect another transaction.
### Durability
This means that once a transaction is complete, it will remain so, even in the event of a power loss or other errors. It guarantees that all of the changes are recorded to a non-volatile storage medium (such as a hard disk), and it makes a record of the completed transaction.
### More Information:
- ACID article: <a href='https://en.wikipedia.org/wiki/ACID' target='_blank' rel='nofollow'>Wikipedia</a>
- Video overview: <a href='https://www.youtube.com/watch?v=LSB4eceRsw8' target='_blank' rel='nofollow'>YouTube</a>

View File

@@ -0,0 +1,10 @@
---
title: Column Databases
---
## Column Databases
Column oriented databases are designed to efficiently return data for a limited number of columns. It does it by storing all of the values of a column together. A column oriented database will excel at read operations on a limited number of columns, however write operation will be expensive compared to row oriented databases.
#### More Information:
<!-- Please add any articles you think might be helpful to read before writing the article -->
Please visit the <a href="https://en.wikipedia.org/wiki/Column-oriented_DBMS">Column-oriented DBMS</a> Wikipedia page for more information.

View File

@@ -0,0 +1,23 @@
---
title: Document Store Databases
---
## Document Store Databases
A document store database is considered to be yet another type of NoSQL database that is very similar to a Key Value database. A record in a document store represents a single structured document that can be different from all other documents in the database. Unlike a relational database, there is no mapping of objects to various table in the database. Instead we can take the entire object and write it directly into a document store database.
For example, we could have the following object inside of our code.
```json
{
"name": "freeCodeCamp",
"job": "contributor"
}
```
This entire object can be written directly into a document store database without further parsing.
#### More Information:
[MongoDB](https://www.mongodb.com/document-databases)
[Elasticsearch](https://www.elastic.co/)

View File

@@ -0,0 +1,19 @@
---
title: Fault Tolerance
---
## Fault Tolerance
Fault tolerance is the property that enables a system to continue its intended operation, possibly at a reduced level, rather than failing completely, when some portion of the system fails.
A **database** is fault-tolerant when it can access a secondary shard when the primary is unavailable.
This is achieved through:
* Database Replication
* Fault Detection & Failover
A database that maintains multiple copies of all data in different physical nodes located across independent physical sub-systems, such as server racks and network routers, has a higher probability to continue operating when the primary copy of the data is unavailable due to its ability to read data from multiple replications.
In large-scale distribution systems, it becomes increasingly important to have reliable failure detection systems that can identify failing storage drives and provide failover units in order to maximise service uptime.

View File

@@ -0,0 +1,11 @@
---
title: Graph Databases
---
## Graph Databases
A graph database is a database that uses graph structures for semantic queries with nodes, edges and properties to represent and store data. A key concept of the system is the graph (or edge or relationship), which directly relates data items in the store. The relationships allow data in the store to be linked together directly, and in many cases retrieved with one operation.
#### More Information:
<!-- Please add any articles you think might be helpful to read before writing the article -->
* <a href='https://en.wikipedia.org/wiki/Graph_database' target='_blank' rel='nofollow'>Graph Databases</a>

View File

@@ -0,0 +1,15 @@
---
title: Databases
---
## Databases
This is a stub. <a href='https://github.com/freecodecamp/guides/tree/master/src/pages/computer-science/databases/index.md' target='_blank' rel='nofollow'>Help our community expand it</a>.
<a href='https://github.com/freecodecamp/guides/blob/master/README.md' target='_blank' rel='nofollow'>This quick style guide will help ensure your pull request gets accepted</a>.
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
#### More Information:
<!-- Please add any articles you think might be helpful to read before writing the article -->

View File

@@ -0,0 +1,17 @@
---
title: Indexes
---
## Indexes
A **database index** is a data structure that improves the efficiency of data retrievals on a database table. A database table can have more than one index and an index could be created on one or more columns of a database table.
### How do indexes work?
Now imagine you are in a library where the books are not arranged in a predetermined order. If you were tasked to find a book, you would have to go shelf by shelf to locate it. This may be fine when there are only a few shelves of books, but the process is very time consuming if it is a multi-storey library.
On the other hand, assume that the books are now arranged by the last name of author. Given that you know the last name of the author for the book you are searching for, for example "Carnegie", you may look for shelve for "C" and then search within the specific shelf. You have saved yourself from going through every single shelf.
### The tradeoff
As described earlier, an **index** is a data structure, hence it takes up storage space. The more indexes are defined, the more storage space is taken up to maintain the data structure. Another cost comes in the form of additional updates (or writes) to keep the indexes up to date. When new records are added to a table that has an index, additional writes are required to update the index data structure.
#### More Information:
[Database Index](https://en.wikipedia.org/wiki/Database_index)

View File

@@ -0,0 +1,54 @@
---
title: Key Value Databases
---
## Key Value Databases
A key-value database, or key-value store, is a type of [NoSQL](https://en.wikipedia.org/wiki/NoSQL) database that uses a key/value storage. This means that the data stored in the database is a collection of key-value pairs.
This type of data structure is used on many programming languages. Key-value pairs are commonly known as associative arrays, dictionaries or hash. For example, consider a dictionary of phone numbers:
| key | value |
|------------|-------------|
| Rick | 1234555 |
| Morty | 7754321 |
| Summer | 5512377 |
### The Key
The `key` in a key-value pair must be unique. Having a unique identifier will allow you to access the value associated with a given key.
In theory, the key can be anything you want. A key can be a string, a binary sequence, an image, among others. However, some databases may impose limitations on the type of keys that can be used.
Here are some recommendations:
- Keys should follow a convention in order to have consistency. Keys in a phone numbers dictionary should always be names, and not a combination of names, e-mail addresses and numbers.
- Keys should not be too long, or you might have performance issues.
- Keys should not be too short, or you might have readability issues.
### The Value
The `value` in a key-value store can be anything you want. This includes strings, numbers, code, an image, a list, or even another key-value pair. Some databases allow you to restrict the data type that can be stored.
### Use Cases
Key-value databases can be used on multiple scenarios. Here is a list of the most common applications:
- Telecom directories.
- User profiles and session information.
- Shopping cart contents.
- Product details or reviews.
- Internet Protocol (IP) forwarding tables.
- Services health status or configuration.
### Examples
Here are some examples of databases that use the key-value approach:
- [Redis](https://redis.io)
- [Oracle NoSQL Database](https://www.oracle.com/database/nosql/index.html)
- [Cassandra](http://cassandra.apache.org) (hybrid between key-value and column-oriented databases)
- [Voldemort](http://www.project-voldemort.com/voldemort/)
- [Consul KV store](https://www.consul.io/intro/getting-started/kv.html) (a tool with it's own key-value store)
#### More Information:
* Key-value databases on [Wikipedia](https://en.wikipedia.org/wiki/Key-value_database)
Key-Value database is a simple database that uses a map or a dictionary as the fundamental data model where each key is associated with one and only one value in a collection and is the most flexible type of NoSQL database.

View File

@@ -0,0 +1,30 @@
---
title: Non-Relational-Databases
---
## When to Use
If youre dealing with a phenomenally huge amount of data, it can be way too tedious, and the probability of error (in the form of an ORM Impedance Mismatch issue) increases. In that situation you may need to consider going with a non-relational database. A non-relational database just stores data without explicit and structured mechanisms to link data from different tables (or buckets) to one another. If your data model turns out to be very complex, or if you find yourself having to de-normalize your database schema, non-relational databases may be the best way to go.
Other reasons for choosing a non-relational database include:
- The need to store serialized arrays in JSON objects
- Storing records in the same collection that have different fields or attributes
- Finding yourself de-normalizing your database schema or coding around performance and horizontal scalability issues
- Problems easily pre-defining your schema because of the nature of your data model
## Disadvantages
In non-relational databases, there are no joins like there would be in relational databases. This means you need to perform multiple queries and join the data manually within your code -- and that can get very ugly, very fast.
## Example Databases
- MongoDB
- NoSQL
## References
- (https://www.pluralsight.com/blog/software-development/relational-non-relational-databases)
- (https://en.wikipedia.org/wiki/NoSQL)

View File

@@ -0,0 +1,115 @@
---
title: Normal Form
---
## Normal Form
Normalization was first introduced as part of the relational model. It is the process of organizing data tables and columns in a way that reduces redundancies and improves integrity. This can either be done through :
* synthesis : creates a normalized database design based on a known set of dependencies.
* decomposition : takes an existing (insufficiently normalized) database design and improves it based on the known set of dependencies
There are three common normal forms (1st, 2nd and 3rd) plus a rather advanced form called BCNF. They are progressive : in orther to qualify for the 3rd normal form, a database schema must satisfy the rules of the 2nd normal form, and so on for the 1st normal form.
* **1st normal form** : The information is stored in a table, each column contains atomic values, and there are not repeating groups of columns. This :
1. Eliminates repeating groups in individual tables.
2. Creates a separate table for each set of related data.
3. Identifies each set of related data with a primary key
##### Example
A design that violates the 1st normal form, the "telephone" column does not contain atomic values
| customer ID | First name | Last name | Telephone |
|-------------|------------|-----------|--------------------------------------|
| 123 | Pooja | Singh | 555-861-2025, 192-122-1111 |
| 789 | John | Doe | 555-808-9633 |
| 456 | San | Zhang | (555) 403-1659 Ext. 53; 182-929-2929 |
One solution would be to have an extra column for each phone number. But then, this will repeat conceptually the same attribute(phone number). Moreover, adding extra telephone number will require reorganizing the table by adding more column.This is definitely not practicle.
Another solution is to have a separate table for the association customer <-> Telephone: This respects the 1st normal form and there can be as many rows per customer as needed.
| customer ID | First name | Last name |
|-------------|------------|-----------|
| 123 | Pooja | Singh |
| 789 | John | Doe |
| 456 | San | Zhang |
| customer ID | Telephone |
|-------------|------------------------|
| 123 | 555-861-2025 |
| 123 | 192-122-1111 |
| 789 | 555-808-9633 |
| 456 | (555) 403-1659 Ext. 53 |
| 456 | 182-929-2929 |
* **2nd normal form** : The table is in the first normal form and all the non-key columns depend on the table's primary key. This narrows the table's purpose.
##### Example
A design that violates the 2nd normal form. The model full name being the primary key, there are other candidate keys like {manufacturer, model}. The "Manufacturer Country" column is dependant on a non-key column (the Manufacturer).
| Manufacturer | Model | Model Full Name | Manufacturer Country |
|---------------------|--------------|----------------------|----------------------|
| Forte | X-Prime | Forte X-Prime | Italy |
| Forte | Ultraclean | Forte Ultraclean | Italy |
| Dent-o-Fresh | EZbrush | Dent-o-Fresh EZbrush | USA |
| Kobayashi | ST-60 | Kobayashi ST-60 | Japan |
| Hoch | Toothmaster | Hoch Toothmaster | Germany |
| Hoch | X-Prime | Hoch X-Prime | Germany |
The normalized design would be to split into two tables like the following:
| Manufacturer | Manufacturer Country |
|---------------------|----------------------|
| Forte | Italy |
| Dent-o-Fresh | USA |
| Kobayashi | Japan |
| Hoch | Germany |
| Manufacturer | Model | Model Full Name |
|---------------------|--------------|----------------------|
| Forte | X-Prime | Forte X-Prime |
| Forte | Ultraclean | Forte Ultraclean |
| Dent-o-Fresh | EZbrush | Dent-o-Fresh EZbrush |
| Kobayashi | ST-60 | Kobayashi ST-60 |
| Hoch | Toothmaster | Hoch Toothmaster |
| Hoch | X-Prime | Hoch X-Prime |
* **3rd normal form** : The table is in second normal form and all of its columns are not transitively dependent on the primary key.
A column is said to be dependant on an another column if it can be derived from it, for example, the age can be derived from the birthday. Transitivity means this dependance might involve other columns. for example, if we consider three columns `PersonID BodyMassIndex IsOverweight` , the column 'IsOverweight' is transitively dependant on 'personID' through 'BodyMassIndex'.
##### Example
A design that violates the 3rd normal form. {Tournament, Year} is the primary key for the table and the column 'Winner Date of Birth' transitively depends on it.
| Tournament | Year | Winner | Winner Date of Birth |
|----------------------|-------------|----------------|----------------------|
| Indiana Invitational | 1998 | Al Fredrickson | 21 July 1975 |
| Cleveland Open | 1999 | Bob Albertson | 28 September 1968 |
| Des Moines Masters | 1999 | Al Fredrickson | 21 July 1975 |
| Indiana Invitational | 1999 | Chip Masterson | 14 March 1977 |
A design compliant with the 3rd normal form would be :
| Tournament | Year | Winner |
|----------------------|-------------|----------------|
| Indiana Invitational | 1998 | Al Fredrickson |
| Cleveland Open | 1999 | Bob Albertson |
| Des Moines Masters | 1999 | Al Fredrickson |
| Indiana Invitational | 1999 | Chip Masterson |
| Winner | Date of Birth |
|----------------|-------------------|
| Chip Masterson | 14 March 1977 |
| Al Fredrickson | 21 July 1975 |
| Bob Albertson | 28 September 1968 |
#### More Information:
* database normalisation on <a href='https://en.wikipedia.org/wiki/Database_normalization' target='_blank' rel='nofollow'>wikipedia</a>
* first normal form on <a href='https://en.wikipedia.org/wiki/First_normal_form' target='_blank' rel='nofollow'>wikipedia</a>
* second normal form on <a href='https://en.wikipedia.org/wiki/Second_normal_form' target='_blank' rel='nofollow'>wikipedia</a>
* third normal form on <a href='https://en.wikipedia.org/wiki/Third_normal_form' target='_blank' rel='nofollow'>wikipedia</a>

View File

@@ -0,0 +1,73 @@
---
title: Relational Databases
---
As a database is a way to store data, relational-databases are a model for how the data is being stored. The data is organized into tables, also known as relations. The tables contain a record for each instance of the data, known as records or tuples. Unique identifiers identify each record to describe it across the database.
## Tables
Like the a sheet in excel, tables are made up of columns and rows. Each row is an instance of data with attributes in the column of the table know as fields. There can be several tables for each category for entities. An example could be a table of users. Each row would be a user and each field would be details on the user like email, password, and contact details for that specific user. In Figure 1 you can see diagram of the example.
|             | user       | email     | Telephone                            |
|-------------|------------|------------------|--------------------------------------|
| row 1       | Jerry     | j@j.uk.za       | 771447444121           |
| row 2 | Sally | batgirl@gh.co.za | 771447444121 |
| row 3 | Alex | samwis@tty.fe | 771447444121 |
| row 4 | Doug | 4sure@dam.us | 745151515152 |
Figure 1 - Example of user table.
## Records
A record is a single entity of data. As in the example above, it could be a user, an account, a device, or anything that data can represent. Records do need a unique identifier, sometimes referred to as a key. This key must be unique as it is used to describe relationships a record has with other records in other tables. In Figure 1, we could add keys to each row that identifies each user with a key and the table would now look like Figure 2.
| KEY   | user       | email           | Telephone                          |
|-----------|------------|------------------|--------------------------------------|
| u1       | Jerry     | j@j.uk.za       | 771447444121           |
| u2 | Sally | batgirl@gh.co.za | 771447444121 |
| u3 | Alex | samwis@tty.fe | 771447444121 |
| u4 | Doug | 4sure@dam.us | 745151515152 |
Figure 2 - Example of user database with KEY field.
## Fields
Fields describe the record. This could hold any information on the entity that the record symbolizes. In Figure 3 you can see a table that shows pets. The columns (fields) describe each pet (record) with p\_name, p\_age, p\_type and p\_owner. The p is shorthand for pet and the last column will be explained in the next section on relationships.
| KEY       | p\_name    | p\_age     | p\_owner   |
|-----------|------------|------------------|---------------|
| p1       | Suzy     | j@j.uk.za       | u1 |
| p2 | Little Dip | batgirl@gh.co.za | u1 |
| p3       | Amillë     | samwis@tty.fe  | u2 |
| p4 | Doug | 4sure@dam.us | u3 |
Figure 3 - Example of Pet table.
## Relationships
Relational-databases allow you to describe the relationships entities have with each other. This is sometimes the most difficult topic of relational databases to understand. If we take our example tables we should be able to see the relationship our user table has with the pet table. If you read the p\_owner field you can see it could be also be as in Figure 4. This explains the relation each pet has with a user. Relationship could have different types.
| KEY       | p\_name   | p\_age     | p\_owner   |
|-----------|------------|------------------|---------------|
| p1       | Suzy     | j@j.uk.za       | Jerry |
| p2 | Little Dip | batgirl@gh.co.za | Jerry |
| p3       | Amillë     | samwis@tty.fe  | Sally |
| p4 | Doug | 4sure@dam.us | Doug |
Figure 4 - Example of Pet table with owner field linked.
A one-to-many relationship is one record linked to many other records, the example being the user Jerry having two pets. It could also be a many-to-many relationship where the tables could be books and authors, as authors could co-write many books. Finally the most common relationship type is one-to-one, a record that can only be linked to one, and only one, other record.
## Conclusion
This is just a brief intro into relational-databases. Below links are provided to resources that could help you further study the subject.
#### More Information:
* Relational databases on <a href='https://en.wikipedia.org/wiki/Relational_database' target='_blank' rel='nofollow'>wikipedia</a>
* One-to-many on <a href='https://en.wikipedia.org/wiki/One-to-many_(data_model' target='_blank' rel='nofollow'>wikipedia</a>)
* Many-to-many on <a href='https://en.wikipedia.org/wiki/Many-to-many_(data_model' target='_blank' rel='nofollow'>wikipedia</a>)
* One-to-one on <a href='https://en.wikipedia.org/wiki/One-to-one_(data_model' target='_blank' rel='nofollow'>wikipedia</a>)
* Relationship model on <a href='https://en.wikipedia.org/wiki/Entity%E2%80%93relationship_model' target='_blank' rel='nofollow'>wikipedia</a>

View File

@@ -0,0 +1,46 @@
# Deadlocks
### The Deadlock Problem
- A set of blocked processes each holding a resource and waiting to acquire a resource held by another process in the set.
- Example
- System has 2 disk drives.
- P 1 and P 2 each hold one disk drive and each needs another one.
#### Bridge Crossing Example
![bridge crossing example](http://www.eenadupratibha.net/pratibha/engineering/images/unit5/1.jpg)
- Traffic only in one direction.
- Each section of a bridge can be viewed as a resource.
- If a deadlock occurs, it can be resolved if one car backs up (preempt resources and rollback).
- Several cars may have to be backed up if a deadlock occurs.
- Starvation is possible.
### Deadlock Characterization
Deadlock can arise if four conditions hold simultaneously.
- **Mutual exclusion** : only one process at a time can use a resource.
- **Hold and wait** : a process holding at least one resource is waiting to acquire additional resources held by other processes.
- **No preemption** : a resource can be released only voluntarily by the process holding it, after that process has completed its task.
- **Circular wait** : there exists a set { P<sub>0</sub>, P<sub>1</sub>, …, P<sub>0</sub> } of waiting processes such that P<sub>0</sub> is waiting for a resource that is held by P<sub>1</sub>, P<sub>1</sub> is waiting for a resource that is held by P<sub>2</sub>, …, P<sub>n 1</sub> is waiting for a resource that is held by P<sub>n</sub>, and P<sub>0</sub> is waiting for a resource that is held by P<sub>0</sub>.
### Methods for Handling Deadlocks
- Ensure that the system will never enter a deadlock state.
- Allow the system to enter a deadlock state and then recover.
- Ignore the problem and pretend that deadlocks never occur in the system; **used by most operating systems, including UNIX**.
### Deadlock Prevention
- **Mutual Exclusion** It is not required for sharable resources; must hold for nonsharable resources.
- **Hold and Wait** It must guarantee that whenever a process requests a resource, it does not hold any other resources.
- Require process to request and be allocated all its resources before it begins execution, or allow process to request resources only when the process has none.
- Low resource utilization; starvation possible.
- **No Preemption**
- If a process that is holding some resources requests another resource that cannot be immediately allocated to it, then all resources currently being held are released.
- Preempted resources are added to the list of resources for which the process is waiting.
- Process will be restarted only when it can regain its old resources, as well as the new ones that it is requesting.
- **Circular Wait** It imposes a total ordering of all resource types, and require that each process requests resources in an increasing order of enumeration.
#### More information :
- [Deadlock](https://en.wikipedia.org/wiki/Deadlock)
- [Operating System | Process Management | Deadlock Introduction](https://www.geeksforgeeks.org/operating-system-process-management-deadlock-introduction/)

View File

@@ -0,0 +1,8 @@
---
title: Ditributed Algorithms
---
## Distributed Algorithms
Distributed algorithms is the study of algorithms that run on more than one processor. The purpose of such algorithms is to utilize parallelization to achieve speedup. Some applications of distributed algorithms would be in multicore processors and clusters of computers.
While studying distributed algorithms in theory, the distributed system is modeled in order to reach an abstract level independent from different implementations and systems. Two common models are message passing model and shared memory model. In message passing, each process (process and processors are usually used interchangeably) communicated via messages that it sends and receives to and from other processes. In the shared memory model, processes communicate by accessing a shared memory.

View File

@@ -0,0 +1,52 @@
---
title: Dynamic Programming
---
## Dynamic Programming
Dynamic Programming(DP) is a programming technique for solving problems where the computations of its subproblems overlap: you write your program in a way that avoids recomputing already solved problems.
This technique, it's usually applied in conjunction with memoization which is an optimization technique where you cache previously computed results, and return the cached result when the same computation is needed again.
An example with Fibonacci's series which is defined as:
```F(N) = F(N-1) + F(N-2)```
This is the tree to find F(5):
![Fibonacci serie's tree](https://i.stack.imgur.com/59Rpw.png)
To compute F(5) it will need to compute many times the same F(i). Using recursion:
```python
def fib(n)
{
if n <= 1:
return n
return fib(n-1) + fib(n-2);
}
```
And below is the optimised solution (using DP)
For F(5), this solution will generate the calls depicted in the image above, running in O(2^N).
Here is an optimised solution which uses DP and memoization:
```python
lookup = {1 : 1, 2 : 1} # Create a lookup-table (a map) inizialized with the first 2 Fibonacci's numbers
def fib(n)
{
if n in lookup: # If n is already computed
return n # Return the previous computed solution
else
lookup[n] = fib(n-1) + fib(n-2) # Else, do the recursion.
return lookup[n]
}
```
Caching computed solutions in a lookup table, and query it before go recursion will let the program have a running time of O(N).
#### More Information:
[What is dynamic programming on StackOverflow](https://stackoverflow.com/questions/1065433/what-is-dynamic-programming")
[Difference between memoization and DP on StackOverflow](https://stackoverflow.com/questions/6184869/what-is-the-difference-between-memoization-and-dynamic-programming)

View File

@@ -0,0 +1,62 @@
---
title: Error Handling
---
## Error Handling
Error Handling, and to a larger extent, Exception Handling, are functions/methods written to return important information about the manipulation of data. Error handling is often used alongside Promises and Callbacks.
Error handling is a very important thing every developer should care about while programming. Here I'll explain how to handle errors which occur in run-time using try-catch blocks with an example in C# programs. Try-catch statements are available in all the major programming languages with similar syntax.
### How the try-catch block works.
The try-catch statement consists of a **try** block and a **catch** block and an optional **finally** block. Code that could throw an exception should be put in the try block. The catch block takes the exception that could be thrown as a parameter and then handles that exception inside the block. During runtime, the code in the try block is first executed. If an exception is thrown, it will be thrown to the catch block to be handled. If there is no catch block, the program will display an unhandled exception error and stop running. Multiple catch blocks are used if code in the try block could throw more than one exception. There is also an optional **finally** block that will execute the code in it regardless of whether or not an exception is thrown.
Below is an example program that handles the divide by zero exception using predefined class in C# library. Exception is the base class for all the exceptions.
```c#
using System;
namespace ErrorHandling
{
class DivideByZero
{
int result;
DivideByZero()
{
result = 0;
}
public void division(int num1, int num2)
{
try
{
result = num1 / num2;
}
catch (DivideByZeroException e)
{
Console.WriteLine("Exception caught: {0}", e);
}
catch(Exception ex)
{
Console.WriteLine("Exception caught: {0}", ex);
}
finally
{
Console.WriteLine("Result: {0}", result);
}
}
static void Main(string[] args)
{
DivideByZero d = new DivideByZero();
d.division(10, 0);
Console.ReadKey();
}
}
}
```
* In the above program passing 0 as second parameter will throw DivideByZeroExceptions.
* This exception will handled by the catch block which has DivideByZeroException class. If any exceptions other than DivideByZeroExceptions occur, they will be handled by Exception catch block.
Exception is the base class for all the exceptions classes available in C# library. Even if you want to write your own exception, you have to inherit the Exception base class into your program.
#### More Information:
<!-- Please add any articles you think might be helpful to read before writing the article -->
https://quizlet.com/135129010/computer-science-error-handling-flash-cards/
https://en.wikipedia.org/wiki/Exception_handling

View File

@@ -0,0 +1,21 @@
---
title: Evented Servers
---
## Evented Servers
Evented servers run a single event loop that handles events for all connected clients. This is opposed to Threaded servers, which use multiple concurrently executing threads, where each thread handles one client request.
In simple terms, Evented servers have only one main thread that is shared amongst all client requests.
What is special with Evented servers is the fact that they can prioritize the work that needs to be done with clients' requests.
We'll illustrate this with an example.
Let's say you are the owner of a cab company (let it be known as the Server) and you have people calling your company (let them be known as Clients) that want to arrange a pickup (let those be known as Requests). You hire operators (let them be known as Processes/Threads) to take orders from the Clients. Your business logic states that your operator must stay on the line until a cab driver has been dispatched to the client. So essentially, you would want to hire as many operators as the amount of cab drivers that you can dispatch.
With an Evented server, there is only one operator that is able to take the pickup details from the customers, but knows to call the customer back once the cab driver has been dispatched to him.
These kind of servers use callbacks to let the clients know when their requests have been dealt with.
#### More Information:
<!-- Please add any articles you think might be helpful to read before writing the article -->
[Even-driven architecture on Wikipedia](https://en.wikipedia.org/wiki/Event-driven_architecture)

View File

@@ -0,0 +1,47 @@
---
title: Garbage Collection
---
## Garbage Collection
#### What is Garbage Collection?
In general layman term, Garbage collection (GC) is nothing but collecting or gaining the memory back which has been allocated to the objects, which is not in use at the moment in any part of our program. A brief description as below.
Garbage collection is the process in which programs try to free up memory space that is no longer used by objects, and such. Garbage collection is implemented differently for every language. Most high-level programming languages have some sort of garbage collection built it. Low-level programming languages may add garbage collection through libraries.
As said above, every programming language has their own way of GC. In C programming, developers need to take care of memory allocation and deallocation using malloc() and dealloc() functions. But, in case of C# developers no need to take care of GC and it's not recommended as well.
#### How memory allocation happening?
In C#, memory allocation of objects are happened in managed heap. which takes care by CLR (common language runtime). Memory allocation for the heap is done through win32 dll in OS as like in the C. But, In C objects are placed in memory where ever the free space suits the size of object. And, the memory mapping is woks based on Linkedlist concepts. In C#, memory allocation for heap is happening in linear manner. like one after another.
Whenever a new object is being created. A memory is allocated in the heap and the pointer moved to next memory address. Memory allocation in C# is faster than the C. Since, in C the memory need to search and allocate for the object. so it will take a bit higher time than C#.
#### Generations in C# GC?
In .net programming, heap has three generations called generation 0, 1, 2. Generation 0 get filled first whenever new object is create. Garbage collector run when the Generation 0 get filled. newly created objects are placed in Generation 0. While performing garbage collection all the unwanted objects are destroyed, memory gets freed and compacted. GC takes care of pointing the pointers of freed memory once GC happens.
Generations 1 and 2 has object which has the longer life time. GC on generations 1 and 2 will not happen until the generations 0 has sufficient memory to allocate.
Its not advisable to invoke the GC programmatically. It's good to let it happend on its own. GC get call whenever the generation 0 gets filled. GC will not impact the performance of your program.
Garbage collection is the process in which programs try to free up memory space that is no longer used by variables, objects, and such. Garbage collection is implemented differently for every language. Most high-level programming languages have some sort of garbage collection built in. Low-level programming languages may add garbage collection through libraries.
Garbage collection is a tool that saves time for the programmer, for example it replaces the need for functions such as malloc() and free() which are found in C. It can also help in preventing memory leaks.
The downside of garbage collection is that it has a negative impact on performance. The program has to regularly run though the program, checking object references and cleaning out memory - this takes up resources and often requires the program to pause.
If an object has no references (is no longer reachable) then it is eligible for garbage collection. For example in the Java code below, the Thing object originally referenced by 'thing1' has its one and only reference redirected to another object on the heap - it is then unreachable and will have its memory unallocated by the garbage collector.
```java
class Useless {
public static void main (String[] args) {
Thing thing1 = new Thing();
Thing thing2 = new Thing();
thing2 = thing1; // direct thing2's reference towards thing1
// no references access thing2
} }
```
One example of garbage collection is ARC, short for automatic reference counting. This is used in Swift, for example. ARC boils down to keeping track of the references to all objects that are created. If the amount of references drops to 0, the object will be marked for deallocation.
#### More Information:
* https://docs.microsoft.com/en-us/dotnet/standard/garbage-collection/fundamentals - To know more about garbage Collection

View File

@@ -0,0 +1,86 @@
---
title: Hexadecimal Numbers
---
## The Hexadecimal Numeral System
Hexadecimal numbers, often shortened to "hex numbers" or "hex",
are numbers represented in base 16 as opposed to base 10 that we use for everyday arithmetic and counting.
In practical terms, this means that each column of a number written in hexadecimal can represent up to 16 values.
Digits in hexadecimal use the standard symbols 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9 to represent the corresponding value,
and use the first six letters of the alphabet to represent the values 10 through 15 (E.G: A, B, C, D, E, F).
In programming, we prefix hexadecimal constants with `0x`, with some exceptions.
### Examples and explanation
```
0x1 == 1
0xF == 15
0xFF == 255
0xFFF == 4095
0x1000 == 4096
```
In the standard base 10 system, each column represents increasing powers of 10,
while in base 16 each column represents increasing powers of 16.
As seen in the table example above, with one hex digit we can represent numbers up to and including 15. Add another column and we can represent numbers up to 255, 4095 with another column, and so on.
## Uses of Hexadecimal in Low Level Programming
Hexadecimal first found its use in Computer Science as a convenience feature.
Data in our computers has a lowest common storage unit, the Byte.
Each byte contains 8 bits, and is able to store a number between 0 and 255 inclusive.
Hexadecimal has the advantage of being terse and having well defined boundaries.
A single byte is always represented by two hexadecimal digits
from 0x00 to 0xFF, the latter being the largest per-byte value of 255.
The terseness and byte-aligned nature of hexadecimal numbers make them a popular choice for software engineers working on low-level code-bases or embedded software.
## Uses of Hexadecimal Numbers in JavaScript
JavaScript supports the use of hexadecimal notation in place of any integer, but not decimals.
As an example, the number 2514 in hex is 0x9D2, but there is no language-supported way of representing 25.14 as a hex number.
Using hexadecimal in your code is a personal and stylistic choice, and has no effect on the underlying logic your code implements.
## Uses of Hexadecimal Numbers in CSS
CSS has for a long time used hexadecimal notation to represent color values. Consider the following selector:
```css
.my-container {
background-color: #112233;
color: #FFFFFF;
}
```
The `background-color`'s value is in fact three hex bytes.
The CSS processor treats these as three individual bytes, representing Red, Green, and Blue.
In our example, 11 corresponds to the Red color component, 22 corresponds to the Green color component, and 33 to the Blue color component.
There is currently no way as of CSS3 to define a color with an alpha component using hex.
The proposed CSS4 Draft<sup>1</sup> includes a proposal to allow for an extra byte to specify alpha values.
For now, use of the standard `rgba()` function is the recommended way to add an alpha value to your colors.
#### References:
+ <sup>1</sup> [CSS Color Module Level 4 - 4.2. The RGB hexadecimal notations: #RRGGBB](https://www.w3.org/TR/css-color-4/#hex-notation)
#### More Information:
<!-- Please add any articles you think might be helpful to read before writing the article -->
* [How Do HEX Color Codes Work? (in 60 seconds)](https://www.youtube.com/watch?v=c56x1aj2CPA) - Good Video which also explains a little bit about Hexadecimal Numbers.
* [Hex Codes & Color Theory](https://www.youtube.com/watch?v=xlRiLSDdqcY) - A Longer Video which delves into Color theory (Such as what are additive colors and what are subtractive colors etc.) and it also points to other resources for delving deeper into the topic.
* [Web Colors](https://en.wikipedia.org/wiki/Web_colors) - Wikipedia Article on how colors are used on the web.
* [Wikipedia article about Hexadecimal code](https://en.wikipedia.org/wiki/Hexadecimal)
* [Wikipedia article about hexadecimal numeral system](https://wikipedia.org/wiki/Hexadecimal_numeral_system)
* [Wikipedia article about web colors](https://en.wikipedia.org/wiki/Web_colors)
* [Hex Colors](http://www.color-hex.com/)
* [Medium article on hex color code](https://medium.com/webkul-dev/hex-color-codes-27cd0a37c3ce)
* [More information on color values in CSS](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value)
* [CSS color property on the MDN web docs](https://developer.mozilla.org/en-US/docs/Web/CSS/color)
* [Explore different Hex colors](http://www.colorhexa.com/)

View File

@@ -0,0 +1,39 @@
---
title: Computer Science
---
# Computer Science
Computer Science is the study of computers and the concepts that make computers possible.
Much of computer science was pioneered in the latter half of the 20th century.
Today, if you attend an undergraduate computer science course, you will learn about both hardware and software. You'll learn how computers work at a low level of abstraction (machine language) and at a high level of abstraction (modern scripting langauges like JavaScript).
# Computer Science Fields
Computer science is categorized into several fields. The following are among the current established and well-studied fields. Most of the fields are further categorized into sub0fields.
- <a href="https://en.wikipedia.org/wiki/Theory_of_computation">Theory of Computing</a>
- Complexity Theory
- Formal Methods
- Distributed Algorithms
- <a href="https://en.wikipedia.org/wiki/Computer_security">Security</a>
- Cryptography<br>
- <a href="https://en.wikipedia.org/wiki/Artificial_intelligence">Artificial Intelligence</a>
- Data Mining
- Machine Learning
- Computer Vision
- <a href="https://en.wikipedia.org/wiki/Software_engineering">Software Engineering</a>
- <a href="https://en.wikipedia.org/wiki/Data_science">Data Sciences</a>
- Big Data
- <a href="https://en.wikipedia.org/wiki/Human%E2%80%93computer_interaction">Human Computer Interaction</a>
- Brain Computer Interface
- Systems
- Distributed Systems
- Operating Systems
- Database Systems
##More Information
* [Visualization of Data Structures](http://www.cs.usfca.edu/~galles/JavascriptVisual/Algorithms.html)
* [Khan Academy](https://www.khanacademy.org/computing/computer-science) : A deep dive into algorithms, cryptography, introductory computing, and much more.
* [CS50](https://cs50.harvard.edu) : A free, introduction to computer science course, taught by David J. Malan and staff at Harvard & Yale Universities.
* [Visualization of Data Structures](http://www.cs.usfca.edu/~galles/JavascriptVisual/Algorithms.html)

View File

@@ -0,0 +1,21 @@
---
title: Interpreters
---
## Interpreters
Interpreters are a kind of translator. Interpreters take source code - code written in JavaScript, Python, and other languages. Then they translate it into code the computer understands.
This translated code is binary code. It is nothing but 1s and 0s. Interpreters translate the source code line-by-line, while running the binary code. The program will run until the interpreter finds errors in the source code. Then it will stop translating/running the program and flag the errors.
To compare, compilers convert all the source code at once to binary code, then run the binary code.
#### More Information:
[Matt Adesanya's "A Gentler Introduction to Programming"](https://medium.freecodecamp.org/a-gentler-introduction-to-programming-707453a79ee8) compares compilers and interpreters, and introduces other basic programming concepts.
Some Interpreted Languages:
* [Python](https://en.wikipedia.org/wiki/Python_(programming_language))
* [JavaScript](https://en.wikipedia.org/wiki/JavaScript)
* [Ruby](https://en.wikipedia.org/wiki/Ruby_(programming_language))
* [Forth](https://en.wikipedia.org/wiki/Forth_(programming_language))
* [Perl](https://en.wikipedia.org/wiki/Perl)

View File

@@ -0,0 +1,68 @@
---
title: Just in Time Compilation
---
## Just in Time Compilation
Just-in-time compilation is a method for improving the performance of interpreted programs. During execution the program may be compiled into native code to improve its performance. It is also known as dynamic compilation.
Dynamic compilation has some advantages over static compilation. When running Java or C# applications, the runtime environment can profile the application while it is being run. This allows for more optimized code to be generated. If the behavior of the application changes while it is running, the runtime environment can recompile the code.
Some of the disadvantages include startup delays and the overhead of compilation during runtime. To limit the overhead, many JIT compilers only compile the code paths that are frequently used.
### Overview
Traditionally there are two methods for converting source code into a form that can be run on a platform. Static compilation converts the code into a language for a specific platform. An interpreter directly executes the source code.
JIT compilation attempts to use the benefits of both. While the interpretted program is being run, the JIT compiler determines the most frequently used code and compiles it to machine code. Depending on the compiler, this can be done on a method or smaller section of code.
Dynamic compilation was first described in a paper by J. McCarthy on LISP in 1960.
Just In Time Compilation, JIT, or Dynamic Translation, is compilation that is being done during the execution of a program. Meaning, at run time, as opposed to prior to execution. What happens is the translation to machine code. The advantages of a JIT are due to the fact, that since the compilation takes place in run time, a JIT compiler has access to dynamic runtime information enabling it to make better optimizations (such as inlining functions).
What is important to understand about the JIT compilation, is that it will compile the bytecode into machine code instructions of the running machine. Meaning, that the resulting machine code is optimized for the running machine's CPU architecture.
Two examples of JIT Compilers are : JVM (Java Virtual Machine) in Java and CLR (Common Language Runtime), in C#.
## JIT stands for Just-in-Time which means that code gets compiled when it is needed, not before runtime.
In the beginning, a compiler was responsible for turning a high-level language (defined as higher level than assembler) into object code (machine instructions), which would then be linked (by a linker) into an executable.
At one point in the evolution of languages, compilers would compile a high-level language into pseudo-code, which would then be interpreted (by an interpreter) to run your program. This eliminated the object code and executables, and allowed these languages to be portable to multiple operating systems and hardware platforms. Pascal (which compiled to P-Code) was one of the first; Java and C# are more recent examples. Eventually the term P-Code was replaced with bytecode, since most of the pseudo-operations are a byte long.
A Just-In-Time (JIT) compiler is a feature of the run-time interpreter, that instead of interpreting bytecode every time a method is invoked, will compile the bytecode into the machine code instructions of the running machine, and then invoke this object code instead. Ideally the efficiency of running object code will overcome the inefficiency of recompiling the program every time it runs.
A JIT compiler runs after the program has started and compiles the code (usually bytecode or some kind of VM instructions) on the fly (or just-in-time, as it's called) into a form that's usually faster, typically the host CPU's native instruction set. A JIT has access to dynamic runtime information whereas a standard compiler doesn't and can make better optimizations like inlining functions that are used frequently.
This is in contrast to a traditional compiler that compiles all the code to machine language before the program is first run.
To paraphrase, conventional compilers build the whole program as an EXE file BEFORE the first time you run it. For newer style programs, an assembly is generated with pseudocode (p-code). Only AFTER you execute the program on the OS (e.g., by double-clicking on its icon) will the (JIT) compiler kick in and generate machine code (m-code) that the Intel-based processor or whatever will understand.
## Typical scenario:
The source code is completely converted into machine code
## JIT scenario:
The source code will be converted into assembly language like structure [for ex IL (intermediate language) for C#, ByteCode for java].
The intermediate code is converted into machine language only when the application needs that is required codes are only converted to machine code.
## JIT vs Non-JIT comparison:
In JIT not all the code is converted into machine code first a part of the code that is necessary will be converted into machine code then if a method or functionality called is not in machine then that will be turned into machine code... it reduces burden on the CPU.
As the machine code will be generated on run time....the JIT compiler will produce machine code that is optimised for running machine's CPU architecture.
JIT Examples:
In Java JIT is in JVM (Java Virtual Machine)
In C# it is in CLR (Common Language Runtime)
In Android it is in DVM (Dalvik Virtual Machine), or ART (Android RunTime) in newer versions.
Java Virtual Machine (JVM)( JVM executes bytecode) maintains a count as of how many time a function is executed. If this count exceeds a predefined limit JIT compiles the code into machine language which can directly be executed by the processor (unlike the normal case in which javac compile the code into bytecode and then java - the interpreter interprets this bytecode line by line converts it into machine code and executes).
Also next time this function is calculated same compiled code is executed again unlike normal interpretation in which the code is interpreted again line by line. This makes execution faster.
#### More Information
- [JIT Compilation (Wikipedia)](https://en.wikipedia.org/wiki/Just-in-time_compilation)
- [JIT Introduction](https://eli.thegreenplace.net/2013/11/05/how-to-jit-an-introduction/)

View File

@@ -0,0 +1,20 @@
---
title: Asymptotic Notation
---
## Asymptotic Notation
How do we measure the performance value of algorithms?
Consider how time is one of our most valuable resources. In computing, we can measure performance with the amount of time a process takes to complete. If the data processed by two algorithms is the same, we can decide on the best implementation to solve a problem.
We do this by defining the mathematical limits of an algorithm. These are the big-O, big-omega, and big-theta, or the asymptotic notations of an algorithm. On a graph the big-O would be the longest an algorithm could take for any given data set, or the "upper bound". Big-omega is like the opposite of big-O, the "lower bound". That's where the algorithm reaches its top-speed for any data set. Big theta is either the exact performance value of the algorithm, or a useful range between narrow upper and lower bounds.
Some examples:
- "The delivery will be there within your lifetime." (big-O, upper-bound)
- "I can pay you at least one dollar." (big-omega, lower bound)
- "The high today will be 25ºC and the low will be 19ºC." (big-theta, narrow)
- "It's a kilometer walk to the beach." (big-theta, exact)
#### More Information:
<!-- Please add any articles you think might be helpful to read before writing the article -->
- <a href='https://learnxinyminutes.com/docs/asymptotic-notation/' target='_blank' rel='nofollow'>Asymptotic Notation</a>

View File

@@ -0,0 +1,75 @@
---
title: Big O Notation
---
## Big O Notation
*As a computer scientist, if you are working on an important piece of software, you will likely need to be able to estimate how fast some algorithm or other going to run.*
Big O notation is used in computer science to describe the performance or complexity of an algorithm. Actually Big O notation is special symbol that tells you how fast an algorithm is. Of course youll use predefined algorithms oftenand when you do, its vital to understand how fast or slow they are.
#### What Big O notation looks like?
<img align="left" src="https://user-images.githubusercontent.com/5860906/31781171-74c6b48a-b500-11e7-9626-f715b37b10f0.png">
This tells you the number of operations an algorithm will make. Its called Big O notation because you put a “Big O” in front of the number of operations.
<br clear="left"/>
#### Big O establishes a worst-case run time
Say you are a doctor who is treating Harry Abbit, you might look into the electronic records that are related to Harry Abbit's medical history (he is the first person in a list). Lets consider the situation when his life depends on all available medical data.
Suppose youre using simple search to look for a person in the electronic records. You know that simple search takes O(n) time to run, so youll have to look through every single entry for Abbit. Of course, youve noticed that Abbit is the first entry, so you didnt have to look at every entryyou found it on the first try.
*Did this algorithm take O(n) time? Or did it take O(1) time because you found the person on the first try?*
In this case, thats the best-case scenario. But Big O notation is about the worst-case scenario. Thats O(n) time (simple search still takes). Its a reassurance that simple search will never be slower than O(n) time.
#### Algorithm running times grow at different rates
Lets assume it takes 1 millisecond to check one entry. With simple search, the doctor has to check 10 entries, so the search takes 10 ms to run. On the other hand, he only has to check 3 elements with *binary search algorithm* (log10 is roughly 3), so that search takes 3 ms to run. 
But realistically, the list will have more than a hundred elements. 
*If it does, how long will simple search take? How long will binary search take?*
The run time for simple search with 1 billion items will be 1 billion ms, which is 11 days. The problem is, the run times for binary search and simple search *dont grow at the same rate*.
<p align="center">
<img src="https://user-images.githubusercontent.com/5860906/31781165-723a053c-b500-11e7-937c-7b33db281efe.png">
</p>
So as the list of numbers gets bigger, binary search becomes a lot faster than simple search. That is, as the number of items increases, binary search takes a little more time to run. But simple search takes a *lot* more time to run. So as the list of numbers gets bigger, binary search becomes a lot faster than simple search. 
*Thats why its not enough to know how long an algorithm takes to runyou need to know how the running time increases as the list size increases. Thats where Big O notation comes in.*
#### Big O notation lets you compare the number of operations
For example, suppose you have a list of size n. Simple search needs to check each element, so it will take n operations. The run time in Big O notation is O(n). 
*Where are the seconds?*
There are noneBig O doesnt tell you the speed in seconds. *Big O notation lets you compare the number of operations.* It tells you how fast the algorithm grows.
<p align="center">
<img src="https://user-images.githubusercontent.com/5860906/31781175-768c208e-b500-11e7-9718-e632d1391e2d.png">
</p
#### Most common running times for algorithms
A list of the most common running times for algorithms in terms of Big O notation. 
Here are five Big O run times that youll encounter a lot, sorted from fastest to slowest:
1. O(log n), also known as *log time*. 
Example: Binary search.
2. O(n), also known as *linear time*. 
Example: Simple search.
3. O(n * log n)
Example: A fast sorting algorithm, like quicksort (coming up in chapter 4).
4. O(n2)
Example: A slow sorting algorithm, like selection sort (coming up in chapter 2).
5. O(n!)
Example: A really slow algorithm, like the traveling salesperson (coming up next!).
*This article only covers the very basics of Big O. For a more in-depth explanation take a look at their respective FreeCodeCamp guides for algorithms.*
### More Information
- [Khan Academy](https://www.khanacademy.org/computing/computer-science/algorithms/asymptotic-notation/a/big-o-notation)
- [Big O cheat sheet](http://bigocheatsheet.com/)

View File

@@ -0,0 +1,28 @@
---
title: Big Omega Notation
---
## Big Omega Notation
This is a stub. <a href='https://github.com/freecodecamp/guides/tree/master/src/pages/computer-science/notation/big-omega-notation/index.md' target='_blank' rel='nofollow'>Help our community expand it</a>.
<a href='https://github.com/freecodecamp/guides/blob/master/README.md' target='_blank' rel='nofollow'>This quick style guide will help ensure your pull request gets accepted</a>.
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
Similar to [big O](https://guide.freecodecamp.org/computer-science/notation/big-o-notation) notation, big Omega(Ω) function is used in computer science to describe the performance or complexity of an algorithm.
If a running time is Ω(f(n)), then for large enough n, the running time is at least k⋅f(n) for some constant k. Here's how to think of a running time that is Ω(f(n)):
<img src="https://s3.amazonaws.com/ka-cs-algorithms/Omega_fn.png" alt="big-omega function"/>
We say that the running time is "big-Ω of f(n)." We use big-Ω notation for **asymptotic lower bounds**, since it bounds the growth of the running time from below for large enough input sizes.
### Difference between Big O and Big Ω
The difference between Big O notation and Big Ω notation is that Big O is used to describe the worst case running time for an algorithm. But, Big Ω notation, on the other hand, is used to describe the best case running time for a given algorithm.
#### More Information:
<!-- Please add any articles you think might be helpful to read before writing the article -->
- [Big-Ω (Big-Omega) notation](https://www.khanacademy.org/computing/computer-science/algorithms/asymptotic-notation/a/big-big-omega-notation)
- <a href="http://www.youtube.com/watch?feature=player_embedded&v=OpebHLAf99Y
" target="_blank"><img src="http://img.youtube.com/vi/OpebHLAf99Y/0.jpg"
alt="MYCODSCHOOL Time complexity analysis" width="240" height="180" border="10" /></a>

View File

@@ -0,0 +1,47 @@
---
title: Big Theta Notation
---
## Big Theta Notation
Big Omega tells us the lower bound of the runtime of a function, and Big O tells us the upper bound. Often times, they are different and we can't put a guarantee on the runtime - it will vary between the two bounds and the inputs. But what happens when they're the same? Then we can give a **theta** (Θ) bound - our function will run in that time, no matter what input we give it. In general, we always want to give a theta bound if possible because it is the most accurate and tightest bound. If we can't give a theta bound, the next best thing is the tightest O bound possible.
Take, for example, a function that searches an array for the value 0:
```python
def containsZero(arr): #assume normal array of length n with no edge cases
for num x in arr:
if x == 0:
return true
return false
```
1. What's the best case? Well, if the array we give it has 0 as the first value, it will take constant time: Ω (1)
2. What's the worst case? If the array doesn't contain 0, we will have iterated through the whole array: O(n)
We've given it an omega and O bound, so what about theta? We can't give it one! Depending on the array we give it, the runtime will be somewhere in between constant and linear.
Let's change our code a bit.
```python
def printNums(arr): #assume normal array of length n with no edge cases
for num x in arr:
print(x)
```
Can you think of a best case and worst case??
I can't! No matter what array we give it, we have to iterate through every value in the array. So the function will take AT LEAST n time (Ω(n)), but we also know it won't take any longer than n time (O(n)). What does this mean? Our function will take **exactly** n time: Θ(n).
If the bounds are confusing, think about it like this. We have 2 numbers, x and y. We are given that x <= y and that y <= x. If x is less than or equal to y, and y is less than or equal to x, then x has to equal y!
If you're familiar with linked lists, test yourself and think about the runtimes for each of these functions!
1. get
2. remove
3. add
Things get even more interesting when you consider a doubly linked list!
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
#### More Information:
<!-- Please add any articles you think might be helpful to read before writing the article -->
https://www.khanacademy.org/computing/computer-science/algorithms/asymptotic-notation/a/big-big-theta-notation
https://stackoverflow.com/questions/10376740/what-exactly-does-big-%D3%A8-notation-represent
https://www.geeksforgeeks.org/analysis-of-algorithms-set-3asymptotic-notations/

View File

@@ -0,0 +1,15 @@
---
title: Notation
---
## Notation
This is a stub. <a href='https://github.com/freecodecamp/guides/tree/master/src/pages/computer-science/notation/index.md' target='_blank' rel='nofollow'>Help our community expand it</a>.
<a href='https://github.com/freecodecamp/guides/blob/master/README.md' target='_blank' rel='nofollow'>This quick style guide will help ensure your pull request gets accepted</a>.
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
#### More Information:
<!-- Please add any articles you think might be helpful to read before writing the article -->

View File

@@ -0,0 +1,22 @@
---
title: Np Completeness
---
## Np Completeness
NP-Complete is a property of certain types of problems. If a problem is NP-Complete, it means that there is no efficient (polynomial) algorithm to find a solution to it quickly. However, if a solution is given to us, we can quickly (in polynomial time) verify that it is correct.
To be more concrete, let us examine a known NP-Complete problem - the subset sum problem. Say we have a set of integers {7, 3, 2, 5, 8}. We want to find a subset of these integers whose elements sum up to 0. How can we do that?
One way would be to simply enumerate all possible subsets and check if their elements sum up to 0. This would be exponentially complex.
And indeed, there is no better algorithm known, which improves on the exponential time bound. That is why it is classifies as an NP-Complete problem.
There are many such known problems apart from the subset sum problem which are known to be NP-Complete. If an efficient algorithm for one is found, it implies that we can design an efficient algorithm for all problems which are NP-Complete.
If you have a problem that can be proved to be NP-complete, you should stop trying to find more efficient algorithms for it and instead use heuristics to solve the problem for most test cases, or solve an approximate version of the problem. Or maybe examine the problem you're solving to see if it can't be simplified to something that isn't NP-Complete.
#### More Information:
https://www.ics.uci.edu/~eppstein/161/960312.html
https://stackoverflow.com/questions/210829/what-is-an-np-complete-in-computer-science

View File

@@ -0,0 +1,86 @@
---
title: Parallel Computing
---
## Parallel Computing
In the simplest sense, parallel computing is the simultaneous use of **multiple compute resources** to solve a computational problem:
- A problem is broken into discrete parts that can be solved concurrently.
- Each part is further broken down to a series of instructions.
- Instructions from each part execute simultaneously on different processors.
- An overall control/coordination mechanism is employed.
![Parallelism](https://computing.llnl.gov/tutorials/parallel_comp/images/parallelProblem.gif)
### Why Parallelism
- Faster, of course
- Finish the work earlier - Same work in less time
- Do more work - More work in the same time
### How to parallelize
- Firstly, break down the computational part into small pieces.
- Then, sssign the small jobs to the parallel running processes.
- But it might become complicated when the small piece of jobs depend upon others.
### Writing a Parallel Program
- If you are starting with an existing serial program, debug the serial code completely.
- Identify which parts of the program can be executed concurrently.
- Requires a thorough understanding of the algorithm.
- Exploit any parallelism which may exist.
- May require restructuring of the program and/or algorithm. May require an entirely new algorithm.
- Decompose the program:
- Task Parallelism
- Data Parallelism
- Combination of both
### Task (Functional) Parallelism
- Different operations are performed on the same or different data in parallel to fully utilize the resources.
- Decomposing the problem into different processes which can be distributed to multiple processors for simultaneous execution.
- Good to use when there is not static structure or fixed determination of number of calculations to be performed.
### Data (Domain) Parallelism
- Same operations are performed on different subsets of same data structure.
- Partitioning the problem's data domain and distributing portions to multiple processors for simultaneous execution.
- Good to use for problems where:
- data is static.
- domain is fixed but computation within various regions of the domain is dynamic.
### Elements of a Parallel Computer
- Hardware
- Multiple Processors
- Multiple Memories
- Interconnection Network
- System Software
- Parallel Operating System
- Programming Constructs to Express/Orchestrate Concurrency
- Application Software
- Parallel Algorithms
### Communication Model of Parallel Platforms
- There are two primary forms of data exchange between parallel tasks
- accessing a shared data space and exchanging messages.
- Platforms that provide a shared data space are called **shared-address-space** machines or **mult iprocessors**.
- Platforms that support messaging are called **message passing platforms** or **multicomputers**.
### Shared-Address-Space Platforms
- Part (or all) of the memory is accessible to all processors.
- Processors interact by modifying data objects stored in this shared-address-space.
- If the time taken by a processor to access any memory word in the system (global or local) is
- identical, then the platform is classified as a **uniform memory access (UMA)**,
- not identical, then its classified as **non-uniform memory access (NUMA)** machine.
![Shared memory](https://computing.llnl.gov/tutorials/parallel_comp/images/sharedMemoryModel.gif)
### Message-Passing Platforms
- These platforms comprise of a set of processors and their own (exclusive) memory.
- Instances of such a view come naturally from clustered workstations and non-shared-addressspace multicomputers.
- Interactions between processes running on different nodes must be accomplished using messages.
- The exchange of messages is used to transfer data, work and to synchronize actions among the processes.
- These platforms are programmed using (variants of) **send** and **receive** primitives.
- Libraries such as **MPI** and **PVM** provide such primitives.
![Message passing](https://computing.llnl.gov/tutorials/parallel_comp/images/msg_pass_model.gif)
#### More Information:
- [Parallel Computing on Wikipedia](https://en.wikipedia.org/wiki/Parallel_computing)
- [Introduction to Parallel Computing](https://computing.llnl.gov/tutorials/parallel_comp/)

View File

@@ -0,0 +1,29 @@
---
title: Ports
---
## Ports
A port is an endpoint of communication for an operating system, in the internet protocol suite. Service names and port numbers are used to distinguish between different services that run over transport protocols such as TCP, UDP, DCCP, and SCTP.
When a computer receives a message from an another source the ports will help in determining which process is expecting that message.
A port is always related to an ip adress of a host and the protocol type of the communication, and thus completes the destination or origination network address of a communication session. There is 65536 available ports in operating system. A port is identified for each address and protocol by a 16-bit number, commonly known as the port number. For example, an address may be "protocol: TCP, IP address: 1.2.3.4, port number: 80", which may be written 1.2.3.4:80 when the protocol is known from context.
Some port numbers are used by convention to identify specific services, such as:
* 20 - FTP
* 21 - FTP
* 22 - SSH
* 23 - Telnet
* 25 - SMTP
* 42 - nameserver
* 53 - Domain Name System (DNS)
* 80 - http
* 110 - pop3
* 143 - imap
* 194 - irc
* 443 - https
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
### Sources
* [iana.org](https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml)
* [Wikipedia](https://en.wikipedia.org/index.php?q=aHR0cHM6Ly9lbi53aWtpcGVkaWEub3JnL3dpa2kvUG9ydF8oY29tcHV0ZXJfbmV0d29ya2luZyk)
* [Webopedia](https://www.webopedia.com/quick_ref/portnumbers.asp)

View File

@@ -0,0 +1,34 @@
---
title: Quantum Computing
---
## Quantum Computing
Quantum computing studies computation systems (quantum computers) that make direct use of quantum-mechanical phenomena, such as superposition and entanglement, to perform operations on data.
### What is quantum computing?
Nature -- including molecules like caffeine -- follows the laws of quantum mechanics, a branch of physics that explores how the physical world works at the most fundamental levels. At this level, particles behave in strange ways, taking on more than one state at the same time, and interacting with other particles that are very far away. Quantum computing harnesses these quantum phenomena to process information in a novel and promising way.
Quantum Computing is the study of quantum computation systems that make use of quantum mechanical phenomena, such as entanglement and superposition. Classical binary digit electronic computers (like your own PC!) are based on transistors, which stores data in binary digits (bits), each of which can be in one of two states (0 or 1). Quantum computers on the other hand store data into quantum bits, which can be in superpositions of states.
Because a quantum computer is able to take advantage of these quantum mechanical properties, it is theorized that large scale quantum computers will be able to solve certain problems far quicker than a classical computer.
### What are classical computers?
The computers we use today are known as classical computers. Theyve been a driving force in the world for decades -- advancing everything from healthcare to how we shop. But there are certain problems that classical computers will simply never be able to solve. Consider the caffeine molecule in a cup of coffee. Surprisingly, its complex enough that no computer that exists or could be built would be capable of modeling caffeine and fully understanding its detailed structure and properties. This is the type of challenge quantum has the potential to tackle.
### How do quantum computers works?
Classical computers encode information in bits. Each bit can take the value of 1 or 0. These 1s and 0s act as on/off switches that ultimately drive computer functions. Quantum computers, on the other hand, are based on qubits, which operate according to two key principles of quantum physics: superposition and entanglement. Superposition means that each qubit can represent both a 1 and a 0 at the same time. Entanglement means that qubits in a superposition can be correlated with each other; that is, the state of one (whether it is a 1 or a 0) can depend on the state of another. Using these two principles, qubits can act as more sophisticated switches, enabling quantum computers to function in ways that allow them to solve difficult problems that are intractable using todays computers.
### What can quantum computers do?
Quantum systems may untangle the complexity of molecular and chemical interactions leading to the discovery of new medicines and materials. They may enable ultra-efficient logistics and supply chains, such as optimizing fleet operations for deliveries during the holiday season. They may help us find new ways to model financial data and isolate key global risk factors to make better investments. And they may make facets of artificial intelligence such as machine learning much more powerful.
### Further Resources
[Quantum Computers Explained Limits of Human Technology | Kurzgesagt In a Nutshell](https://www.youtube.com/watch?v=JhHMJCUmq28)
[Quantum computing explained with a deck of cards | Dario Gil, IBM Research](https://www.youtube.com/watch?v=yy6TV9Dntlw)

View File

@@ -0,0 +1,21 @@
---
title: Qubits
---
## Qubits
A Qubit is short for quantum bit, analogous to the classical computer's binary digit (bit). It is the basic unit of information in a quantum computer, just like a binary digit (0 or 1) is the basic unit of information in classical computers widely in use today.
The major difference between the classical bit and the quantum bit has to do with the amount of **states** they can exist in at a time which directly impacts on the amount of information they can hold. In a classical system, a bit would have to be in one state (0) or the other (1) at any one time. However, **quantum mechanics** allows the qubit to behave as if it were in both states simultaneously. In other words, each additional qubit utilized increases exponentially the amount of information the quantum computer can process or hold. This property is fundamental to quantum computing.
To illustrate this further, if you had one qubit, you can store a "0" and "1" simultaneously (which corresponds to a total of 2 states or values). If you had a 2-qubit system, you can hold **four** values at once - 00, 01, 10, and 11. With a 3-qubit system, you can hold **eight** values at once - 000, 001, 010, 011, 100, 101, 110, and 111. In general, a quantum system consisting of n-qubits will be able to have 2^n states which is exponentially more powerful than any classical computer.
#### More Information:
[Ars Technica - Explanation of Quantum Computing and Qubits](https://arstechnica.com/science/2010/01/a-tale-of-two-qubits-how-quantum-computers-work)
[Wikipedia - Qubits](https://en.wikipedia.org/wiki/Qubit)
[Wikipedia - Quantum Superposition](https://en.wikipedia.org/wiki/Quantum_superposition)
[Quantum Mechanics on Wikipedia](https://en.wikipedia.org/wiki/Quantum_mechanics)

View File

@@ -0,0 +1,13 @@
---
title: Recursive Descent
---
## Recursive Descent
This is a stub. <a href='https://github.com/freecodecamp/guides/tree/master/src/pages/computer-science/recursive-descent/index.md' target='_blank' rel='nofollow'>Help our community expand it</a>.
<a href='https://github.com/freecodecamp/guides/blob/master/README.md' target='_blank' rel='nofollow'>This quick style guide will help ensure your pull request gets accepted</a>.
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
#### More Information:
<!-- Please add any articles you think might be helpful to read before writing the article -->

View File

@@ -0,0 +1,39 @@
---
title: Shortest Path on a Graph
---
## Shortest Path on a Graph
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
Finding the shortest path between two points on a graph is a common problem in data structures especially when dealing with optimization. A graph is a series of nodes connected by edges. Graphs can be weighted (edges carry values) and directional (edges have direction).
Some applications of this are flight path optimization or <a href='https://en.wikipedia.org/wiki/Six_Degrees_of_Kevin_Bacon' target='_blank' rel='nofollow'>6 degrees of Kevin Bacon</a>
## Dijkstra's Algorithm
The most common solution for this problem is Dijkstra's algorithm which updates the shortest path between the current node and all of its neighbors. After updating the distance of all of the neighbors it moves to the node with the lowest distance and repeats the process with all unvisted neighbors. This process continues until the entire graph has been visited.
![Image of Levels of Code](https://upload.wikimedia.org/wikipedia/commons/5/57/Dijkstra_Animation.gif)
**Step 0:**
Our graph needs to be setup so that we can record the required values. On any edge we have the distance between the two nodes it connects. On any node we have its shortest distance from the starting node. Lets set the value on every node to positive infinity, and set the value on the starting node to zero.
**Step 1:**
Look at all nodes directly adjascent to the starting node. The values carried by the edges connecting the start and these adjascent nodes are the shortest distances to each respective node. Record these distances on the node - overwriting infinity - and also cross off the nodes, meaning that their shortest path has been found.
**Step 2:**
Select one of the nodes which has had its shortest path calculated, we'll call this our pivot. Look at the nodes adjascent to it (we'll call these our destination nodes) and the distances separating them. For every destination node: if the value in the pivot plus the edge value connecting it totals less than the destination node's value, then update its value, as a new shorter path has been found. If all routes to this destination node have been explored, it can be crossed off.
**Step 3:**
Repeat step 2 until all nodes have been crossed off. We now have a graph where the values held in any node will be the shortest distance to it from the start node.
#### More Information:
<!-- Please add any articles you think might be helpful to read before writing the article -->
<a href='https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm' target='_blank' rel='nofollow'>More On Dijkstra's algorithm</a>
<a href='https://en.wikipedia.org/wiki/Shortest_path_problem#Algorithms' target='_blank' rel='nofollow'>Other Shortest path algorithms</a>

View File

@@ -0,0 +1,40 @@
---
title: Threads
---
## Threads
A sequence of program instructions given to the operating system to execute. It is the smallest synchronous sequence that can be executed. Being synchronous, instructions in a thread are linear and execute one after another. If a program has multiple threads, the program as a whole can be asynchronous in that these threads are executing their own instructions independently of each other (simultaneously).
A thread is an abstraction that operating systems use to represent the CPU to programs. There is no real concept of threads in machine code or assembly languages.
Threads are a way in programming to perform multiple tasks at the same time.
A common distinction one should make is the difference between threads and processes. A thread is a child of a process so to speak.
There may be any number of child threads within the context of a process. Threads can increase the speed of execution of a program, by increasing the percentage of CPU used for the task.
Note that drastically increasing the number of threads in a program can be highly CPU intensive, and if 100% of a CPU is being used, then threads will have no effect on the speed of execution.
![Threads inside a Process graph](https://upload.wikimedia.org/wikipedia/commons/thumb/a/a5/Multithreaded_process.svg/440px-Multithreaded_process.svg.png)
Suppose you have multiple programs open - each programs share of the CPUs time is represented by one or more threads associated with that program. When the operating systems **scheduler** decides that it is Program As turn to run, the OS feeds (or to be more accurate, multiplexes) instructions in Program As thread to the CPU, which then runs these instructions.
A thread for a certain program consists of some or all of that programs compiled instructions, plus some information required for the CPU to execute these instructions.
**Multithreading** is a programming concept where a program spawns multiple threads during execution so as to perform tasks faster.
Here is a simple multithreading example in python which prints the numbers 1 through 10, by spawning a separate thread for each print statement.
````
import threading
def print_number(number):
print(number)
if __name__ == "__main__":
for i in range(1, 11):
threading.Thread(target=print_number, args=(i,)).start()
````
#### More Information:
<!-- Please add any articles you think might be helpful to read before writing the article -->
- [Threads (Wikipedia)](https://en.wikipedia.org/wiki/Thread_(computing))
- [Understanding Multithreading](http://www.nakov.com/inetjava/lectures/part-1-sockets/InetJava-1.3-Multithreading.html)

View File

@@ -0,0 +1,17 @@
---
title: Ubiquitous Computing
---
## Ubiquitous Computing
The term ubiquitous computing was introduced by Mark Weiser in 1988. He wrote several papers in which he describes his vision of a future where technology is embedded in the environment and everyday objects.
One of the main ideas of ubiquitous computing is that those embedded devices communicate with each other and the surrounding environment in an invisible way so that they can support us in our daily life without being noticed.
Ubiquitous computing is often referred to as pervasive or calm computing because it is about everything in the world being embedded with sensors so that the environment around us can configure itself to all of our needs and requirements without requiring any input or confirmation from us.
A famous example of ubiquitous technology is a smart fridge that knows when you are running low on milk. It would contact your local supermarket so that milk is added to the next delivery of groceries. A smart fridge could also provide you with recipe ideas based on the ingredients that are inside it.
#### More Information:
* [Pervasive Computing on TechTarget](http://internetofthingsagenda.techtarget.com/definition/pervasive-computing-ubiquitous-computing)
* [Ubiquitous Computing on Techopedia](https://www.techopedia.com/definition/22702/ubiquitous-computing)
* [7 things you need to know about ubiquitous computing](http://www.monitis.com/blog/top-7-things-you-need-to-know-about-ubiquitous-computing/)
* [YouTube video: A Day Made of Glass](https://youtu.be/jZkHpNnXLB0)

View File

@@ -0,0 +1,59 @@
---
title: What is an API
---
## What is an API?
API stands for Application Programming Interface. APIs hide complexity from developers, extend systems to partners, organize code, and make components reusable. Dont worry about the AP, just focus on the I. An API is an interface. You use interfaces all the time. A computer operating system is an interface. Buttons in an elevator are an interface. A gas pedal in a car is an interface.
An interface sits on top of a complicated system and simplifies certain tasks, a middleman that saves you from needing to know all the details of whats happening under the hood. A web API is the same sort of thing. It sits on top of a web service, like Twitter or YouTube, and simplifies certain tasks for you. It translates your actions into the technical details for the computer system on the other end.
If you have ever programmed in an object-oriented language like Java or C++, an API is quite similar to the concept of a class. When we call a method on an object (such as ```.toString()```) we don't really care HOW the object is producing the result, all we care about is the string we get at the end. A call to an API works in the same way. For example, when we make a call to the Facebook API to retrieve a user's profile picture, we don't care about how the information is retrieved from the server. We just make the request to the API, let it handle all the complicated retrieval logic, and get our photo at the end of it all.
## Why Are APIs Useful?
Having access to an API generally means having access to a large amount of organized data. The gatekeeper of that data gives a developer permission (in the form of an *API key*) to query a server for information. If the request is successful, the server responds with a message that may look something like this:
```javascript
{
"coord": {
"lon":139,
"lat":35
},
"wind": {
"speed":7.31,
"deg":187.002
},
"rain": {
"3h":0
},
"clouds": {
"all":92
}
}
```
Source: [Open Weather API](https://openweathermap.org/current)
In the example above, a developer made a request for the current weather at a specific latitude and longitude, and the server responded with a *JSON object* about wind, rain, and clouds for that location. Services that you use every day are made with tons of request and response cycles like this.
<strong>Here are Top 10 APIs for beginners </strong>
<ol>
<li>Dropbox: https://www.dropbox.com/developers</li>
<li>Google Maps: https://developers.google.com/maps/web/</li>
<li>Twitter: https://dev.twitter.com/docs</li>
<li>YouTube: https://developers.google.com/youtube/v3/getting-started</li>
<li>Soundcloud: http://developers.soundcloud.com/docs/api/guide#playing</li>
<li>Stripe: https://stripe.com/docs/tutorials/checkout</li>
<li>Instagram: http://instagram.com/developer/</li>
<li>Twilio: https://www.twilio.com/docs</li>
<li>Yelp: http://www.yelp.com/developers/getting_started</li>
<li>Facebook: https://developers.facebook.com/docs/facebook-login/login-flow-for-web</li>
</ol>
#### More Information:
* [API for non-programmers](https://schoolofdata.org/2013/11/18/web-apis-for-non-programmers/)
* [Wikipedia](https://en.wikipedia.org/wiki/Application_programming_interface)
* [Medium](https://medium.com/girl-geeks/top-10-apis-for-beginners-4d3c43be9386)

View File

@@ -0,0 +1,15 @@
---
title: What is an SDK
---
## What is an SDK
A Software Development Kit (SDK) is a set of tools and libraries that you can use to create applications for a specific software package.
Some SDKs are critical for developing a platform-specific app. For example, the development of an Android app on Java platform requires a Java Development Kit, for iOS apps the iOS SDK, and for Universal Windows Platform the .NET Framework SDK.
There are also SDKs that are installed in apps to provide analytics and data about activity. Prominent examples include Google and Facebook.
It may be something as simple as the implementation of one or more application programming interfaces (APIs) in the form of some libraries to interface to a particular programming language or to include sophisticated hardware that can communicate with a particular embedded system.
Common tools include debugging facilities and other utilities, often presented in an integrated development environment (IDE). SDKs also frequently include sample code and supporting technical notes or other supporting documentation to help clarify points made by the primary reference material.