0% found this document useful (0 votes)
2 views

ملخص

Uploaded by

ga778102165
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

ملخص

Uploaded by

ga778102165
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Alright, let's break down chapter 4, which delves into the divide and conquer

algorithm design paradigm.

Divide and Conquer

The divide and conquer strategy involves dividing a problem into smaller
subproblems that are easier to solve, conquering them recursively, and then
combining the solutions to get the solution for the main problem .

Key steps

* Divide: The problem is divided into smaller subproblems .

* Conquer: The subproblems are solved recursively .

* Combine: The solutions to the subproblems are combined to solve the original
problem.

Examples of divide and conquer algorithms :

* Sorting algorithms: Mergesort, Quicksort

* Binary tree traversals: Preorder, Inorder, Postorder

* Searching: Binary Search

* Multiplication of large integers: Karatsuba algorithm

* Matrix multiplication: Strassen's algorithm

* Closest-pair and convex-hull algorithms

Important concepts:

* Recurrence relations: Used to analyze the efficiency of divide and conquer


algorithms.

* Master theorem: Used to solve common recurrence relations .

* Algorithm analysis: Used to determine the time and space efficiency of divide
and conquer algorithms.

Let me know if you want a deeper dive into any of these algorithms .
Chapter 5: Decrease-and-Conquer

Decrease-and-conquer is a problem-solving technique in computer science


where a problem is solved by :

* Reducing the problem to a smaller instance of the same problem .

* Solving the smaller instance.

* Extending the solution of the smaller instance to obtain the solution to the
original instance.

This approach can be implemented top-down or bottom-up and is also referred


to as the inductive or incremental approach .

Types of Decrease-and-Conquer

There are a few ways to decrease the problem size :

* Decrease by a constant (usually by 1):

* Example: Insertion sort, graph traversal algorithms (DFS and BFS),


topological sorting, algorithms for generating permutations and subsets .

* Decrease by a constant factor (usually by half):

* Example: Binary search, bisection method, exponentiation by squaring,


multiplication à la russe.

* Variable-size decrease:

* Example: Euclid's algorithm, selection by partition, Nim-like games.

Examples of Decrease-and-Conquer Algorithms

* Insertion Sort :

* To sort an array A[0..n-1], sort A[0..n-2] recursively and then insert A[n-1] in its
proper place among the sorted A[0..n-2]. It is usually implemented bottom-up
(non-recursively).

* Graph Traversal Algorithms:

* Depth-first search (DFS): Visits the graph's vertices by always moving away
from the last visited vertex to an unvisited one and backtracks if no adjacent
unvisited vertex is available.
* Breadth-first search (BFS): Visits graph vertices by moving across to all the
neighbors of the last visited vertex .

* Topological Sorting:

* A topological sort of a directed acyclic graph (DAG) is a linear ordering of its


vertices such that for every directed edge (u, v), vertex u comes before vertex v in
the ordering .

* Exponentiation by Squaring:

* The problem of computing a^n where n is a non-negative integer can be


solved by squaring the result of computing a^{n/2} if n is even or squaring the
result of computing a^{(n-1)/2} and multiplying it by a if n is odd .

* Euclid's Algorithm :

* Euclid's algorithm is based on the repeated application of the equality gcd(m,


n) = gcd(n, m \mod n) until the second number becomes 0, which results in the
first number becoming the greatest common divisor .

* Selection Problem:

* The selection problem is the problem of finding the k-th smallest element in a
list of n numbers. A faster algorithm than sorting is based on the quicksort-like
partition of the list .

* Interpolation Search :

* Searches a sorted array similar to binary search but estimates the location of
the search key by using its value. The values of the array's elements are assumed
to grow linearly, and the location of the key is estimated as the x-coordinate of
the point on the straight line through (l, A[l]) and (r, A[r]) whose y-coordinate is
the key's value.
Chapter 6: Transform-and-Conquer

Transform-and-conquer is a problem-solving paradigm in computer science that


involves transforming a problem into a more convenient or simpler form to solve
it efficiently. This technique can be applied in various ways :

* Instance simplification: Transforming a problem's instance to a simpler or


easier instance of the same problem .

* Representation change: Transforming a problem's instance to a different


representation of the same instance .

* Problem reduction: Transforming a problem's instance to a different problem


for which an algorithm is already available.

.1Instance Simplification

This approach involves simplifying the problem instance to make it easier to


solve. One common technique is presorting, where a list is sorted to facilitate
further operations. For example, searching, finding the median, and checking for
distinct elements become easier in a sorted list .

.2Representation Change

Changing the representation of a problem instance can sometimes lead to a


more efficient solution. For example, representing a polynomial in Horner's rule
form allows for faster evaluation.

.3Problem Reduction

This technique involves transforming a problem into a different problem for


which an algorithm is already known. The efficiency of this approach depends on
the transformation and solution time being less than solving the original problem
directly. Examples include:

* Computing the least common multiple (LCM) using the greatest common
divisor (GCD).

* Finding the number of paths of length n in a graph by raising the adjacency


matrix to the nth power .

* Transforming maximization problems to minimization problems and vice


versa.

Specific Examples
* Gaussian elimination: A method for solving systems of linear equations by
transforming the system into an upper-triangular form, which is then solved by
back-substitution.

* AVL trees: Self-balancing binary search trees that maintain a balance factor for
each node to ensure logarithmic search, insertion, and deletion times .

* Heaps and heapsort: A heap is a binary tree-based data structure that satisfies
the heap property. Heapsort is a sorting algorithm that uses a heap to achieve
efficient sorting.

* Horner's rule: An efficient way to evaluate polynomials by reducing the


number of multiplications required .

Key Points

* Transform-and-conquer is a versatile technique that can be applied to various


problems.

* Presorting, representation change, and problem reduction are common


approaches in transform-and-conquer .

* Choosing the appropriate transformation is crucial for the efficiency of this


technique.

* Many standard algorithms and data structures utilize the transform-and-


conquer paradigm.

Understanding transform-and-conquer expands your problem-solving toolkit


and opens up efficient solutions for a wide range of problems .

You might also like