SlideShare a Scribd company logo
1 of 20
K.K. WAGH POLYTECHNIC,
NASHIK-03
DEPARTMENT OF COMPUTER
TECHNOLOGY(Second Shift)
Demonstration of
Address Calculation
Sort
Bucket sort, or bin sort, is a distribution sorting algorithm.
It is a stable sort, where the relative order of any two items
with the same key is preserved.
It works in the following way:
 set up m buckets where each bucket is responsible for an equal
portion of the range of keys in the array.
 place items in appropriate buckets.
 sort items in each non-empty bucket using insertion sort.
 concatenate sorted lists of items from buckets to get final sorted
order.
Analysis of running time of Bucket sort:
 Best Case Complexity: O(n logn)
 Worst Case Complexity: O(n2)
Bucket Sort
Example of Bucket Sort
The example uses an input array of 9 elements. Key values are in the
range from 10 to 19. It uses an auxiliary array of linked lists which is
used as buckets.
Items are placed in appropriate buckets and links are maintained to
point to the next element. Order of the two keys with value 15 is
maintained after sorting.
n ← length [A]
For i = 1 to n do
Insert A[i] into list B[nA[i]]
For i = 0 to n-1 do
Sort list B with Insertion sort
Concatenate the lists B[0], B[1], . . B[n-1]
together in order.
Algorithm of Bucket Sort
Program for Bucket Sort
#include<stdio.h>
void Bucket_Sort(int array[], int n)
{
int i, j,k;
int count[10][50];
for(i=0; i < 10; i++)
{
for(j=0;j<50;j++)
count[i][j] = 0;
}
for(i=0,j=0; i < n; i++)
{ k=array[i]/10;
j++;
count[k][j]=array[i];
printf("ncount[%d][%d]=%d",k,j,array[i]);
}
for(i=0,j=0,k=0; i < n; i++)
{
for(j=0;j<50;j++)
{
if(count[i][j]>0)
array[k++] = count[i][j];
}
}
}
int main()
{
int array[100]; int num; int i;
clrscr();
printf("Enter How many Numbers : ");
scanf("%d",&num);
Program for Bucket Sort
printf("Enter the %d elements to be sorted:n",num);
for(i = 0; i < num; i++ )
{
scanf("%d",&array[i]);
}
printf("nThe array of elements before sorting : n");
for (i = 0;i < num;i++)
{
printf("%d ", array[i]);
}
printf("nThe array of elements after sorting :n");
Bucket_Sort(array, num);
for (i = 0;i < num;i++)
{
printf("%d ", array[i]);
}
return 0;
}
Program for Bucket Sort
Radix Sort
Radix is the base of a number system or logarithm.
Radix sort is a multiple pass distribution sort.
 It distributes each item to a bucket according to part of
the item's key.
 After each pass, items are collected from the buckets,
