MIDTERM TOPICS Flashcards
is used to rearrange a given array or list of elements according to a comparison operator on the elements
Sorting Algorithm
refers to rearrangement of a given array or list of elements according to a comparison operator on the elements.
Sorting
Sorting Terminology:
In-place Sorting
Internal Sorting
External Sorting
Stable sorting
Unstable sorting
uses constant space for producing the output (modifies the given array only) or copying elements to a temporary storage
In-place Sorting
is when all the data is placed in the main memory or internal memory
Internal Sorting
is when all the data that needs to be sorted cannot be placed in memory at a time
External Sorting
when two same items appear in the same order in sorted data as in the original array
Stable sorting
When two same data appear in the different order in sorted data
Unstable sorting
Characteristics of Sorting Algorithms
Time Complexity
Auxiliary Space
Stability
In-Place Sorting
Adaptivity
a measure of how long it takes to run an algorithm, is used to categorize sorting algorithms
Time Complexity
This is the amount of extra space (apart from input array) needed to sort
Auxiliary Space
A sorting algorithm is said to be stable if the relative order of equal elements is preserved after sorting
Stability
is one that does not require additional memory to sort the data. This is important when the available memory is limited or when the data cannot be moved.
In-Place Sorting
is one that takes advantage of pre-existing order in the data to improve performance.
Adaptivity
Applications of Sorting Algorithms:
Searching Algorithms
Data management
Database optimization
Machine learning
Data Analysis
Operating Systems
Sorting is often a crucial step in search algorithms like binary search and Ternary Search. A lot of Greedy Algorithms use sorting as a first step to apply Greedy Approach
Searching Algorithms
Sorting data makes it easier to search, retrieve, and analyze. For example the order by operation in SQL queries requires sorting.
Data management
Sorting data in databases improves query performance. We preprocess the data by sorting so that efficient searching can be applied.
Database optimization
Sorting is used to prepare data for training machine learning models
Machine learning
Sorting helps in identifying patterns, trends, and outliers in datasets. It plays a vital role in statistical analysis, financial modeling, and other data-driven fields.
Data Analysis
Sorting algorithms are used in __ ___ for tasks like task scheduling, memory management, and file system organization.
operating systems
is a simple and efficient sorting algorithm that works by repeatedly selecting the smallest (or largest) element from the unsorted portion of the list and moving it to the sorted portion of the list.
Selection sort
is one of the most popular sorting algorithms that is based on the principle of Divide and Conquer Algorithm.
Merge Sort
divide a problem into subproblems. When the solution to each subproblem is ready, we ‘combine’ the results from the subproblems to solve the main problem.
Divide and Conquer