## The Mastery of Computer Programming: Primary Algorithms - Sykalo Eugene 2023

# Mathematical Background

Introduction to Algorithms

## Number theory and its applications in cryptography

Number theory is a branch of mathematics that deals with the properties of integers. It has numerous applications in cryptography, which is the practice of secure communication in the presence of third parties.

One of the most well-known applications of number theory in cryptography is the RSA algorithm. The RSA algorithm relies on the fact that it is relatively easy to multiply two large prime numbers together, but extremely difficult to factor the product into its constituent primes. The algorithm uses this property to create a public and private key pair that can be used to encrypt and decrypt messages.

Another application of number theory in cryptography is the Diffie-Hellman key exchange. This algorithm allows two parties to establish a shared secret key over an insecure communication channel. The algorithm relies on the fact that it is computationally difficult to calculate discrete logarithms in a finite field.

Number theory provides a powerful set of tools for ensuring secure communication in the digital age. By leveraging the properties of integers, modern cryptography algorithms can provide strong guarantees of confidentiality and authenticity for sensitive information.

## Set theory and relations

Set theory is a branch of mathematics that deals with sets, which can be thought of as collections of objects. In set theory, the objects in a set are called elements, and the set is denoted by enclosing its elements in curly braces. For example, {1, 2, 3} is a set with elements 1, 2, and 3.

Sets can be manipulated using various mathematical operations. For example, the union of two sets A and B is the set of all elements that are in either A or B, denoted by A ∪ B. The intersection of two sets A and B is the set of all elements that are in both A and B, denoted by A ∩ B. The difference of two sets A and B is the set of all elements that are in A but not in B, denoted by A \ B.

Relations are a way of describing the connections between elements in sets. A relation between two sets A and B is a subset of the Cartesian product of A and B, denoted by A × B. In other words, a relation is a set of ordered pairs (a, b) where a is an element of A and b is an element of B.

Relations can be used to model a wide range of phenomena, from social networks to physical systems. For example, a social network can be represented as a set of individuals, with a relation between two individuals indicating that they are friends or acquaintances. Similarly, a physical system can be represented as a set of objects, with a relation between two objects indicating that they interact or influence each other.

In computer programming, relations are often used to represent data structures such as graphs and trees. For example, a graph can be represented as a set of vertices and a set of edges, where each edge is a relation between two vertices.

Set theory and relations provide a powerful set of tools for describing and manipulating collections of objects, and for modeling the relationships between them. They are fundamental concepts in computer programming and are used in a wide range of applications, from cryptography to machine learning.

## Combinatorics and probability theory

Combinatorics is a branch of mathematics that deals with the study of counting and arranging objects. It is concerned with questions such as "How many different ways can a set of objects be arranged?" and "How many ways can a particular outcome occur in a series of events?" Combinatorics is an important tool in computer programming, as it is used to solve problems related to data organization and retrieval, as well as to optimize algorithms and data structures.

Probability theory is a branch of mathematics that deals with the study of random events. It is concerned with questions such as "What is the likelihood of a particular outcome occurring in a random process?" and "How can we model and analyze the behavior of systems that exhibit random behavior?" Probability theory is used extensively in computer programming, in applications such as statistical analysis, machine learning, and artificial intelligence.

One of the fundamental concepts in combinatorics is the notion of a permutation, which is a way of arranging a set of objects in a particular order. For example, the set {1, 2, 3} can be arranged in six different ways: {1, 2, 3}, {1, 3, 2}, {2, 1, 3}, {2, 3, 1}, {3, 1, 2}, and {3, 2, 1}. The number of permutations of a set with n elements is given by n!, which represents the product of all the integers from 1 to n.

Another important concept in combinatorics is the notion of a combination, which is a way of selecting a subset of objects from a larger set, without regard for their order. For example, if we want to choose two elements from the set {1, 2, 3}, there are three possible combinations: {1, 2}, {1, 3}, and {2, 3}. The number of combinations of k elements from a set with n elements is given by the binomial coefficient (n choose k), which represents the number of ways of selecting k objects from a set of n objects.

Probability theory is concerned with the study of random events and their associated probabilities. A probability is a number between 0 and 1 that represents the likelihood of a particular event occurring. For example, if we flip a fair coin, the probability of it landing heads-up is 0.5.

One of the fundamental concepts in probability theory is the notion of a random variable, which is a variable that takes on different values depending on the outcome of a random event. For example, if we roll a six-sided die, the number that comes up is a random variable with values ranging from 1 to 6.

Another important concept in probability theory is the notion of a probability distribution, which is a function that assigns probabilities to the possible outcomes of a random event. For example, the probability distribution of rolling a six-sided die is given by the function f(x) = 1/6 for x = 1, 2, 3, 4, 5, 6.

In computer programming, combinatorics and probability theory are used in a wide range of applications, from data analysis to machine learning. For example, in machine learning algorithms, combinatorics is used to optimize the performance of neural networks, while probability theory is used to model and analyze the behavior of complex systems. These fields provide powerful tools for analyzing and manipulating data in computer programming, and are essential for the development of advanced applications and algorithms.

## Graph theory and its algorithms

Graph theory is a branch of mathematics that deals with the study of graphs, which are mathematical structures used to model pairwise relations between objects. A graph consists of a set of vertices, which represent the objects, and a set of edges, which represent the pairwise relations between the objects. Graphs are used extensively in computer programming, in applications such as network routing, data analysis, and machine learning.

One of the most basic algorithms in graph theory is the depth-first search algorithm, which is used to traverse a graph and visit all of its vertices. The algorithm works by starting at a given vertex and recursively visiting all of its neighbors, then visiting the neighbors of its neighbors, and so on, until all of the vertices in the graph have been visited. Depth-first search can be used to find paths between vertices, to detect cycles in a graph, and to determine if a graph is connected.

Another important algorithm in graph theory is Dijkstra's algorithm, which is used to find the shortest path between two vertices in a weighted graph. The algorithm works by maintaining a set of visited vertices and a set of unvisited vertices, and by assigning a tentative distance to each vertex that represents the shortest distance from the start vertex to that vertex. The algorithm then iteratively selects the unvisited vertex with the smallest tentative distance and updates the tentative distances of its neighbors. Dijkstra's algorithm can be used to find the shortest path between any two vertices in a graph, and is widely used in network routing and optimization.

A third important algorithm in graph theory is the minimum spanning tree algorithm, which is used to find the tree that spans all of the vertices in a connected, undirected graph and has the minimum total weight. The algorithm works by starting with a single vertex and iteratively adding the edge with the smallest weight that connects that vertex to a vertex that is not already in the tree. The algorithm terminates when all of the vertices in the graph have been added to the tree. The minimum spanning tree algorithm can be used to find the optimal way to connect a network of nodes, and is used in applications such as data clustering and image segmentation.

In addition to these basic algorithms, there are many other important algorithms in graph theory, such as the Bellman-Ford algorithm, the Floyd-Warshall algorithm, and the A* algorithm. Each of these algorithms is designed to solve a specific problem in graph theory, and is used in a wide range of applications in computer programming.

Graph theory and its algorithms provide powerful tools for modeling and analyzing pairwise relationships between objects. They are essential in a wide range of applications in computer programming, from network routing to machine learning, and are fundamental concepts that every programmer should understand.