The document discusses various sorting algorithms including exchange sorts like bubble sort and quicksort, selection sorts like straight selection sort, and tree sorts like heap sort. For each algorithm, it provides an overview of the approach, pseudocode, analysis of time complexity, and examples. Key algorithms covered are bubble sort (O(n2)), quicksort (average O(n log n)), selection sort (O(n2)), and heap sort (O(n log n)).
Data may be organized in many different ways; the logical or mathematical model of a particular organization of data is called "Data Structure". The choice of a particular data model depends on two considerations:
It must be rich enough in structure to reflect the actual relationships of the data in the real world.
The structure should be simple enough that one can effectively process the data when necessary.
Data Structure Operations
The particular data structure that one chooses for a given situation depends largely on the nature of specific operations to be performed.
The following are the four major operations associated with any data structure:
i. Traversing : Accessing each record exactly once so that certain items in the record may be processed.
ii. Searching : Finding the location of the record with a given key value, or finding the locations of all records which satisfy one or more conditions.
iii. Inserting : Adding a new record to the structure.
iv. Deleting : Removing a record from the structure.
Primitive and Composite Data Types
Primitive Data Types are Basic data types of any language. In most computers these are native to the machine's hardware.
Some Primitive data types are:
Integer
Data Structures, which is also called as Abstract Data Types (ADT) provide powerful options for programmer. Here is a tutorial which talks about various ADTs - Linked Lists, Stacks, Queues and Sorting Algorithms
Introduction: Data Types, Data structures
Types of Data Structures
Operations, ADTs
Algorithms, Comparison of Algorithms, Complexity, Time- space tradeoff.
Recursion: Introduction, format of recursive functions, recursion Vs. Iteration, examples.
Sorting: Quick sort, Merge Sort, Selection Sort
Concept and Definition of Data Structures
Introduction to Data Structures: Information and its meaning, Array in C++: The array as an ADT, Using one dimensional array, Two dimensional array, Multi dimensional array, Structure , Union, Classes in C++.
https://github.com/ashim888/dataStructureAndAlgorithm
Data may be organized in many different ways; the logical or mathematical model of a particular organization of data is called "Data Structure". The choice of a particular data model depends on two considerations:
It must be rich enough in structure to reflect the actual relationships of the data in the real world.
The structure should be simple enough that one can effectively process the data when necessary.
Data Structure Operations
The particular data structure that one chooses for a given situation depends largely on the nature of specific operations to be performed.
The following are the four major operations associated with any data structure:
i. Traversing : Accessing each record exactly once so that certain items in the record may be processed.
ii. Searching : Finding the location of the record with a given key value, or finding the locations of all records which satisfy one or more conditions.
iii. Inserting : Adding a new record to the structure.
iv. Deleting : Removing a record from the structure.
Primitive and Composite Data Types
Primitive Data Types are Basic data types of any language. In most computers these are native to the machine's hardware.
Some Primitive data types are:
Integer
Data Structures, which is also called as Abstract Data Types (ADT) provide powerful options for programmer. Here is a tutorial which talks about various ADTs - Linked Lists, Stacks, Queues and Sorting Algorithms
Introduction: Data Types, Data structures
Types of Data Structures
Operations, ADTs
Algorithms, Comparison of Algorithms, Complexity, Time- space tradeoff.
Recursion: Introduction, format of recursive functions, recursion Vs. Iteration, examples.
Sorting: Quick sort, Merge Sort, Selection Sort
Concept and Definition of Data Structures
Introduction to Data Structures: Information and its meaning, Array in C++: The array as an ADT, Using one dimensional array, Two dimensional array, Multi dimensional array, Structure , Union, Classes in C++.
https://github.com/ashim888/dataStructureAndAlgorithm
Data structure and algorithm using javaNarayan Sau
This presentation created for people who like to go back to basics of data structure and its implementation. This presentation mostly helps B.Tech , Bsc Computer science students as well as all programmer who wants to develop software in core areas.
This slide explains three (3) basic sorting algorithms with codes on github. Bubble sort, Selection sort and insertion sort.
visit https://github.com/EngrMikolo/BasicSortingAlgorithms to checkout the codes
Analysis and design of algorithms part2Deepak John
Analysis of searching and sorting. Insertion sort, Quick sort, Merge sort and Heap sort. Binomial Heaps and Fibonacci Heaps, Lower bounds for sorting by comparison of keys. Comparison of sorting algorithms. Amortized Time Analysis. Red-Black Trees – Insertion & Deletion.
Read| The latest issue of The Challenger is here! We are thrilled to announce that our school paper has qualified for the NATIONAL SCHOOLS PRESS CONFERENCE (NSPC) 2024. Thank you for your unwavering support and trust. Dive into the stories that made us stand out!
Model Attribute Check Company Auto PropertyCeline George
In Odoo, the multi-company feature allows you to manage multiple companies within a single Odoo database instance. Each company can have its own configurations while still sharing common resources such as products, customers, and suppliers.
The French Revolution, which began in 1789, was a period of radical social and political upheaval in France. It marked the decline of absolute monarchies, the rise of secular and democratic republics, and the eventual rise of Napoleon Bonaparte. This revolutionary period is crucial in understanding the transition from feudalism to modernity in Europe.
For more information, visit-www.vavaclasses.com
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...Levi Shapiro
Letter from the Congress of the United States regarding Anti-Semitism sent June 3rd to MIT President Sally Kornbluth, MIT Corp Chair, Mark Gorenberg
Dear Dr. Kornbluth and Mr. Gorenberg,
The US House of Representatives is deeply concerned by ongoing and pervasive acts of antisemitic
harassment and intimidation at the Massachusetts Institute of Technology (MIT). Failing to act decisively to ensure a safe learning environment for all students would be a grave dereliction of your responsibilities as President of MIT and Chair of the MIT Corporation.
This Congress will not stand idly by and allow an environment hostile to Jewish students to persist. The House believes that your institution is in violation of Title VI of the Civil Rights Act, and the inability or
unwillingness to rectify this violation through action requires accountability.
Postsecondary education is a unique opportunity for students to learn and have their ideas and beliefs challenged. However, universities receiving hundreds of millions of federal funds annually have denied
students that opportunity and have been hijacked to become venues for the promotion of terrorism, antisemitic harassment and intimidation, unlawful encampments, and in some cases, assaults and riots.
The House of Representatives will not countenance the use of federal funds to indoctrinate students into hateful, antisemitic, anti-American supporters of terrorism. Investigations into campus antisemitism by the Committee on Education and the Workforce and the Committee on Ways and Means have been expanded into a Congress-wide probe across all relevant jurisdictions to address this national crisis. The undersigned Committees will conduct oversight into the use of federal funds at MIT and its learning environment under authorities granted to each Committee.
• The Committee on Education and the Workforce has been investigating your institution since December 7, 2023. The Committee has broad jurisdiction over postsecondary education, including its compliance with Title VI of the Civil Rights Act, campus safety concerns over disruptions to the learning environment, and the awarding of federal student aid under the Higher Education Act.
• The Committee on Oversight and Accountability is investigating the sources of funding and other support flowing to groups espousing pro-Hamas propaganda and engaged in antisemitic harassment and intimidation of students. The Committee on Oversight and Accountability is the principal oversight committee of the US House of Representatives and has broad authority to investigate “any matter” at “any time” under House Rule X.
• The Committee on Ways and Means has been investigating several universities since November 15, 2023, when the Committee held a hearing entitled From Ivory Towers to Dark Corners: Investigating the Nexus Between Antisemitism, Tax-Exempt Universities, and Terror Financing. The Committee followed the hearing with letters to those institutions on January 10, 202
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdfTechSoup
In this webinar you will learn how your organization can access TechSoup's wide variety of product discount and donation programs. From hardware to software, we'll give you a tour of the tools available to help your nonprofit with productivity, collaboration, financial management, donor tracking, security, and more.
Biological screening of herbal drugs: Introduction and Need for
Phyto-Pharmacological Screening, New Strategies for evaluating
Natural Products, In vitro evaluation techniques for Antioxidants, Antimicrobial and Anticancer drugs. In vivo evaluation techniques
for Anti-inflammatory, Antiulcer, Anticancer, Wound healing, Antidiabetic, Hepatoprotective, Cardio protective, Diuretics and
Antifertility, Toxicity studies as per OECD guidelines
Acetabularia Information For Class 9 .docxvaibhavrinwa19
Acetabularia acetabulum is a single-celled green alga that in its vegetative state is morphologically differentiated into a basal rhizoid and an axially elongated stalk, which bears whorls of branching hairs. The single diploid nucleus resides in the rhizoid.
1. Data Structures & Algorithm
Sorting I
Session VI
Dr. V.Umadevi M.Sc(CS &IT). M.Tech (IT)., M.Phil., PhD.,
D.Litt.,
Director, Department of Computer Science, Jairams Arts
and Science College, Karur.
2. Data Structures & Algorithm
Sorting I
• Introduction to Sorting
• Exchange Sort
– Bubble sort
– Quick Sorts
• Selection and Tree Sorting
– Straight Selection Sort
– Heap Sort
3. Data Structures & Algorithm
Sorting
General Def : Arrange the data in some appropriate order according to some
key.
Examples:
• An English dictionary, in which all words are arranged in alphabetic
order.
• A phone directory, in which phone numbers are listed in some order.
• Sorting is the fundamental algorithmic problem in computer science.
• Learning the different sorting algorithms is like learning scales for a
musician.
• Formal Def : Given a sequence of numbers <x1, x2, ..., xn>, a sorting
algorithm must compute a permutation <x'1, x'2, ..., x'n> such that x'1 ≤
x'2≤ ... ≤ x'n
4. Data Structures & AlgorithmExchange Sorts
Bubble Sort
• This sort is oldest and simplest sort in use.
• Its is the slowest sort.
• Works by comparing each item in the list with the item next to it, swapping
them if required.
• Algorithm repeat this process until it makes a pass all the way through the
list without swapping any items.
• Causes larger values to “Sink" to the end of the list while smaller values “bubble"
towards the beginning of the list.
• Bubble sort is generally considered to be the most inefficient sorting algorithm in
common usage.
• Under best-case conditions (the list is already sorted), the bubble sort can
approach a constant O(n) level of complexity.
Pros: Simplicity and ease of implementation.
Cons: Horribly inefficient.
5. Data Structures & Algorithm
void bubbleSort(int numbers[], int array_size)
{
int i, j, temp;
for (i = (array_size - 1); i >= 0; i--)
{
for (j = 1; j <= i; j++)
{
if (numbers[j-1] > numbers[j])
{
temp = numbers[j-1];
numbers[j-1] = numbers[j];
numbers[j] = temp;
}
}
}
}
Source code for Bubble sort
6. Data Structures & AlgorithmExample:
1 2 3 4 5 6 7 // Positions
-------------
4 6 2 5 7 3 4 // Initial sequence
4 2 5 6 3 4 7 // Swapped: 2-3, 3-4, 5-6, 6-7; last_swap=6
2 4 5 3 4 6 7 // Swapped: 1-2, 4-5, 5-6; last_swap=5
2 4 3 4 5 6 7 // Swapped: 3-4, 4-5; last_swap=4
2 3 4 4 5 6 7 // Swapped: 2-3; last_swap=2
2 3 4 4 5 6 7 // No swapping; last_swap=0; end
• Analysis: Best case performing one pass which require n-1 comparisons
• Consequently best case is O(n).
• Worst case performance of bubble sort is n(n-1)/ 2 comparison and exchange
• Average case is analysis is O(n2
).
• Average number of comparison and exchanges are both O(n2
).
Bubble Sort Analysis
7. Data Structures & AlgorithmQuick Sort
• Invented in 1960 by C. A. R. Hoare
• Popular and well investigated
• Easy to be implemented and improved
• Quick sort is an in-place, divide-and-conquer, massively recursive sort.
• Recursive algorithm consists of four steps:
1. If there are one or less elements in the array to be sorted, return
immediately.
2. Pick an element in the array to serve as a "pivot" point. (Usually the left-
most element in the array is used.)
3. Split the array into two parts - one with elements larger than the pivot
and the other with elements smaller than the pivot.
4. Recursively repeat the algorithm for both halves of the original array.
8. Data Structures & Algorithm
Initial Step - First Partition Sort Left Partition in the same way
• Partition array into two segments.
• First segment all elements are less than or equal to the pivot value.
• Second segment all elements are greater or equal to the pivot value.
• Sort the two segments recursively.
• Pivot can only be found by scanning the whole array and this would slow down
the algorithm.
• Quick sort is fastest on average, but sometimes unbalanced partitions can lead
to very slow sorting.
• The best sorting algorithm when there is no infinite memory space.
9. Data Structures & Algorithm
Quicksort Example
Analysis
• Worst-Case Analysis - the pivot is the smallest element, all the time (requires N
recursive call of quicksort O(N)with comparison for a level). So the
algorithm O(N2
)will be run in a time.
• Best-Case Analysis - the pivot is in the middle, all the time. The running time
is . O(N Log N)
• Average-Case Analysis - each of the sizes for array (s1) is equally likely. The
running time for this case is also O(N Log N) .
Pros: Extremely fast.
Cons: Very complex algorithm, massively recursive.
10. Data Structures & Algorithmvoid quickSort(int numbers[], int array_size)
{ q_sort(numbers, 0, array_size - 1); }
void q_sort(int numbers[], int left, int right)
{
int pivot, l_hold, r_hold;
l_hold = left;
r_hold = right;
pivot = numbers[left];
while (left < right)
{
while ((numbers[right] >= pivot) && (left < right))
right--;
if (left != right)
{
numbers[left] = numbers[right];
left++;
}
while ((numbers[left] <= pivot) && (left < right))
left++;
if (left != right)
{
numbers[right] = numbers[left];
right--;
}
}
numbers[left] = pivot;
pivot = left;
left = l_hold;
right = r_hold;
if (left < pivot)
q_sort(numbers, left, pivot-1);
if (right > pivot)
q_sort(numbers, pivot+1, right);
}
Code For Quick Sort
11. Data Structures & Algorithm
Analysis of Exchange Sorts
Exchange Sorts Running Time
Algorithms Best Case Average
Case
Worst
Case
Bubble Sort O(n2
) O(n2
) O(n2
)
Quick Sort O(n Log n) O(n Log n) O(n2
)
12. Data Structures & AlgorithmStraight Selection Sort
• Selection sort is one in which successive elements are selected in order
and placed into their proper sorted positions.
• Elements of the input may have to be preprocessed to make the ordered
selection possible.
• Def: An algorithm which orders items by repeatedly looking through
remaining items to find the least one and moving it to a final location.
• Select successive elements in ascending order and place them into their
proper position.
– Find the smallest element from the array, and exchange it with the first
element.
– Find the second smallest element, and exchange it with the second
element.
– Repeat until sorted in proper order.
– Searching the smallest key in the record is called pass
13. Data Structures & Algorithm
• 42 23 74 11 65 58 94 36 99 87 //Input
• [11 ] 23 74 42 65 58 94 36 99 87
• [11 23 ] 74 42 65 58 94 36 99 87
• [11 23 36 ] 42 65 58 94 74 99 87
• [11 23 36 42 ] 65 58 94 74 99 87
• [11 23 36 42 58 ] 65 94 74 99 87
• [11 23 36 42 58 65 ] 94 74 99 87
• [11 23 36 42 58 65 74 ] 94 99 87
• [11 23 36 42 58 65 74 87 ] 99 94
• [11 23 36 42 58 65 74 87 94 ] 99
• 11 23 36 42 58 65 74 87 94 99 //Output
• Selection sort works by selecting the smallest unsorted item remaining in
the list, and then swapping it with the item in the next position to be
filled.
Example of Selection Sort
14. Data Structures & Algorithm
•Starting near the top of the array extract the 3.
•Then the above elements are shifted down until we find the correct place to
insert the 3.
•This process repeats in Figure(b) with the next number.
• Finally, in Figure(c) complete the sort by inserting 2 in the correct place.
15. Data Structures & Algorithm
• N-1 pass is required in order to perform the sort.
• During the Ist pass in which the record with the smallest key is found n-1
records are compared.
• In general for ith
pass of the sort n-I comparisons are required.
• Total number of comparisons is
• Σn-1
n-I =n(n-1)/2
• i=1
• Therefore the number of comparison is proportional to n2
i.e O(n2
)
• Selection sort has a complexity of O(n2).
Pros: Simple and easy to implement.
Cons: Inefficient for large lists, so similar to the more efficient
insertion sort that the insertion sort should be used in its
place.
Analysis of Selection Sort
16. Data Structures & Algorithm
selection( int a[], int N) /* in C */ /* sort a[1..N], NB. 1 to N */
{ int i, j, smallest, aSmallest, temp;
for (i=1; i < N; i++)
{ /* invariant: a[1..i-1] sorted and elements a[1..i-1] <= a[i..N] */
smallest = i; /* find smallest in a[i..N] */
aSmallest = a[i];
for(j=i+1; j <= N; j++) /* a[smallest] is the least element in a[i..j-1] */
if ( a[j] < aSmallest )
{
smallest=j;
aSmallest=a[j];
} /* a[smallest] is the least element in a[i..j] */
temp=a[i];
a[i]=a[smallest];
a[smallest]=temp;
/*swap*/ /* a[1..i] sorted and elements a[1..i] <= a[i+1..N] */
} /* a[1..N-1] sorted and elements a[1..N-1] <= a[N] */
/* i.e. a[1..N] sorted. */
Source Code for Selection Sort
17. Data Structures & Algorithm
Heap Sort
• Elegant and efficient, widely used.
• No extra memory is needed.
• Heap sort is based on a tree structure that reflects the packing order in a
corporate hierarchy.
• This method has two phases.
• First the tree representing file is converted to heap
• Second stage output sequence is generated in decreasing order
• A heap is complete binary tree in which each node satisfies the heap condition
represented as an array.
Def- a heap is a list in which each entry contains a key and for all positions k in the
list, the key at position k is at least as large as the keys in positions
2k and 2k+1 provided these positions exist in the list.
• A complete binary tree is said to satisfy the heap condition if the key of each node
is greater than or equal to the key in its children, thus the root node
will have the largest key value.
18. Data Structures & Algorithm
Analysis of Heap sort
• Elegant and efficient, widely used.
• No extra memory is needed.
• On average, Heap sort is third place in speed.
• But inner loop is a bit longer than that of Quick Sort, about twice as slow
as Quick Sort on the average.
• Building of the heap uses at most 2N comparisons,
• In the worst case, at most 2n log n - O(n) comparisons are used by
heapsort.
• Good performance (NlogN) is guaranteed.