keeping the items in order, then redistributed according
to the next most significant part of the key.
This sorts keys digit-by-digit (hence referred to as digital
sort), or, if the keys are strings that we want to sort
alphabetically, it sorts character-by-character.
Radix sort uses bucket or count sort as the stable sorting
algorithm, where the initial relative order of equal keys is
unchanged.
Radix Sort
Radix sort is classified based on how it works internally:
least significant digit (LSD) radix sort:
Processing starts from the least significant digit and
moves towards the most significant digit.
Most significant digit (MSD) radix sort:
Processing starts from the most significant digit and
moves towards the least significant digit. This is recursive. It
works in the following way:
Example of LSD-Radix Sort
12 44 41 34 11 32 23
Input is an array of 15 integers. For integers, the number of buckets is 10, from 0 to 9.
The first pass distributes the keys into buckets by the least significant digit (LSD).
When the first pass is done, we have the following.
23
44
34
12
42
32
41
11
0 1 2 3 4 5 6 7 8 9
5087 77
77
50 87 58
58
08
0842
Example of LSD-Radix Sort…contd
50
We collect these, keeping their relative order:
Now we distribute by the next most significant digit, which is the highest digit in our
example, and we get the following.
11
12
23
32
34
41
42
44
When we collect them, they are in order.
12 42 444111 3223 34
12 42 4441 3411 32 23 77 58 08
0 1 2 3 4 5 6 7 8 9
50 877708
08 50 77 87
58
58
87
#include <conio.h>
#include <stdio.h>
void main()
{
int unsorted[50] , bucket[10][50]={{0}} , sorted[50] ;
int j , k , m , p , flag = 0, num, N;
clrscr();
printf("nEnter the number of elements to be sorted :");
scanf("%d",&N);
printf("nEnter the elements to be sorted :n");
for(k=0 ; k < N ; k++)
{
scanf("n%d",&num);
sorted[k] = unsorted[k] = num;
}
for(p=1; flag != N ; p*=10)
{
flag = 0;
for(k=0;k<N;k++)
{
printf("n flag=%d",flag);
bucket[(sorted[k]/p)%10][k] = sorted[k];
printf("n position of element=%d %d",((sorted[k]/p)%10),k);
printf("n element value=%d",bucket[(sorted[k]/p)%10][k]);
if ( (sorted[k]/p)%10 == 0 )
{
flag++;
}
}
for(j=0,m=0;j<10;j++)
{
for(k=0;k<N;k++)
{
if( bucket[j][k] > 0 )
{
sorted[m] = bucket[j][k];
bucket[j][k] = 0 ; m++;
}
}
}
}
if (flag == N)
{
printf("nSorted List: n");
for(j=0 ; j < N ; j++)
{
printf("%dt", sorted[j]);
} printf("n");
}
getch() ;
}
 This can be one of the fastest types of distributive sorting
technique if enough space is available also called as
Hashing.
 In this algorithm, a hash function is used and applied to
each element in the list. The result of the hash function
is placed in to an address in the table that represents the
key.
 Linked lists are used as address table for storing keys.(if
there are 4 keys then 4 linked lists are used).
 The hash function places the elements in linked lists are
called as sub files. An item is placed into a sub-file in
correct sequence by using any sorting method. After all
the elements are placed into subfiles, the lists
(subfies)are concatenated to produce the sorted list.
Address Calculation Sort
Procedure:
1. In this method a hash function f is applied to each key.
2. The result of this function determines into which of the
several subfiles the record is to be placed.
The function should have the property that: if x <= y ,
f (x) <= f (y), Such a function is called order preserving.
3. An item is placed into a subfile in correct sequence by
using any sorting method – simple insertion is often
used.
4. After all the elements are placed into subfiles, the lists
(subfiles) are concatenated to produce the sorted list.
Address Calculation Sort
Example:
25 57 48 37 12 92 86 33
Let us create 10 subfiles (linked lists). Initially each of
these subfiles is empty.
Key.
Address Calculation Sort
0
1
2
3
4
5
6
7
8
9
Example:
The number is passed to hash function, which returns its last
digit (ten’s place digit), which is placed at that position only,
in the linked lists.
num= 25 - f(25) gives 2
57 - f(57) gives 5
48 - f(48) gives 4
37 - f(37) gives 3
12 - f(12) gives 1
92 - f(92) gives 9
86 - f(86) gives 8
33 - f(33) gives 3
which is repeated.
Address Calculation Sort
0
1
2
3
4
5
6
7
8
9
25
57
48
33
12
92
86
37
Example:
After concatenating all linked list we get the sorted list.
12 25 33 37 48 57 86 92
Efficiency:
If all the elements (n) are uniformly distributed over m
subfiles then n/m is approximately 1, time of the sort is near
O(n).
On the other hand if maximum elements accommodate in
one or two subfiles, then n/m is much larger significant work
is required to insert element into proper subfile at its proper
position and efficiency is O(n2).
Address Calculation Sort
Thank You

More Related Content

What's hot

Lesson 02 python keywords and identifiers
Lesson 02   python keywords and identifiersLesson 02   python keywords and identifiers
Lesson 02 python keywords and identifiersNilimesh Halder
 
Applications of stack
Applications of stackApplications of stack
Applications of stackeShikshak
 
For Loops and Nesting in Python
For Loops and Nesting in PythonFor Loops and Nesting in Python
For Loops and Nesting in Pythonprimeteacher32
 
Direct linking loader
Direct linking loaderDirect linking loader
Direct linking loaderbabyparul
 
Issues in the design of Code Generator
Issues in the design of Code GeneratorIssues in the design of Code Generator
Issues in the design of Code GeneratorDarshan sai Reddy
 
