TPA Project
TPA Project
TD-TP Control
By:
FATAH Maroua
FERHI Asmaa
Dr. C. M. BENTAOUZA
2021 / 2022
The first work
This chapter of this book presents how to design algorithms according to a sequence of
questions to guide your search for the right algorithm for your problem.
Designing the right algorithm for a given application is a major creative act—that of taking a problem and
pulling a solution out of the ether. And the key to algorithm design is to proceed by asking yourself
questions to guide your thought process. What if we do this? What if we do that?
Obviously, the more experience you have with algorithm design techniques such as dynamic
programming, graph algorithms, intractability, and data structures, the more successful you will be at
working through the list of questions:
1. Do I really understand the problem?
2. Can I find a simple algorithm or heuristic for my problem?
3. Can I find my problem in a catalog of a programming book?
4. Are there special cases of the problem that I know how to solve?
5. Which of the standard algorithm design paradigms are most relevant to my problem?
6. Am I still stumped?
Problem-solving is not a science, but part art and part skill. It is one of the skills most worth developing.
The distinction between strategy and tactics is important to keep aware of during any design process.
« Introduction to Algorithms Third Edition »
Advanced Design and Analysis Techniques
Dynamic Programming
This part covers one of the three important techniques used in designing and analyzing efficient
algorithms: dynamic programming.
Dynamic programming typically applies to optimization problems in which we make a set of choices in
order to arrive at an optimal solution, and it is effective when a given subproblem may arise from more
than one partial set of choices, the key technique is to store the solution to each such subproblem in case
it should reappear.
Dynamic programming, like the divide-and-conquer method, solves problems by combining the solutions
to subproblems. And the dynamic-programming algorithms solve each sub subproblem just once and
then saves its answer in a table, thereby avoiding the work of recomputing the answer every time it
solves each sub subproblem.
When developing a dynamic-programming algorithm, we follow a sequence of four steps:
1. Characterize the structure of an optimal solution.
2. Recursively define the value of an optimal solution.
3. Compute the value of an optimal solution, typically in a bottom-up fashion.
4. Construct an optimal solution from computed information.
Steps 1,2,3 form the basis of a dynamic-programming solution to a problem.
This chapter presents an algorithmic model for parallel computing based on dynamic
multithreading, and introduces the basics of the model, showing how to quantify parallelism in
terms of the measures of work and span.
One important class of concurrency platform is dynamic multithreading, which is the model adopted in
this chapter.
Dynamic multithreading allows programmers to specify parallelism in applications without worrying about
communication protocols, load balancing, and other vagaries of static-thread programming. Although the
functionality of dynamic-multithreading environments is still evolving, almost all support two features:
nested parallelism and parallel loops.
• In mathematics, The Chinese remainder is a theorem that awards a unique solution for the linear
simultaneous congruence with the coprime moduli. In the basic form, this theorem determines a number X
that when divided by some given divisors, leave the remainders, provided that the divisors must be a
pairwise coprime.
• It knows by the Chinese mathematician Sun-Tzu in the 3rd century.
• The theorem is expressing in modern general terms using congruence notation. Let m 1, m2, …, mk be
integers that are greater than one and pairwise relatively prime (that is, the only common factor between
any two of them is 1), and let a1, a2, …, ak be any integers. Then there exists an integer solution a such
that x ≡ ai (mod mi) for each i = 1, 2, …, k. Furthermore, for any other integer b that satisfies all the
congruences, b ≡ a (mod M) where M = m1m2⋯mk :
X ≡ a1 (mod m1)
X ≡ a2 (mod m2)
…
…
…
X ≡ an (mod mn)
M = m1m2⋯mk
- The general construction to find the solution of congruences system using the Chinese remainder
theorem:
- Compute :
M = m1m2⋯mk
- For each i = 1, 2…, k, compute:
using Euclid's extended algorithm (zi exists since m1, m2, …, mk are pairwise coprime).
- The integer
X = [Equation]ai yi zi
is a solution to the system of congruences, and x mod M is the unique solution modulo M.