Watch the greedy choice pick the activity that ends first, then the next one that fits after it. Worked example with eight activities, A to H, in O(n log n).
About this algorithm
Activity selection picks the largest number of activities that do not overlap in time, given each one's start and finish. One room, one person or one machine can only do one thing at a time. The greedy rule is to keep choosing the compatible activity that finishes earliest, because that leaves the most time for everything after it.
Use it to fit as many fixed-time events as possible into one resource: meetings into one room, talks a single attendee can go to, jobs on one machine with fixed slots. It counts activities and treats them all as equally worth having. If activities carry different values, the problem is weighted interval scheduling, which needs dynamic programming. If you must schedule every meeting and want the fewest rooms, that is the meeting rooms problem, solved with a min-heap of end times. Job sequencing is the variant where tasks have deadlines and profits rather than fixed times.
Order the activities so the one that ends first comes first.
The earliest-finishing activity is always part of some best answer, so select it and record its finish time as lastFinish.
Walk down the sorted list. An activity whose start is at least lastFinish does not clash with anything chosen, so select it and set lastFinish to its finish. One that starts earlier overlaps, so skip it. This page treats an activity starting exactly when the last one ends as no clash.
The activities you selected are a largest possible set of non-overlapping ones.
The page loads A (1 to 4), B (3 to 5), C (0 to 6), D (5 to 7), E (3 to 9), F (5 to 9), G (6 to 10) and H (8 to 11), already in finish order. Select A, so lastFinish is 4. B starts at 3 and C at 0, both before 4, so skip them. D starts at 5, so select it and lastFinish becomes 7. E starts at 3, F at 5 and G at 6, all before 7, so skip them. H starts at 8, so select it. The answer is A, D, H: three activities, and no set of four exists here.
Picking by earliest start fails on this same input: it takes C (0 to 6) first, which blocks A, B, D, E and F, then takes G, and ends with only two activities. Picking the shortest activity also fails in general: one short activity can sit across the boundary of two longer ones and block both.
Time: the sort costs n log n and the selection pass looks at each activity once. Space: the page sorts a copy of the activities, which is the O(n); the pass itself keeps only lastFinish and the count of chosen activities, so sorting in place would bring it down to O(1) extra.