• 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

[email protected]

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

[email protected]

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

[email protected]

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

[email protected]

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