• No results found

Analysis and Performance of Various Algorithms

N/A
N/A
Protected

Academic year: 2022

Share "Analysis and Performance of Various Algorithms"

Copied!
5
0
0

Loading.... (view fulltext now)

Full text

(1)

Anshu Rawat

, IJRIT 516 www.ijrit.com ISSN 2001-5569

Analysis and Performance of Various Algorithms

Anshu Rawat1, Anu Jindal2, Diksha Mangla3, Diksha Taneja4

1Student, Computer Science, Dronacharya College of Engineering Gurgaon, Haryana, India

rawat.anshu1312@gmail.com

2Student, Computer Science, Dronacharya College of Engineering Gurgaon, Haryana, India

Shona281995@gmail.com

3Student, Computer Science, Dronacharya College of Engineering Gurgaon, Haryana, India

Dikshamangla13@gmail.com

4Student, Computer Science, Dronacharya College of Engineering Gurgaon, Haryana, India

Dikshataneja03@gmail.com

Abstract

In this paper, we would like highlight the Relation between searching and sorting. Sorting is a great topic in CS because it is simple and very important topic. If we know the logic of any program or coding, then we can implement the program easily. To design that type of algorithms that has efficient use in computer resources. How searching and sorting take place in program with the help of logic and example & we can calculate the Complexity from the program. The Research Paper Presents the different types of searching and sorting Like binary search and linear search in searching And Insertion sort, Quick sort and so many.

Keywords: - Coding, Complexity, Logic, Searching, Sorting

1. INTRODUCTION

Basically sorting takes two inputs: - one for elements and another for comparison procedure. It consists of same elements that are entered in the input list according to the comparison procedures. Sorting is one of the studied problems in computing, there are many types of sorting.

Sorting

Simple selection Bubble Sort Insertion Sort Quick Sort Merge Sort Radix Sort Fig.1

(2)

Anshu Rawat

, IJRIT 517

In Searching, We can solve any problem by defining the space of possible solutions, and then search that space to find a correct solution. We consider the more specific problem of efficiently searching for documents that contain some target word.

2. SEARCHING

LINEAR SEARCH SEARCHING

BINARY SEARCH Fig.2

2.1 LOGIC OF LINEAR SEARCH

 Accept the number to be searched as B

 Data[N+1]=ITEM;

 LOC=1;

 Repeat while Data[LOC]=1

 ITEM: LOC = LOC+1

 IF LOC=N+1,THEN

 LOC=0

 Exit.

2.2 LOGIC OF BI NARY SEARCH

Accept the number to be search as B

• The zeroth index of array is taken as LOW and index of last

Element of array is taken as HIGH

Take F=0

While(LOW<HIGH)

Take mid as mid =(LOW+HIGH)/2

If(A[MID]=B)

Then number is found at position mid+1and F=1

Else if(A[MID]>B) HIGH=MID-1

Else

LOW=MID+1

LOW=LOW+1

If F=0, then

the number is not found

• Exit

(3)

Anshu Rawat

, IJRIT 518 3. SORTING

SORTING

3.1 LOGIC OF INSERTION SORTING

 For (i=0 to i<n)

 K= A[i];

 For (j=i-1 to j>=0&& A[j]>K)

 A[j+1]=A[j];

 A]j]=K;

 The Array Become Sorted

 Exit.

Complexity: - T (n) =0(n2)

3.2 LOGIC OF SIMPLE SELECTION SORTING

i

j

4 3 5 2 1

1 4 5 3 2

1 2 5 4 3

1 2 3 5 4

1 2 3 4 5

Example of Simple selection Sorting

 For (i=0 to i<=n-2)

 For(j=i+1to j<=n-1)

 If(a[i]>a[j])

 T=a[i];

 a[i]= a[j];

 a[j]=t;

 The array become Sorted

 Exit

Complexity: - f (n) = 0(n2)

3.3 LOGIC OF BUBBLE SORTING

 For(i=0 to i<=n-2)

 For(j=0 to j<n-1-i)

 If(a[j]>a[j+1])

 T=a[j];

 a[j]=a[j+1];

SIMPLE SORT

MERGE SORT

INSERTION SORT

QUICK SORT

(4)

Anshu Rawat

, IJRIT 519

 a[j+1]=t;

 The array become sorted

 Exit

Complexity: - f (n) = 0(n2)

3.4 LOGIC OF MERGE SORTING

 Void Merge (int low, int high)

 If(low<high)

 Int mid= (low + high)/2

 Merge sort(low, mid);

 Merge sort(mid+1, high);

 Merge sort(low, mid, high);

 Void merge (int low, int mid, int high)

 int k= low;

 int i=low;

 int j= mid+1;

 While(k<=mid && j<=high)

 If(a[k]<=a[j])

 b[i++]=a[k++];

 Else

 b[i++]= a[j++];

 While(j<=high)

 b[i++]= a[j++];

 While(k<=mid)

 b[i++]= a[k++];

 For(k=low to k<=high)

 a[k]=b[k];

 The array become sorted

 Exit.

Complexity: - T (n)=0 (nlogn)

3.5 LOGIC OF QUICK SORT

lb mid ub

7 2 4 3 1

1 2 4 3 7

1 2 3 4 7

Example of Quick Sort

 Void quick_sort (int a[], int lb, int ub);

 int i= lb +1;

 int j= ub;

 int k= lb;

 int t;

 While(i<=j)

 While(a[i]<a[k])

 i++;

 While(a[j]>a[k] && j>lb)

 j--;

(5)

Anshu Rawat

, IJRIT 520

 if(i<j)

 t=a[i];

 a[i]=a[j];

 a[j]=t;

 i++;

 j--;

 if(j<i)

 t=a[k];

 a[k]=a[j];

 a[j]=t;

 if(lb<j-1)

 quick_sort(a, lb, j-1);

 if(ub>j+1)

 quick_sort(a, j+1, ub);

 void disp(int a[], int Len)

 int i;

 The array become sorted

 Exit.

Complexity: -

In best case: - T (2k) = 2kT + kcn In Worst case: - T (n) = 0(n2)

4. REFERNCES

1. http://www.cs.carleton.edu/

2. http://www.cs.ccsu.edu/

3. https://www.cs.auckland.ac

4. DATA STRUCTURES FOR C, G.S. Baluja

References

Related documents

RESULTS AND DISCUSSION 4.1 Sarawak Crude Oil 4.2 Soil Samples 4.3 Biodegradation of Crude Oil by NPSC, OPSC and B350M at Different Concentrations of Sodium Chloride 4.4

Insertion sort makes n – 1 compares and 0 exchanges to sort an array of n distinct keys in ascending order.

Searching an EndNote Library Advanced Search Pane. To sort library, click on any

In mice subjected to PSNL, repeated once daily intrathecal injection of TAT-GESV (10 nmol i.t.) and MK-801 (5 nmol i.t.) across eight consecutive days elevated (A) mechanical

The research will discuss and implement several sorting algorithms such as bubble sort, selection sort, insertion sort and will also include complexity sort such as quick

4.8 Louis Stellman, untitled (American and Chinese flags), ca. Courtesy of the California History Room, California State Library, Sacramento, California... The boldness and agency

Present an estimate of the total costs of the project for specific activities to enhance knowledge sharing that do not require research: travelling, durables, consumables and

Finally, we provided a proof-of-concept by combining rep B and placI for expression of GFP gene in Shewanella , and followed by demonstrated expression of Mtr path- way as