# Greedy Technique to Resolve problems

The greedy technique is a problem-solving approach in Data Structures and Algorithms (DSA) where the optimal choice is made at each step with the hope of finding a global optimum solution. It works by always choosing the best immediate or local option, without worrying about the future consequences.The greedy technique is suitable for problems that exhibit the following properties:

**Greedy Choice Property**: The optimal solution can be constructed by making the best local choice at each step.**Optimal Substructure**: The optimal solution to the problem contains the optimal solutions to its subproblems.Let's consider the Activity Selection Problem, which is a classic example of a greedy algorithm

Given a set of activities, each with a start time and an end time, the goal is to select the maximum number of non-overlapping activities.

Here's how we can solve this problem using the greedy technique in Go:

`package main import ( "fmt" "sort" ) type activity struct { start int end int } func main() { activities := []activity{ {1, 3}, {2, 4}, {3, 5}, {3, 8}, {4, 6}, {5, 7}, {6, 9}, } selectedActivities := activitySelection(activities) fmt.Println("Selected Activities:") for _, act := range selectedActivities { fmt.Printf("Start: %d, End: %d\n", act.start, act.end) } } func activitySelection(activities []activity) []activity { sort.Slice(activities, func(i, j int) bool { return activities[i].end < activities[j].end }) selectedActivities := []activity{activities[0]} prevEnd := activities[0].end for i := 1; i < len(activities); i++ { if activities[i].start >= prevEnd { selectedActivities = append(selectedActivities, activities[i]) prevEnd = activities[i].end } } return selectedActivities }`