8 queens problem using back tracking
8 queens problem using back tracking8 queens problem using back tracking
8 queens problem using back trackingTech_MX
 
Basic blocks and control flow graphs
Basic blocks and control flow graphsBasic blocks and control flow graphs
Basic blocks and control flow graphsTilakpoudel2
 
Array linear data_structure_2 (1)
Array linear data_structure_2 (1)Array linear data_structure_2 (1)
Array linear data_structure_2 (1)eShikshak
 
Array operations
Array operationsArray operations
Array operationsZAFAR444
 
Introduction to loaders
Introduction to loadersIntroduction to loaders
Introduction to loadersTech_MX
 
Theory of automata and formal language lab manual
Theory of automata and formal language lab manualTheory of automata and formal language lab manual
Theory of automata and formal language lab manualNitesh Dubey
 
Two dimensional arrays
Two dimensional arraysTwo dimensional arrays
Two dimensional arraysNeeru Mittal
 
Array implementation and linked list as datat structure
Array implementation and linked list as datat structureArray implementation and linked list as datat structure
Array implementation and linked list as datat structureTushar Aneyrao
 
Linked List - Insertion & Deletion
Linked List - Insertion & DeletionLinked List - Insertion & Deletion
Linked List - Insertion & DeletionAfaq Mansoor Khan
 

What's hot (20)

Lesson 02 python keywords and identifiers
Lesson 02   python keywords and identifiersLesson 02   python keywords and identifiers
Lesson 02 python keywords and identifiers
 
Data Representation
Data RepresentationData Representation
Data Representation
 
Applications of stack
Applications of stackApplications of stack
Applications of stack
 
Python for loop
Python for loopPython for loop
Python for loop
 
For Loops and Nesting in Python
For Loops and Nesting in PythonFor Loops and Nesting in Python
For Loops and Nesting in Python
 
Direct linking loader
Direct linking loaderDirect linking loader
Direct linking loader
 
Linker and Loader
Linker and Loader Linker and Loader
Linker and Loader
 
Issues in the design of Code Generator
Issues in the design of Code GeneratorIssues in the design of Code Generator
Issues in the design of Code Generator
 
8 queens problem using back tracking
8 queens problem using back tracking8 queens problem using back tracking
8 queens problem using back tracking
 
Basic blocks and control flow graphs
Basic blocks and control flow graphsBasic blocks and control flow graphs
Basic blocks and control flow graphs
 
Array linear data_structure_2 (1)
Array linear data_structure_2 (1)Array linear data_structure_2 (1)
Array linear data_structure_2 (1)
 
Array operations
Array operationsArray operations
Array operations
 
Introduction to loaders
Introduction to loadersIntroduction to loaders
Introduction to loaders
 
String matching algorithms
String matching algorithmsString matching algorithms
String matching algorithms
 
Python Modules
Python ModulesPython Modules
Python Modules
 
Theory of automata and formal language lab manual
Theory of automata and formal language lab manualTheory of automata and formal language lab manual
Theory of automata and formal language lab manual
 
Linked list
Linked listLinked list
Linked list
 
Two dimensional arrays
Two dimensional arraysTwo dimensional arrays
Two dimensional arrays
 
Array implementation and linked list as datat structure
Array implementation and linked list as datat structureArray implementation and linked list as datat structure
Array implementation and linked list as datat structure
 
Linked List - Insertion & Deletion
Linked List - Insertion & DeletionLinked List - Insertion & Deletion
Linked List - Insertion & Deletion
 

Viewers also liked

Spr ch-05-compilers
Spr ch-05-compilersSpr ch-05-compilers
Spr ch-05-compilersVasim Pathan
 
Webinar – Pricing & Regulations: Will you be able to justify your valuations ...
Webinar – Pricing & Regulations: Will you be able to justify your valuations ...Webinar – Pricing & Regulations: Will you be able to justify your valuations ...
Webinar – Pricing & Regulations: Will you be able to justify your valuations ...aimsoftware
 
Universities as Regenerators: Rupert Goddard, Sheppard Robson
Universities as Regenerators: Rupert Goddard, Sheppard RobsonUniversities as Regenerators: Rupert Goddard, Sheppard Robson
Universities as Regenerators: Rupert Goddard, Sheppard RobsonPlace North West
 
