Skip to content

Commit

Permalink
Merge pull request #3050 from apmit2704/master
Browse files Browse the repository at this point in the history
Update readme.md
  • Loading branch information
ZoranPandovski authored Nov 26, 2022
2 parents c8e50a3 + 03252db commit 79943aa
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 3 deletions.
3 changes: 3 additions & 0 deletions cryptography/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
![image](https://user-images.githubusercontent.com/57450747/138556646-e8859ee7-014a-46f2-9825-fe0a9a837ee4.png)
## Cryptography
__Cryptography__ is about constructing and analyzing protocols that prevent third parties or the public from reading private messages.



Modern cryptography is heavily based on mathematical theory and computer science practice; cryptographic algorithms are designed around computational hardness assumptions, making such algorithms hard to break in practice by any adversary. It is theoretically possible to break such a system, but it is infeasible to do so by any known practical means.

Algorithms are considered secure if an attacker cannot determine any properties of the plaintext or key, given the ciphertext. An attacker should not be able to determine anything about a key given a large number of plaintext/ciphertext combinations which used the key.
Expand Down
67 changes: 67 additions & 0 deletions dynamic_programing/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Dynamic Programming

The core idea of Dynamic Programming is to avoid repeated work by remembering partial results and this concept finds it application in a lot of real life situations.

In programming, Dynamic Programming is a powerful technique that allows one to solve different types of problems in time O(n2) or O(n3) for which a naive approach would take exponential time.

**Dynamic Programming and Recursion:**

Dynamic programming is basically, recursion plus using common sense. What it means is that recursion allows you to express the value of a function in terms of other values of that function. Where the common sense tells you that if you implement your function in a way that the recursive calls are done in advance, and stored for easy access, it will make your program faster. This is what we call Memoization - it is memorizing the results of some specific states, which can then be later accessed to solve other sub-problems.

The intuition behind dynamic programming is that we trade space for time, i.e. to say that instead of calculating all the states taking a lot of time but no space, we take up space to store the results of all the sub-problems to save time later.

Let's try to understand this by taking an example of Fibonacci numbers.

Fibonacci (n) = 1; if n = 0
Fibonacci (n) = 1; if n = 1
Fibonacci (n) = Fibonacci(n-1) + Fibonacci(n-2)

So, the first few numbers in this series will be: 1, 1, 2, 3, 5, 8, 13, 21... and so on!

A code for it using pure recursion:

```c
int fib (int n) {
if (n < 2)
return 1;
return fib(n-1) + fib(n-2);
}
```
Using Dynamic Programming approach with memoization:
```c
void fib () {
fibresult[0] = 1;
fibresult[1] = 1;
for (int i = 2; i<n; i++)
fibresult[i] = fibresult[i-1] + fibresult[i-2];
}
```
Are we using a different recurrence relation in the two codes? No. Are we doing anything different in the two codes? Yes. In the recursive code, a lot of values are being recalculated multiple times. We could do good with calculating each unique quantity only once.

**Majority of the Dynamic Programming problems can be categorized into two types:**

1. Optimization problems.
2. Combinatorial problems.

The optimization problems expect you to select a feasible solution, so that the value of the required function is minimized or maximized. Combinatorial problems expect you to figure out the number of ways to do something, or the probability of some event happening.

Every Dynamic Programming problem has a schema to be followed:

Show that the problem can be broken down into optimal sub-problems.
Recursively define the value of the solution by expressing it in terms of optimal solutions for smaller sub-problems.
Compute the value of the optimal solution in bottom-up fashion.
Construct an optimal solution from the computed information.
Bottom up vs. Top Down:

-> Bottom Up - I'm going to learn programming. Then, I will start practicing. Then, I will start taking part in contests. Then, I'll practice even more and try to improve. After working hard like crazy, I'll be an amazing coder.

-> Top Down - I will be an amazing coder. How? I will work hard like crazy. How? I'll practice more and try to improve. How? I'll start taking part in contests. Then? I'll practicing. How? I'm going to learn programming.

Not a great example, but I hope I got my point across. In Top Down, you start building the big solution right away by explaining how you build it from smaller solutions. In Bottom Up, you start with the small solutions and then build up.

Memoization is very easy to code and might be your first line of approach for a while. Though, with dynamic programming, you don't risk blowing stack space, you end up with lots of liberty of when you can throw calculations away. The downside is that you have to come up with an ordering of a solution which works.

One can think of dynamic programming as a table-filling algorithm: you know the calculations you have to do, so you pick the best order to do them in and ignore the ones you don't have to fill in.

Article taken from https://www.hackerearth.com/practice/algorithms/dynamic-programming/introduction-to-dynamic-programming-1/tutorial/
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@

#### Definition-

Pointers are variables that store the address of another variable.
Pointers are variables that store the address of another variable.

![Image](http://blog.ashutoshdwivedi.in/tutorials/pointers/introduction%20to%20pointers/1.png)
![Image](http://blog.ashutoshdwivedi.in/tutorials/pointers/introduction%20to%20pointers/2.png)
![image](https://user-images.githubusercontent.com/57450747/138556486-8c12421f-7020-45b9-a3fd-5c3bbdd9dd53.png)


<!-- ![Image](http://blog.ashutoshdwivedi.in/tutorials/pointers/introduction%20to%20pointers/1.png)
![Image](http://blog.ashutoshdwivedi.in/tutorials/pointers/introduction%20to%20pointers/2.png) -->



Expand Down

0 comments on commit 79943aa

Please # to comment.