Download as pdf or txt
Download as pdf or txt
You are on page 1of 20

DISCRETE MATHS (SC 205) PROJECT

GROUP MEMBERS:
Ajay Chovatiya (202201203)
Darshan Gami (202201205)
Harsh Rathod (202201212)

INSTRUCTORS:
Prof.Manish Gupta
Prof.Manoj Raut
Prof.Prosenjit Kundu

1
INDEX

1. Introduction 3

2. Problem Statement 5

3. Solution Using DAC Algorithm 6

4. Use Of These Algorithms 8

5. Mathematical Aspects of these Algorithms 12

6. C++ Code Convex Hull For Algorithm 14

7. Conclusion 19

8. Bibliography 20

2
INTRODUCTION

The ”Divide and Conquer” algorithm design concept is indeed a funda-


mental strategy employed by mathematicians and computer scientists to
solve complex problems. While it is not credited to a specific person, the
concept has been used for centuries, and its roots can be traced back to
various early mathematicians and researchers.

One prominent example of the Divide and Conquer strategy can be found
in the work of Al-Khwarizmi, a Persian mathematician and philosopher
who lived during the 9th century. Al-Khwarizmi is known for his signifi-
cant contributions to mathematics, particularly in the field of algebra. He
wrote a book titled ”Kitab al-Jabr wa al-Muqabala,” which laid the foun-
dation for modern algebra and introduced systematic methods for solving
equations.paradigm.

In this book, Al-Khwarizmi outlined an algorithmic method known as


”algorism,” which involved decomposing complex problems into smaller,
more manageable subproblems. He described techniques for solving linear
and quadratic equations by dividing them into cases based on the different
possible scenarios and then solving each case individually. This approach
allowed for a systematic and organized method of problem-solving.

Al-Khwarizmi’s work had a significant impact on the development of math-


ematics and computation. The term ”algorithm” is derived from his name,
and it is a testament to his contributions to the field. His method of
breaking down problems into smaller parts, solving them independently,
and then combining the results aligns closely with the Divide and Conquer
strategy.

While Al-Khwarizmi’s work predates the formal recognition of the Divide


and Conquer paradigm and the specific phrase ”Divide and Conquer” by
Jon von Neumann, his contributions laid the groundwork for this algorith-
mic approach. The concept of breaking down problems into manageable
subproblems and solving them separately is at the core of the Divide and
Conquer strategy, and Al-Khwarizmi’s algorism exemplifies this approach.

3
DIVIDE AND CONQUER ALGORITHM

The Divide and Conquer algorithm provides an efficient approach to


solve the Convex Hull problem by dividing it into smaller subproblems
and merging their solutions. The algorithm exploits the properties of con-
vexity to progressively combine convex hulls of subsets of points to obtain
the final convex hull . Divide and conquer algorithm was found by
John Mauchly

John Mauchly, also known as John W. Mauchly was born on August


30, 1907, in Cincinnati, Ohio, United States. After his graduation, he
joined the University of Pennsylvania as an associate professor of electri-
cal engineering and also started a computer company with Eckert named
Eckert-Mauchly computer corporation(EMCC) and pioneered fundamen-
tal computer concepts, including the stored program, subroutines, and
programming languages. He also got IEEE Emanuel R. Piore Awardand
was a life member of the Franklin Institute and the Society of Advance-
ment of Management and was elected fellow of the IRE.

WHAT IS CONVEX HULL:

The Convex Hull is a fundamental concept in computational geome-


try. It represents the smallest convex polygon that encloses a set of points
in a plane. Finding the Convex Hull of a set of points is a common prob-
lem in various fields, including computer graphics, geographic information
systems, and robotics.

4
WHAT IS DIVIDE AND CONQURE ALGORITHM:

The Divide and Conquer algorithm is a fundamental problem-solving


technique used in computer science and mathematics. It involves break-
ing down a complex problem into smaller, more manageable subproblems,
solving them independently, and then combining their solutions to obtain
the final solution to the original problem.

This approach is widely employed to solve a wide range of problems effi-


ciently and effectively. The divide and conquer algorithm has been able
to successfully solve complex problems like the tower of Hanoi and also
some complex mathematical problems. The divide-and-conquer strat-
egy divides a problem into related subproblems, recursively resolves the
related subproblems, and then merges the answers to the original prob-
lems. ”Divide and rule” primarily divided into three parts: Divide the
larger problem first into several smaller instances of the same problem,
or subproblems. Then, by recursively solving the subproblems, you can
defeat them. Solve the subproblems as base cases if they are small enough.
And combine the solutions to the subproblems into the solutions for the
original problem.