Promotional Strategies: Virgin Mobile India
Promotional Strategies: Virgin Mobile IndiaPromotional Strategies: Virgin Mobile India
Promotional Strategies: Virgin Mobile Indiashruthi.rajan
 
Power Of Promotional Products
Power Of Promotional ProductsPower Of Promotional Products
Power Of Promotional Productsguest71c04f
 
Time Management Strategies For Business Owners
Time Management Strategies For Business OwnersTime Management Strategies For Business Owners
Time Management Strategies For Business OwnersSynduit
 
Options pricing ( calculation of option premium)
Options pricing ( calculation of option premium)Options pricing ( calculation of option premium)
Options pricing ( calculation of option premium)Ameya Ranadive
 
PHARMA Target Segmentation Grid (2 plus 2)
PHARMA Target Segmentation Grid (2 plus 2)PHARMA Target Segmentation Grid (2 plus 2)
PHARMA Target Segmentation Grid (2 plus 2)Walid Saafan
 
Compiler Engineering Lab#5 : Symbol Table, Flex Tool
Compiler Engineering Lab#5 : Symbol Table, Flex ToolCompiler Engineering Lab#5 : Symbol Table, Flex Tool
Compiler Engineering Lab#5 : Symbol Table, Flex ToolMashaelQ
 
Chapter 4 - Marketing Research Process
Chapter 4 - Marketing Research ProcessChapter 4 - Marketing Research Process
Chapter 4 - Marketing Research ProcessDr. Ankit Kesharwani
 
A New Way of Looking at Eric Ries's Vision-Strategy-Product (VSP) Pyramid: TH...
A New Way of Looking at Eric Ries's Vision-Strategy-Product (VSP) Pyramid: TH...A New Way of Looking at Eric Ries's Vision-Strategy-Product (VSP) Pyramid: TH...
A New Way of Looking at Eric Ries's Vision-Strategy-Product (VSP) Pyramid: TH...Rod King, Ph.D.
 

Viewers also liked (18)

Spr ch-05-compilers
Spr ch-05-compilersSpr ch-05-compilers
Spr ch-05-compilers
 
Marketing fifthp
Marketing fifthpMarketing fifthp
Marketing fifthp
 
Chapter 12
Chapter 12Chapter 12
Chapter 12
 
Webinar – Pricing & Regulations: Will you be able to justify your valuations ...
Webinar – Pricing & Regulations: Will you be able to justify your valuations ...Webinar – Pricing & Regulations: Will you be able to justify your valuations ...
Webinar – Pricing & Regulations: Will you be able to justify your valuations ...
 
Product strategy
Product strategyProduct strategy
Product strategy
 
Chpt6
Chpt6Chpt6
Chpt6
 
Universities as Regenerators: Rupert Goddard, Sheppard Robson
Universities as Regenerators: Rupert Goddard, Sheppard RobsonUniversities as Regenerators: Rupert Goddard, Sheppard Robson
Universities as Regenerators: Rupert Goddard, Sheppard Robson
 
Promotional Strategies: Virgin Mobile India
Promotional Strategies: Virgin Mobile IndiaPromotional Strategies: Virgin Mobile India
Promotional Strategies: Virgin Mobile India
 
Power Of Promotional Products
Power Of Promotional ProductsPower Of Promotional Products
Power Of Promotional Products
 
Time Management Strategies For Business Owners
Time Management Strategies For Business OwnersTime Management Strategies For Business Owners
Time Management Strategies For Business Owners
 
Options pricing ( calculation of option premium)
Options pricing ( calculation of option premium)Options pricing ( calculation of option premium)
Options pricing ( calculation of option premium)
 
PHARMA Target Segmentation Grid (2 plus 2)
PHARMA Target Segmentation Grid (2 plus 2)PHARMA Target Segmentation Grid (2 plus 2)
PHARMA Target Segmentation Grid (2 plus 2)
 
Basics of brand map
Basics of brand mapBasics of brand map
Basics of brand map
 
What is symbol table?
What is symbol table?What is symbol table?
What is symbol table?
 
