Topic 9: Constructor: DEFINITION: A Constructor Is A Special Method That Is Used To Initialize A
Topic 9: Constructor: DEFINITION: A Constructor Is A Special Method That Is Used To Initialize A
using System;
namespace Constructor
class paraconstrctor
public int a, b;
a = x;
b = y;
class MainClass
{
static void Main()
Console.WriteLine("-----------
parameterized constructor example by vithal wadje---------------");
Console.WriteLine("\t");
Console.Read();
Default Constructor
A constructor without any parameters is called a default constructor; in
other words this type of constructor does not take parameters. The
drawback of a default constructor is that every instance of the class will
be initialized to the same values and it is not possible to initialize each
instance of the class to different values. The default
constructor initializes:
Linear search
BINARY SEARCH
DEFINITION: Binary Search is a searching technique used to search an
element in a sorted array. In this article, we will learn about how to
implement Binary Search in PHP using iterative and recursive way. Given a
array of numbers, we need to search for the presence of element x in the
array using Binary Search.
TOPIC 14: SORTING
BUBBLE SORT
DEFINITION: Bubble sort, sometimes referred to as sinking sort, is a
simple sorting algorithm that repeatedly steps through the list, compares
adjacent pairs and swaps them if they are in the wrong order. The pass
through the list is repeated until the list is sorted. The algorithm, which is
a comparison sort, is named for the way smaller or larger elements
"bubble" to the top of the list. Although the algorithm is simple, it is too slow
and impractical for most problems even when compared to insertion
sort.[2] Bubble sort can be practical if the input is in mostly sorted order with
some out-of-order elements nearly in position.
int main()
{
int a[50],n,i,j,temp;
printf("Enter the size of array: ");
scanf("%d",&n);
printf("Enter the array elements: ");
for(i=0;i<n;++i)
scanf("%d",&a[i]);
for(i=1;i<n;++i)
for(j=0;j<(n-i);++j)
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
return 0;
}
SELECTION SORT
DEFINITION: In computer science, selection sort is a sorting algorithm,
specifically an in-place comparison sort. It has O(n2) time complexity,
making it inefficient on large lists, and generally performs worse than the
similar insertion sort. Selection sort is noted for its simplicity, and it has
performance advantages over more complicated algorithms in certain
situations, particularly where auxiliary memory is limited.
The algorithm divides the input list into two parts: the sublist of items
already sorted, which is built up from left to right at the front (left) of the list,
and the sublist of items remaining to be sorted that occupy the rest of the
list. Initially, the sorted sublist is empty and the unsorted sublist is the entire
input list. The algorithm proceeds by finding the smallest (or largest,
depending on sorting order) element in the unsorted sublist, exchanging
(swapping) it with the leftmost unsorted element (putting it in sorted order),
and moving the sublist boundaries one element to the right.
// Logic of selection sort algorithm
for(i=0;i<count;i++){
for(j=i+1;j<count;j++){
if(number[i]>number[j]){
temp=number[i];
number[i]=number[j];
number[j]=temp;
}
}
}
return 0;
}
BIBLIOGRAPHY
WWW.google.com
WWW.wikipedia.com
WWW.javapoint.com
Computer science with java- Sumitra Arora
INDEX
SL NO TOPIC PAGE NUMBER
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.