top of page
Inaugurated by IN-SPACe
ISRO Registered Space Tutor

S0-SA3-0658

What is Sorting by Two Properties?

Grade Level:

Class 2

Logic, Computing, AI, Data Science, Maths

Definition
What is it?

Sorting by Two Properties means arranging items based on two different characteristics, one after the other. First, you sort by the main characteristic, and then, for items that are the same in the main characteristic, you sort them further by the second characteristic.

Simple Example
Quick Example

Imagine you have many cricket players and want to arrange them. First, you might sort them by their 'Team Name' (Property 1). Then, within each team, you might sort the players by their 'Runs Scored' (Property 2), from highest to lowest. This way, you can quickly find the top scorer in each team.

Worked Example
Step-by-Step

Let's sort a list of students based on their 'Class' (Property 1) and then by 'Marks in Maths' (Property 2, highest to lowest).

Students: (Rohan, Class 5, 85 Marks), (Priya, Class 6, 92 Marks), (Amit, Class 5, 90 Marks), (Sara, Class 6, 88 Marks), (Deepak, Class 5, 78 Marks)

Step 1: Sort by Class (Property 1) in ascending order (Class 5 first, then Class 6).
Class 5 Students: (Rohan, 85), (Amit, 90), (Deepak, 78)
Class 6 Students: (Priya, 92), (Sara, 88)

---

Step 2: Within Class 5, sort by Marks in Maths (Property 2) from highest to lowest.
(Amit, Class 5, 90 Marks)
(Rohan, Class 5, 85 Marks)
(Deepak, Class 5, 78 Marks)

---

Step 3: Within Class 6, sort by Marks in Maths (Property 2) from highest to lowest.
(Priya, Class 6, 92 Marks)
(Sara, Class 6, 88 Marks)

---

Final Sorted List:
1. (Amit, Class 5, 90 Marks)
2. (Rohan, Class 5, 85 Marks)
3. (Deepak, Class 5, 78 Marks)
4. (Priya, Class 6, 92 Marks)
5. (Sara, Class 6, 88 Marks)

Why It Matters

This concept is fundamental in Logic, Computing, and Data Science. It helps us organise large amounts of information efficiently, making it easier to find what we need. Data Analysts and Software Engineers use this every day to make sense of complex data, like arranging products on an e-commerce site or managing a school's student records.

Common Mistakes

MISTAKE: Sorting all items by Property 1, then sorting all items again by Property 2, without keeping the first sort intact. | CORRECTION: First, sort everything by Property 1. Then, for groups of items that have the same Property 1 value, sort ONLY those groups by Property 2.

MISTAKE: Mixing up the order of properties (e.g., sorting by Property 2 first, then Property 1, when the question specifies Property 1 first). | CORRECTION: Always follow the specified order of properties. The 'first' property is the primary sort, and the 'second' is the secondary sort.

MISTAKE: Not understanding what 'ascending' or 'descending' means for each property. | CORRECTION: Pay close attention to whether each property needs to be sorted from smallest to largest (ascending) or largest to smallest (descending).

Practice Questions
Try It Yourself

QUESTION: Sort these fruits by 'Color' (Property 1, alphabetically) then by 'Weight' (Property 2, lightest to heaviest):
(Apple, Red, 150g), (Banana, Yellow, 120g), (Cherry, Red, 10g), (Mango, Yellow, 200g)
| ANSWER:
1. (Apple, Red, 150g)
2. (Cherry, Red, 10g)
3. (Banana, Yellow, 120g)
4. (Mango, Yellow, 200g)

QUESTION: Arrange these auto-rickshaw trips by 'Driver Rating' (Property 1, highest to lowest) and then by 'Distance' (Property 2, shortest to longest):
(Trip A, Rating 4.5, 10km), (Trip B, Rating 4.0, 8km), (Trip C, Rating 4.5, 12km), (Trip D, Rating 4.0, 5km)
| ANSWER:
1. (Trip A, Rating 4.5, 10km)
2. (Trip C, Rating 4.5, 12km)
3. (Trip D, Rating 4.0, 5km)
4. (Trip B, Rating 4.0, 8km)

QUESTION: You have a list of students with their 'City' and 'Age'. Sort them first by 'City' (Property 1, alphabetically) and then by 'Age' (Property 2, youngest to oldest).
(Mumbai, 12), (Delhi, 11), (Mumbai, 10), (Delhi, 13), (Chennai, 12), (Mumbai, 11)
| ANSWER:
1. (Chennai, 12)
2. (Delhi, 11)
3. (Delhi, 13)
4. (Mumbai, 10)
5. (Mumbai, 11)
6. (Mumbai, 12)

MCQ
Quick Quiz

Which of these shows sorting by two properties: 'School' (Property 1) then 'Class' (Property 2)?

All students from Class 5, then all students from Class 6, regardless of school.

All students from DPS, then within DPS, students sorted by Class; then all students from DAV, then within DAV, students sorted by Class.

All students from DPS, then all students from DAV, then all students from Class 5, then all students from Class 6.

All students from Class 5 of DPS, then all students from Class 6 of DAV.

The Correct Answer Is:

B

Option B correctly demonstrates sorting by two properties. It first sorts by 'School' (DPS then DAV) and then, for students within each school, it sorts by 'Class'. Other options either don't use both properties correctly or don't maintain the nested sorting.

Real World Connection
In the Real World

When you search for a movie on a streaming app like Hotstar or Amazon Prime Video, you might first sort by 'Genre' (e.g., Action, Comedy) and then, within that genre, sort by 'Release Year' (newest first) or 'IMDb Rating' (highest first). This helps you find the perfect movie quickly. Even when booking train tickets on IRCTC, you might sort by 'Departure Time' and then by 'Fare' within similar times.

Key Vocabulary
Key Terms

SORTING: Arranging items in a specific order | PROPERTY: A characteristic or feature of an item | PRIMARY SORT: The first, main characteristic used for sorting | SECONDARY SORT: The second characteristic used to sort items that have the same primary sort value | ASCENDING: From smallest to largest (A-Z, 1-10) | DESCENDING: From largest to smallest (Z-A, 10-1)

What's Next
What to Learn Next

Great job understanding sorting by two properties! Next, you can explore 'Sorting Algorithms' like Bubble Sort or Merge Sort. These algorithms are the actual steps computers use to perform these kinds of sorting tasks, building directly on what you've learned here.

bottom of page