PROBLEM STATEMENT

You are given a set of n points in a two-dimensional plane. Your task is


to compute the convex hull of these points, which is the smallest convex
polygon that encloses all the given points.

Design an efficient algorithm that can handle a wide range of input point
distributions and provide a solution with optimal time complexity. The
algorithm should be able to handle edge cases such as collinear points, du-
plicate points, and degenerate cases where the convex hull is a line segment
or a single point.

5
Solution Of Convex HuLL Problem using Divide and
Conquer Algorithm :
Consider a set of points in a two-dimensional plane: (1, 2), (3, 5), (4, 3),
(2, 7), (6, 1), (5, 4),(3,1),(2,4). We’ll use the Divide and Conquer Convex
Hull algorithm to find the convex hull of these points.

Divide: We divide the set of points into two subsets along a horizontal
line. Let’s say we divide the points into (1, 2), (3, 1), (6,1) and (2, 7), (4,
3), (5, 4),(3,5),(2,4).

Conquer: We recursively compute the convex hull of each subset. For the
first subset, the convex hull is (1, 2), (3, 1), (6,1). For the second subset,
the convex hull is (2, 7),(5,4)).

6
Merge: To merge the convex hulls, we find the upper tangent and lower
tangent points, which are the points where the two convex hulls touch each
other. In this case, The merged convex hull becomes (1, 2), (6, 1), (2, 7),
(5, 4),(3,1).

Visually, the merged convex hull represents the smallest convex polygon
that encloses all the given points. In our example, the convex hull is a

7
pentagon connecting the outermost points (1, 2),(6, 1), (2, 7), (5, 4),(3,1).
The divide and conquer approach in computing the convex hull reduces
the time complexity to O(n log n), where n is the number of input points.
This algorithm efficiently solves the convex hull problem and is widely used
in practice.

USE OF THESE ALGORITHMS

Divide and conqure algorithms, which find the smallest convex polygon
that encloses a set of points, have several real-life applications in various
fields. Here are some examples:

1. Logistics and Supply Chain Management: Divide and conquer algo-


rithms can be applied to optimize routing and scheduling problems in
logistics and supply chain management. By dividing large transportation
networks into smaller subnetworks and solving them independently, effi-
cient routes and schedules can be computed for the entire system.

2. Financial Investments: When managing a diverse investment portfo-


lio, divide and conquer algorithms can be used to analyze and optimize
the allocation of investments across different sectors or asset classes. By
breaking down the portfolio into smaller subsets and applying specific in-
vestment strategies to each subset, overall returns can be maximized while
minimizing risk.

8
3. Event Organization :Divide Conqure Algorithm can be Used to in
Event Organization.Big Events Like Olympic,World Cup,etc.. have many
participants and Events So first we can devide whole Event in small task
after we can use conqure method Because it is useful for making team for
each task. so We give task to all team and finally we combine/merge them
so our event is now organizable very easily and quickly.

4. Manufacturing Production : Divide and conquer algorithms find


applications in manufacturing and production processes. For example, in
production line optimization, the problem of optimizing the flow of mate-
rials and resources across different stages of production can be solved using
divide and conquer techniques to identify bottlenecks, allocate resources
efficiently, and improve overall productivity.

9
5. Project Management: Divide and conquer algorithms can be utilized
in project management for task allocation, scheduling, and resource op-
timization. By dividing large projects into smaller subprojects or tasks,
project managers can assign responsibilities, set deadlines, and manage
resources more effectively.

These are just a few examples highlighting the practical applications


of convex hull algorithms in real-life scenarios. The ability to determine
the convex boundary of a set of points efficiently makes them valuable
tools in various fields where shape analysis, boundary detection, or spatial
relationships are important.

10
MATHEMATICAL ASPECTS OF THESE
ALGORITHMS IN OUR PROJECT

Problem: Organizing a large-scale event with multiple activities


and participants.

Solution using Divide and Conquer:


1. Divide: Divide the event planning process into smaller tasks and sub-
tasks.
2. Conquer: Allocate responsibility for each task or subtask to different
teams or individuals.
3. Combine: Bring together the contributions from each team or individ-
ual to create a cohesive and successful event.

Example:
Let’s consider organizing a music festival with multiple stages, perfor-
mances, and logistical arrangements.

1. Divide:
Divide the event planning process into smaller tasks and subtasks:
- Stage setup and equipment arrangement
- Artist booking and scheduling
- Ticketing and registration
- Security and crowd management
- Food and beverage arrangements
- Marketing and promotion
11
2. Conquer:
Allocate responsibility for each task or subtask to different teams
or individuals:
- Stage setup and equipment arrangement: Assign a team of tech-
nicians and stage managers.
- Artist booking and scheduling: Appoint a team or individual
responsible for contacting and managing artists’ schedules.
- Ticketing and registration: Assign a team to handle ticket sales
and registration processes.
- Security and crowd management: Hire a professional security
team or work with a security agency.
- Food and beverage arrangements: Coordinate with vendors and
caterers to provide food and beverage services.
- Marketing and promotion: Assign a team or individual to handle
advertising, social media campaigns, and promotion efforts.

3. Combine:
Bring together the contributions from each team or individual to
create a cohesive and successful event:
- Coordinate with the stage setup team to ensure the stages are
prepared and equipped for performances.
- Collaborate with the artist management team to finalize the
lineup and schedule performances.
- Work with the ticketing team to manage ticket sales and entry
to the event.
- Coordinate with the security team to ensure the safety of atten-
dees and manage crowd control.
- Collaborate with food and beverage vendors to provide refresh-
ments and dining options.
- Work with the marketing team to promote the event and attract
attendees.

By dividing the event planning process into smaller tasks and assigning
responsibility for each task, the event organizers can efficiently manage
various aspects of the music festival. The contributions from each team or
individual are combined to create a successful and well-organized event.

12
By using divide and conqure algorithm our task’s / code’s worst case
time complexity is O(nlogn).Brute force time complexity is O(n2 ) . This
algorithm is better than brute force that’s why we preferred to use this
algorithm.

C++ CODE CONVEX HULL FOR ALGORITHM


#include<bits/stdc++.h>
using namespace std;

pair<int, int> mid;

int quad(pair<int, int> p)


{
if (p.first >= 0 && p.second >= 0)
return 1;
if (p.first <= 0 && p.second >= 0)
return 2;
if (p.first <= 0 && p.second <= 0)
return 3;
return 4;
}

int orientation(pair<int, int> a, pair<int, int> b, pair<int, int> c)


{

13
int res = (b.second-a.second)*(c.first-b.first) -
(c.second-b.second)*(b.first-a.first);

if (res == 0)
return 0;
if (res > 0)
return 1;
return -1;
}

bool compare(pair<int, int> p1, pair<int, int> q1)


{
pair<int, int> p = make_pair(p1.first - mid.first, p1.second -
mid.second);

pair<int, int> q = make_pair(q1.first - mid.first, q1.second -


mid.second);

int one = quad(p);


int two = quad(q);

if (one != two)
return (one < two);
return (p.second * q.first < q.second * p.first);
}

vector<pair<int, int>> merger(vector<pair<int, int>> a,


vector<pair<int, int>> b)
{
int n1 = a.size(), n2 = b.size();

int ia = 0, ib = 0;
for (int i = 1; i < n1; i++)
if (a[i].first > a[ia].first)
ia = i;

for (int i = 1; i < n2; i++)


if (b[i].first < b[ib].first)
ib = i;

14
int inda = ia, indb = ib;
bool done = 0;
while (!done)
{
done = 1;
while (orientation(b[indb], a[inda], a[(inda+1)%n1]) >= 0)
inda = (inda + 1) % n1;

while (orientation(a[inda], b[indb], b[(n2+indb-1)%n2]) <= 0)


{
indb = (n2+indb-1)%n2;
done = 0;
}
}

int uppera = inda, upperb = indb;


inda = ia, indb = ib;
done = 0;
int g = 0;
while (!done)
{
done = 1;
while (orientation(a[inda], b[indb], b[(indb+1)%n2]) >= 0)
indb = (indb+1)%n2;

while (orientation(b[indb], a[inda], a[(n1+inda-1)%n1]) <= 0)


{
inda = (n1+inda-1)%n1;
done = 0;
}
}

int lowera = inda, lowerb = indb;


vector<pair<int, int>> ret;

int ind = uppera;


ret.push_back(a[uppera]);
while (ind != lowera)

15
{
ind = (ind+1)%n1;
ret.push_back(a[ind]);
}

ind = lowerb;
ret.push_back(b[lowerb]);
while (ind != upperb)
{
ind = (ind+1)%n2;
ret.push_back(b[ind]);
}
return ret;
}