Compiler Engineering Lab#5 : Symbol Table, Flex Tool
Compiler Engineering Lab#5 : Symbol Table, Flex ToolCompiler Engineering Lab#5 : Symbol Table, Flex Tool
Compiler Engineering Lab#5 : Symbol Table, Flex Tool
 
Brand mapping tool
Brand mapping toolBrand mapping tool
Brand mapping tool
 
Chapter 4 - Marketing Research Process
Chapter 4 - Marketing Research ProcessChapter 4 - Marketing Research Process
Chapter 4 - Marketing Research Process
 
A New Way of Looking at Eric Ries's Vision-Strategy-Product (VSP) Pyramid: TH...
A New Way of Looking at Eric Ries's Vision-Strategy-Product (VSP) Pyramid: TH...A New Way of Looking at Eric Ries's Vision-Strategy-Product (VSP) Pyramid: TH...
A New Way of Looking at Eric Ries's Vision-Strategy-Product (VSP) Pyramid: TH...
 

Similar to Address calculation-sort

DS Unit 1.pptx
DS Unit 1.pptxDS Unit 1.pptx
DS Unit 1.pptxchin463670
 
data structures and algorithms Unit 3
data structures and algorithms Unit 3data structures and algorithms Unit 3
data structures and algorithms Unit 3infanciaj
 
Data structures arrays
Data structures   arraysData structures   arrays
Data structures arraysmaamir farooq
 
DS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and EngineeringDS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and EngineeringRAJASEKHARV8
 
Computer notes - Binary Search
Computer notes - Binary SearchComputer notes - Binary Search
Computer notes - Binary Searchecomputernotes
 
Please help solve this in C++ So the program is working fin.pdf
Please help solve this in C++ So the program is working fin.pdfPlease help solve this in C++ So the program is working fin.pdf
Please help solve this in C++ So the program is working fin.pdfankit11134
 
computer notes - Data Structures - 32
computer notes - Data Structures - 32computer notes - Data Structures - 32
computer notes - Data Structures - 32ecomputernotes
 
lecture 10
lecture 10lecture 10
lecture 10sajinsc
 
21CS32 DS Module 1 PPT.pptx
21CS32 DS Module 1 PPT.pptx21CS32 DS Module 1 PPT.pptx
21CS32 DS Module 1 PPT.pptxreddy19841
 
Data structure using c module 1
Data structure using c module 1Data structure using c module 1
Data structure using c module 1smruti sarangi
 
Searching and sorting by B kirron Reddi
Searching and sorting by B kirron ReddiSearching and sorting by B kirron Reddi
Searching and sorting by B kirron ReddiB.Kirron Reddi
 

Similar to Address calculation-sort (20)

Merge radix-sort-algorithm
Merge radix-sort-algorithmMerge radix-sort-algorithm
Merge radix-sort-algorithm
 
Merge radix-sort-algorithm
Merge radix-sort-algorithmMerge radix-sort-algorithm
Merge radix-sort-algorithm
 
DS Unit 1.pptx
DS Unit 1.pptxDS Unit 1.pptx
DS Unit 1.pptx
 
Array Presentation
Array PresentationArray Presentation
Array Presentation
 
data structures and algorithms Unit 3
data structures and algorithms Unit 3data structures and algorithms Unit 3
data structures and algorithms Unit 3
 
Data structures arrays
Data structures   arraysData structures   arrays
Data structures arrays
 
DS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and EngineeringDS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and Engineering
 
DSA - Array.pptx
DSA - Array.pptxDSA - Array.pptx
DSA - Array.pptx
 
Computer notes - Binary Search
Computer notes - Binary SearchComputer notes - Binary Search
Computer notes - Binary Search
 
Data structure
Data  structureData  structure
Data structure
 
Please help solve this in C++ So the program is working fin.pdf
Please help solve this in C++ So the program is working fin.pdfPlease help solve this in C++ So the program is working fin.pdf
Please help solve this in C++ So the program is working fin.pdf
 
computer notes - Data Structures - 32
computer notes - Data Structures - 32computer notes - Data Structures - 32
computer notes - Data Structures - 32
 
UNIT IV -Data Structures.pdf
UNIT IV -Data Structures.pdfUNIT IV -Data Structures.pdf
UNIT IV -Data Structures.pdf
 
