Skip to content

[Feature]: Add Greedy Algorithm in the src-algorithms #738

Description

@Riya010107

Problem or limitation

Greedy is used when:

-Problem has optimal substructure
-Problem has greedy choice property
-Local best choice leads to global best solution

Proposed solution

Greedy algorithms are used to solve optimization problems where:

  • We want the maximum or minimum result
  • We make decisions step by step
  • At each step, we choose the best possible option right now (locally optimal choice)

Alternatives considered

No response

Use case

🧩Problem:

You are given multiple activities with start and end times.
You must select the maximum number of non-overlapping activities.

🎯 Goal:

Maximize number of activities without conflict.

💡 Greedy Idea (Proposed Solution):
Always pick the activity that finishes earliest
This leaves maximum time for remaining activities
Sort activities by end time
Select next activity only if it starts after last selected activity ends

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    GSSoCOfficial issue for GSSoC contributors

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions