Class 12 Notes Computer Science Chap 5 (2024-25)
Class 12 Notes Computer Science Chap 5 (2024-25)
CLASS 12TH
SUBJECT – COMPUTER SCIENCE
CHAPTER – 5 SORTING
Introduction to Sorting:
• Sorting is the process of arranging data in a specific order, usually ascending or
descending.
• Sorting is essential for various applications like searching, data analysis, and
optimization in algorithms.
Types of Sorting:
There are two types of sorting:
1. Internal Sorting: Sorting is done in the main memory (RAM). This is used when the
dataset is small enough to fit in memory.
2. External Sorting: Sorting involves external storage (such as disk), used when the data
is too large to fit into memory.
Sorting Algorithms:
The most commonly used sorting algorithms are:
1. Bubble Sort
2. Selection Sort
3. Insertion Sort
4. Merge Sort
5. Quick Sort
1. Bubble Sort:
• Concept: Compares adjacent elements and swaps them if they are in the wrong
order. This process is repeated until the list is sorted.
• Time Complexity: O(n²) in the worst and average cases. Best case: O(n) (when the
list is already sorted).
• Algorithm:
1. Start with the first element of the list.
2. Compare the current element with the next element.
3. If the current element is greater than the next, swap them.
4. Move to the next element and repeat the process until the end of the list.
5. Repeat this process for all elements.
• Example:
Unsorted list: [64, 25, 12, 22, 11]
Sorted list after Bubble Sort: [11, 12, 22, 25, 64]
2. Selection Sort:
• Concept: Divides the list into two parts: a sorted part and an unsorted part.
Repeatedly selects the smallest (or largest) element from the unsorted part and
swaps it with the leftmost unsorted element.
• Time Complexity: O(n²) for all cases (best, average, and worst).
• Algorithm:
1. Find the smallest element in the unsorted part of the list.
2. Swap it with the first element of the unsorted part.
3. Move the boundary between the sorted and unsorted parts one step to the
right.
4. Repeat until the entire list is sorted.
• Example:
Unsorted list: [64, 25, 12, 22, 11]
Sorted list after Selection Sort: [11, 12, 22, 25, 64]
3. Insertion Sort:
• Concept: Builds the sorted list one element at a time by repeatedly taking an
element from the unsorted part and inserting it into the correct position in the
sorted part.
• Time Complexity: O(n²) in the worst case. Best case: O(n) when the list is already
sorted.
• Algorithm:
1. Start with the second element, as the first element is already "sorted".
2. Compare it with elements in the sorted part, moving the larger elements one
position to the right.
3. Insert the current element into its correct position.
4. Repeat this process for all elements in the unsorted part.
• Example:
Unsorted list: [64, 25, 12, 22, 11]
Sorted list after Insertion Sort: [11, 12, 22, 25, 64]
4. Merge Sort:
• Concept: A Divide and Conquer algorithm. It divides the list into two halves,
recursively sorts both halves, and then merges them back together.
• Time Complexity: O(n log n) for all cases (best, average, and worst).
• Algorithm:
1. Divide the list into two halves.
2. Recursively sort both halves.
3. Merge the two sorted halves back into one sorted list.
• Example:
Unsorted list: [64, 25, 12, 22, 11]
Sorted list after Merge Sort: [11, 12, 22, 25, 64]
5. Quick Sort:
• Concept: Another Divide and Conquer algorithm. It selects a pivot element,
partitions the array into two parts based on the pivot, and recursively sorts both
parts.
• Time Complexity: Best and average case: O(n log n). Worst case: O(n²) (when the
pivot is poorly chosen).
• Algorithm:
1. Select a pivot element.
2. Partition the array such that elements smaller than the pivot go to the left,
and elements greater go to the right.
3. Recursively apply Quick Sort to the sub-arrays on the left and right of the
pivot.
• Example:
Unsorted list: [64, 25, 12, 22, 11]
Sorted list after Quick Sort: [11, 12, 22, 25, 64]
Applications of Sorting:
• Searching: Sorted lists are easier to search (e.g., binary search).
• Data Storage and Retrieval: Helps in efficiently storing and retrieving data.
• Optimization: Sorting helps optimize the performance of other algorithms.
Conclusion:
Sorting is a fundamental operation in computer science, with various algorithms suited to
different needs. While algorithms like Bubble Sort and Selection Sort are simple but
inefficient for large datasets, advanced algorithms like Quick Sort and Merge Sort provide
better performance for most real-world applications.
Dear Teachers and Students,
Join School of Educators' exclusive WhatsApp, Telegram, and Signal groups for FREE access
to a vast range of educational resources designed to help you achieve 100/100 in exams!
Separate groups for teachers and students are available, packed with valuable content to
boost your performance.
Additionally, benefit from expert tips, practical advice, and study hacks designed to enhance
performance in both CBSE exams and competitive entrance tests.
Don’t miss out—join today and take the first step toward academic excellence!
Access to Previous Years' Question Papers and Topper Answers: The group
provides access to previous years' question papers (PYQ) and exemplary answer
scripts of toppers. This resource is invaluable for exam preparation, allowing
individuals to familiarize themselves with the exam format, gain insights into scoring
techniques, and enhance their performance in assessments.
Free and Unlimited Resources: Members enjoy the benefit of accessing an array of
educational resources without any cost restrictions. Whether its study materials,
teaching aids, or assessment tools, the group offers an abundance of resources
tailored to individual needs. This accessibility ensures that educators and students
have ample support in their academic endeavors without financial constraints.
Instant Access to Educational Content: SOE WhatsApp groups are a platform where
teachers can access a wide range of educational content instantly. This includes study
materials, notes, sample papers, reference materials, and relevant links shared by
group members and moderators.
Timely Updates and Reminders: SOE WhatsApp groups serve as a source of timely
updates and reminders about important dates, exam schedules, syllabus changes, and
academic events. Teachers can stay informed and well-prepared for upcoming
assessments and activities.
Access to Expert Guidance: SOE WhatsApp groups are moderated by subject matter
experts, teachers, or experienced educators can benefit from their guidance,
expertise, and insights on various academic topics, exam strategies, and study
techniques.
Join the School of Educators WhatsApp Group today and unlock a world of resources,
support, and collaboration to take your teaching to new heights. To join, simply click
on the group links provided below or send a message to +91-95208-77777 expressing
your interest.
Best Regards,
Team
School of Educators
Join School of Educators WhatsApp Groups
You will get Pre- Board Papers PDF, Word file, PPT, Lesson Plan, Worksheet, practical
tips and Viva questions, reference books, smart content, curriculum, syllabus,
marking scheme, toppers answer scripts, revised exam pattern, revised syllabus,
Blue Print etc. here . Join Your Subject / Class WhatsApp Group.
Entrepreneurship French IT
Artificial Intelligence
You will get Pre- Board Papers PDF, Word file, PPT, Lesson Plan, Worksheet, practical
tips and Viva questions, reference books, smart content, curriculum, syllabus,
marking scheme, toppers answer scripts, revised exam pattern, revised syllabus,
Blue Print etc. here . Join Your Subject / Class WhatsApp Group.
Artificial Intelligence
Entrepreneurship French IT
AI IIT/NEET CUET
Groups Rules & Regulations:
To maximize the benefits of these WhatsApp groups, follow these guidelines:
Additional notes:
1. Avoid posting messages between 9 PM and 7 AM.
2. After sharing resources with students, consider deleting outdated data if necessary.
3. It's a NO Nuisance groups, single nuisance and you will be removed.
No introductions.
No greetings or wish messages.
No personal chats or messages.
No spam. Or voice calls
Share and seek learning resources only.
Join our premium groups and just Rs. 1000 and gain access to all our exclusive
materials for the entire academic year. Whether you're a student in Class IX, X, XI, or
XII, or a teacher for these grades, Artham Resources provides the ultimate tools to
enhance learning. Pay now to delve into a world of premium educational content!
Class 12
📣 Don't Miss Out! Elevate your academic journey with top-notch study materials and secure
your path to top scores! Revolutionize your study routine and reach your academic goals with
our comprehensive resources. Join now and set yourself up for success! 📚🌟
Best Wishes,
Team
School of Educators & Artham Resources
SKILL MODULES BEING OFFERED IN
MIDDLE SCHOOL
Artificial Intelligence Beauty & Wellness Design Thinking & Financial Literacy
Innovation
Digital Citizenship Life Cycle of Medicine & Things you should know What to do when Doctor
Vaccine about keeping Medicines is not around
at home
Application of Photography
Satellites
SKILL SUBJECTS AT SECONDARY LEVEL (CLASSES IX – X)
Food Production Front Office Operations Banking & Insurance Marketing & Sales
Artificial Intelligence
Physical Activity Trainer Electronics & Hardware
Data Science
(NEW)
Mass Media Studies Library & Information Fashion Studies Applied Mathematics
Science
You will get Pre- Board Papers PDF, Word file, PPT, Lesson Plan, Worksheet, practical
tips and Viva questions, reference books, smart content, curriculum, syllabus,
marking scheme, toppers answer scripts, revised exam pattern, revised syllabus,
Blue Print etc. here . Join Your Subject / Class signal Group.
Class 2 Class 3
Class 1
Class 5 Class 6
Class 4
Hindi-B
English Hindi-A
IT Artifical intelligence
IT Code-402
Biology Accountancy
Mathematics
BST History
Economics
Geography Sociology Hindi Elective
IP
Vocal Music Comp. Science
IIT/NEET
Entrepreneurship French
Kindergarten