lecture 10
lecture 10lecture 10
lecture 10
 
Arrays
ArraysArrays
Arrays
 
Searching
SearchingSearching
Searching
 
21CS32 DS Module 1 PPT.pptx
21CS32 DS Module 1 PPT.pptx21CS32 DS Module 1 PPT.pptx
21CS32 DS Module 1 PPT.pptx
 
Lec4
Lec4Lec4
Lec4
 
Data structure using c module 1
Data structure using c module 1Data structure using c module 1
Data structure using c module 1
 
Searching and sorting by B kirron Reddi
Searching and sorting by B kirron ReddiSearching and sorting by B kirron Reddi
Searching and sorting by B kirron Reddi
 

Recently uploaded

Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationAadityaSharma884161
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Romantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxRomantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxsqpmdrvczh
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 

Recently uploaded (20)

Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint Presentation
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Romantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxRomantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 

Address calculation-sort

  • 1. K.K. WAGH POLYTECHNIC, NASHIK-03 DEPARTMENT OF COMPUTER TECHNOLOGY(Second Shift) Demonstration of Address Calculation Sort
  • 2. Bucket sort, or bin sort, is a distribution sorting algorithm. It is a stable sort, where the relative order of any two items with the same key is preserved. It works in the following way:  set up m buckets where each bucket is responsible for an equal portion of the range of keys in the array.  place items in appropriate buckets.  sort items in each non-empty bucket using insertion sort.  concatenate sorted lists of items from buckets to get final sorted order. Analysis of running time of Bucket sort:  Best Case Complexity: O(n logn)  Worst Case Complexity: O(n2) Bucket Sort
  • 3. Example of Bucket Sort The example uses an input array of 9 elements. Key values are in the range from 10 to 19. It uses an auxiliary array of linked lists which is used as buckets. Items are placed in appropriate buckets and links are maintained to point to the next element. Order of the two keys with value 15 is maintained after sorting.
  • 4. n ← length [A] For i = 1 to n do Insert A[i] into list B[nA[i]] For i = 0 to n-1 do Sort list B with Insertion sort Concatenate the lists B[0], B[1], . . B[n-1] together in order. Algorithm of Bucket Sort
  • 5. Program for Bucket Sort #include<stdio.h> void Bucket_Sort(int array[], int n) { int i, j,k; int count[10][50]; for(i=0; i < 10; i++) { for(j=0;j<50;j++) count[i][j] = 0; } for(i=0,j=0; i < n; i++) { k=array[i]/10; j++; count[k][j]=array[i]; printf("ncount[%d][%d]=%d",k,j,array[i]); }
  • 6. for(i=0,j=0,k=0; i < n; i++) { for(j=0;j<50;j++) { if(count[i][j]>0) array[k++] = count[i][j]; } } } int main() { int array[100]; int num; int i; clrscr(); printf("Enter How many Numbers : "); scanf("%d",&num); Program for Bucket Sort
  • 7. printf("Enter the %d elements to be sorted:n",num); for(i = 0; i < num; i++ ) { scanf("%d",&array[i]); } printf("nThe array of elements before sorting : n"); for (i = 0;i < num;i++) { printf("%d ", array[i]); } printf("nThe array of elements after sorting :n"); Bucket_Sort(array, num); for (i = 0;i < num;i++) { printf("%d ", array[i]); } return 0; } Program for Bucket Sort
  • 8. Radix Sort Radix is the base of a number system or logarithm. Radix sort is a multiple pass distribution sort.  It distributes each item to a bucket according to part of the item's key.  After each pass, items are collected from the buckets, keeping the items in order, then redistributed according to the next most significant part of the key. This sorts keys digit-by-digit (hence referred to as digital sort), or, if the keys are strings that we want to sort alphabetically, it sorts character-by-character. Radix sort uses bucket or count sort as the stable sorting algorithm, where the initial relative order of equal keys is unchanged.
  • 9. Radix Sort Radix sort is classified based on how it works internally: least significant digit (LSD) radix sort: Processing starts from the least significant digit and moves towards the most significant digit. Most significant digit (MSD) radix sort: Processing starts from the most significant digit and moves towards the least significant digit. This is recursive. It works in the following way:
  • 10. Example of LSD-Radix Sort 12 44 41 34 11 32 23 Input is an array of 15 integers. For integers, the number of buckets is 10, from 0 to 9. The first pass distributes the keys into buckets by the least significant digit (LSD). When the first pass is done, we have the following. 23 44 34 12 42 32 41 11 0 1 2 3 4 5 6 7 8 9 5087 77 77 50 87 58 58 08 0842
  • 11. Example of LSD-Radix Sort…contd 50 We collect these, keeping their relative order: Now we distribute by the next most significant digit, which is the highest digit in our example, and we get the following. 11 12 23 32 34 41 42 44 When we collect them, they are in order. 12 42 444111 3223 34 12 42 4441 3411 32 23 77 58 08 0 1 2 3 4 5 6 7 8 9 50 877708 08 50 77 87 58 58 87
  • 12. #include <conio.h> #include <stdio.h> void main() { int unsorted[50] , bucket[10][50]={{0}} , sorted[50] ; int j , k , m , p , flag = 0, num, N; clrscr(); printf("nEnter the number of elements to be sorted :"); scanf("%d",&N); printf("nEnter the elements to be sorted :n"); for(k=0 ; k < N ; k++) { scanf("n%d",&num); sorted[k] = unsorted[k] = num; }
  • 13. for(p=1; flag != N ; p*=10) { flag = 0; for(k=0;k<N;k++) { printf("n flag=%d",flag); bucket[(sorted[k]/p)%10][k] = sorted[k]; printf("n position of element=%d %d",((sorted[k]/p)%10),k); printf("n element value=%d",bucket[(sorted[k]/p)%10][k]); if ( (sorted[k]/p)%10 == 0 ) { flag++; } }
  • 14. for(j=0,m=0;j<10;j++) { for(k=0;k<N;k++) { if( bucket[j][k] > 0 ) { sorted[m] = bucket[j][k]; bucket[j][k] = 0 ; m++; } } } } if (flag == N) { printf("nSorted List: n"); for(j=0 ; j < N ; j++) { printf("%dt", sorted[j]); } printf("n"); } getch() ; }
  • 15.  This can be one of the fastest types of distributive sorting technique if enough space is available also called as Hashing.  In this algorithm, a hash function is used and applied to each element in the list. The result of the hash function is placed in to an address in the table that represents the key.  Linked lists are used as address table for storing keys.(if there are 4 keys then 4 linked lists are used).  The hash function places the elements in linked lists are called as sub files. An item is placed into a sub-file in correct sequence by using any sorting method. After all the elements are placed into subfiles, the lists (subfies)are concatenated to produce the sorted list. Address Calculation Sort
  • 16. Procedure: 1. In this method a hash function f is applied to each key. 2. The result of this function determines into which of the several subfiles the record is to be placed. The function should have the property that: if x <= y , f (x) <= f (y), Such a function is called order preserving. 3. An item is placed into a subfile in correct sequence by using any sorting method – simple insertion is often used. 4. After all the elements are placed into subfiles, the lists (subfiles) are concatenated to produce the sorted list. Address Calculation Sort
  • 17. Example: 25 57 48 37 12 92 86 33 Let us create 10 subfiles (linked lists). Initially each of these subfiles is empty. Key. Address Calculation Sort 0 1 2 3 4 5 6 7 8 9
  • 18. Example: The number is passed to hash function, which returns its last digit (ten’s place digit), which is placed at that position only, in the linked lists. num= 25 - f(25) gives 2 57 - f(57) gives 5 48 - f(48) gives 4 37 - f(37) gives 3 12 - f(12) gives 1 92 - f(92) gives 9 86 - f(86) gives 8 33 - f(33) gives 3 which is repeated. Address Calculation Sort 0 1 2 3 4 5 6 7 8 9 25 57 48 33 12 92 86 37
  • 19. Example: After concatenating all linked list we get the sorted list. 12 25 33 37 48 57 86 92 Efficiency: If all the elements (n) are uniformly distributed over m subfiles then n/m is approximately 1, time of the sort is near O(n). On the other hand if maximum elements accommodate in one or two subfiles, then n/m is much larger significant work is required to insert element into proper subfile at its proper position and efficiency is O(n2). Address Calculation Sort