vector<pair<int, int>> bruteHull(vector<pair<int, int>> a)


{
set<pair<int, int>> s;

for (int i = 0; i < a.size(); i++)


{
for (int j = i + 1; j < a.size(); j++)
{
int x1 = a[i].first, x2 = a[j].first;
int y1 = a[i].second, y2 = a[j].second;

int a1 = y1 - y2;
int b1 = x2 - x1;
int c1 = x1 * y2 - y1 * x2;
int pos = 0, neg = 0;
for (int k = 0; k < a.size(); k++)
{
if (a1 * a[k].first + b1 * a[k].second + c1 <= 0)
neg++;
if (a1 * a[k].first + b1 * a[k].second + c1 >= 0)
pos++;
}
if (pos == a.size() || neg == a.size())
{

16
s.insert(a[i]);
s.insert(a[j]);
}
}
}

vector<pair<int, int>> ret;


for (auto e : s)
ret.push_back(e);

mid = {0, 0};


int n = ret.size();
for (int i = 0; i < n; i++)
{
mid.first += ret[i].first;
mid.second += ret[i].second;
ret[i].first *= n;
ret[i].second *= n;
}
sort(ret.begin(), ret.end(), compare);
for (int i = 0; i < n; i++)
ret[i] = make_pair(ret[i].first / n, ret[i].second / n);

return ret;
}

vector<pair<int, int>> divide(vector<pair<int, int>> a)


{
if (a.size() <= 5)
return bruteHull(a);

vector<pair<int, int>> left, right;


for (int i = 0; i < a.size() / 2; i++)
left.push_back(a[i]);
for (int i = a.size() / 2; i < a.size(); i++)
right.push_back(a[i]);

vector<pair<int, int>> left_hull = divide(left);


vector<pair<int, int>> right_hull = divide(right);

17
return merger(left_hull, right_hull);
}

int main()
{
vector<pair<int, int>> a;
a.push_back(make_pair(1, 3));
a.push_back(make_pair(2, 7));
a.push_back(make_pair(3, 5));
a.push_back(make_pair(6, 1));
a.push_back(make_pair(4, 3));
a.push_back(make_pair(5, 4));

int n = a.size();

sort(a.begin(), a.end());
vector<pair<int, int>> ans = divide(a);

cout << "Convex hull:\n";


for (auto e : ans)
cout << e.first << " " << e.second << endl;

return 0;
}

CONCLUSION
This project was an exhilarating expedition for all of us. It served as a
compelling illustration of how intricate challenges can be adeptly tackled
through fundamental mathematical principles. Furthermore, we came to
the realization that the practical application of Discrete Mathematics ex-
tends well beyond the confines of academia, permeating various facets of
our daily lives and exerting influence on numerous aspects of our existence.

The divide and conquer algorithm stands as a formidable strategy for


problem-solving, possessing the capacity to efficiently and effectively ad-

18
dress a diverse array of complex problems. By disassembling a sizable
problem into smaller, manageable subproblems, this algorithm harnesses
the power of parallel processing and minimizes computation time. While
certain limitations exist, it remains an adaptable tool for resolving a broad
spectrum of quandaries in fields such as computer science, mathematics,
and engineering.

BIBLIOGRAPHY

—REFERENCES—

https://www.geeksforgeeks.org/
convex-hull-using-graham-scan/

https://en.wikipedia.org/wiki/Divide-and-conquer_
algorithm

https://www.careerguide.com/career/wp-content/
uploads/2020/01/event-management-bg.jpg

19
https://images.shiksha.com/mediadata/images/
articles/1583747992phpzaxKKK.jpeg

https:
//upload.wikimedia.org/wikipedia/commons/thumb/5/
57/Tesla_auto_bots.jpg/330px-Tesla_auto_bots.jpg

https://shorturl.at/esyzG

https://shorturl.at/cfzB5

-: THANK YOU :-

20

You might also like