Thursday, 8 June 2023

What is Chat GPT

 What is Chat GPT


Chatbot GPT (Generative Pre-prepared Transformer) alludes to a conversational simulated intelligence model created by OpenAI. GPT models, for example, GPT-3.5, are prepared utilizing tremendous measures of text information to create human-like reactions in regular language. These models are intended to comprehend and produce text, making them appropriate for taking part in discussions with clients.

Visit GPT is explicitly enhanced for talk based cooperation's and can give reactions, answer questions, give ideas, and take part in a large number of conversational errands. It use profound learning strategies, including transformer designs, to process and grasp the setting of a discussion and create important and sound reactions.

The preparation interaction includes presenting the model to different sorts of message information, like books, articles, sites, and discussions, permitting it to learn examples, semantics, and language structures. GPT models don't approach constant data and depend exclusively on the information gained during their preparation, which has a particular information cutoff date.

Visit GPT models plan to reproduce human-like discussions and give helpful and instructive reactions to clients' questions. In any case, it's vital to take note of that they depend on measurable examples as opposed to genuine comprehension, and their reactions ought to be checked and basically assessed when utilized in commonsense applications.

Monday, 26 August 2019

hotal advertisement program in html #Hotel Oberoi Palace

<HTML>
<HEAD>
<script data-ad-client="ca-pub-1059090032851162" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
</HEAD>
<BODY>
<CENTER>
<H1>Hotel Oberoi Palace</H1>
</center>
<P>
These pages are indented to advertise our hotels strikingt features <h2>Accomodation<HR ALIGN=LEFT WIDTH="25%"></H2>
<PRE>
Single room        Rs.  12000
Double room        Rs.  14000
Classic room        Rs.  17000
</PRE>

<h2>Prominent Features <HR ALIGN=LEFT WIDTH="35%"></H2>
<OL TYPE = a>
<li>Open 24 hours
<li>Free Medical services
<li>Specious car parking
<li>Satellite televisions
<li>Giant shopping complex
<li>Swimming pool
<li>Gymnasium
<li>Van and car rental
<li>Individual air-conditioning
</ol>
<P>
<H2>Business Facilities<HR ALIGN=LEFT WIDTH="32%"></H2>
<OL TYPE = i>
<LI>Telephone
<li>Fax
<li>E-mail
<li>Telex
<li>Conference rooms
</ol>
<h2>Mode of Payment <HR ALIGN=LEFT WIDTH="30%"></H2>
<UL>
<LI><I>Cash
<li><i>Cheque
<li><iS>All Major Credit LCArds
</ul>
<h2f><i>Conference room - seating capacity</I><h2>
<TABLE BORDER =20>
<TR><TH>Room<th>Seating capacity
<tr><td><i>Croom 1</I><TD ALIGN = CENTER><I>500</i>
<TR><tD><I>Theater</i><TD ALIGN = CENTER><I>700</I>
<TR><TD><I>hall</i><TD ALIGN = CENTER><I>300</I>
<TR><TD><I>Croom2</i><TD ALIGN = CENTER><I>500></I>
</TABLE>
<H2><I>Dining Facilities</i></H2>
<ul>
<LI><i>Roof Garden (after 7 p.m.) </i>
<li><i>24 hour Restaurant</i>
<UL TYPE = CIRCLE>
<LI>Bakery
<li>Chat
<li>Chinese
<li>Indian
<li>Thandori
<li>Ice creams
<li>Milk Shakes
</ul>
<p>
For reservations &amp; suggestions,contact the following address:
<p>
<address>
E-mail : OBE@humchi09.vsnl.net
<br>
phone : (044) 6794348 &amp; 6794374
<br>
Fax : (044) 6791321
<br>
<HR NOSHADE WIDTH="100%">
</ADDRESS>
</BODY>
</HTML>

<script data-ad-client="ca-pub-1059090032851162" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>

product purchase and registration in html #chirag


<HTML>
<HEAD>
   <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
   <META NAME="GENERATOR" CONTENT="Mozilla/4.04 [en]C-NE  (Win95; I) [Netscape]">
   <TITLE> CHIRAG INTERNET</TITLE>
</HEAD>
<BODY BGCOLOR="#C0C0C0">

<CENTER>
<H2>
<U><FONT COLOR="#000000">POPULAR CONSUMER GOODS</FONT></U></H2></CENTER>

<HR>
<BR><FONT SIZE=+1>REGISTRATION DETAILS ON YOUR PURCHASE</FONT>
<ADDRESS FONT: 18PT ARIAL; COLOR: "RED">
NAME&nbsp;<INPUT TYPE =TEXT NAME = ID SIZE = 20></ADDRESS>

<BR>ENTER THE ADDRESS
<BR><TEXTAREA NAME = ARTICLES ROWS =5 COLS=20></TEXTAREA>
<BR>E-MAIL&nbsp;<INPUT TYPE = TEXT NAME = E-MAIL SIZE 20>
<BR>TEL NO&nbsp;<INPUT TYPE = TEXT NAME = TELNO SIZE = 20>
<BR>FAX&nbsp;<INPUT TYPE = TEXT NAME =FAX SIZE 20>
<H4>
LIST THE PRODUCTS FORM THE PURCHASE</H4>
<SELECT SIZE = MULTIPLE NAME = "PRODUCT LISRT"><OPTION VALUE = " "></OPTION><OPTION VALUE = " ">CONFECTIONERIES&nbsp;</OPTION><OPTION VALUE = " ">COSMETICS&nbsp;</OPTION><OPTION VALUE = " ">GIFT
ARTICLES&nbsp;</OPTION><OPTION VALUE = " ">GROCERY&nbsp;</OPTION><OPTION VALUE = " ">VEGETABLES&nbsp;</OPTION><OPTION VALUE = " ">STATIONERY&nbsp;</OPTION><OPTION VALUE = " ">TOILETRIES&nbsp;</OPTION><OPTION VALUE = " ">AUDIO/VIDEO</OPTION>
<BR></SELECT>
<H4>
ENTER THE NAME OF THE PRODUCTS TO BE PURCHASED</H4>
<TEXTAREA NAME = ARTICLES ROW =5 COLS 25></TEXTAREA>
</BODY>
</HTML>

supermarket #deep1

<HTML>
<HEAD>
<TITLE>SuperMarket</TITLE>
</HEAD>
<FRAMESET COLS="40%,60%">
<FRAMESET ROWS="50%,50%">
<FRAME SRC="SAMPLE3.HTML">
<FRAME SRC="SAMPLE2.HTML">
</FRAMESET>
<FRAME SRC="SAMPLE1.HTML">
</FRAMESET>
</HTML>

supermarket #deep4

<HTML>
<HEAD>
<TITLE>SuperMarket</TITLE>
</HEAD>
<FRAMESET COLS="40%,60%">
<FRAMESET ROWS="50%,50%">
<FRAME SRC="SAMPLE3.HTML">
<FRAME SRC="SAMPLE2.HTML">
</FRAMESET>
<FRAME SRC="SAMPLE1.HTML">
</FRAMESET>
</HTML>

supermarket #deep3

<HTML>
<HEAD>
<TITLE>SuperMarket</TITLE>
</HEAD>
<FRAMESET COLS="40%,60%">
<FRAMESET ROWS="50%,50%">
<FRAME SRC="SAMPLE3.HTML">
<FRAME SRC="SAMPLE2.HTML">
</FRAMESET>
<FRAME SRC="SAMPLE1.HTML">
</FRAMESET>
</HTML>

supermarket #deep2



<HTML>
<HEAD>
<TITLE>SuperMarket</TITLE>
</HEAD>
<FRAMESET COLS="40%,60%">
<FRAMESET ROWS="50%,50%">
<FRAME SRC="SAMPLE3.HTML">
<FRAME SRC="SAMPLE2.HTML">
</FRAMESET>
<FRAME SRC="SAMPLE1.HTML">
</FRAMESET>
</HTML>

How to set background color in html #background

How to set background color in html

<body bgcolor=#000000>
<h1 align=center>welcome to wais<hr size=3 width="50%"></h1>
<blockquote>
<font color=#FFFFFF>
<font size=+1>
<p>
wais stands for wide area information service.
</font>
</font>
</blockquote>
</body>




Shows the use of special characters code #specialcharacters

Shows the use of special characters code


<!-this example shows use of special characters code>
<body>
<h2><b>list of html<b>tags</b></h2>
<p>
<ol>
<li>&lt;html&gt;
<li>&lt;head&gt;
<li>&lt;body&gt;
<li>&lt;i&gt;
<li>&lt;b&gt;
<li>&lt;cite&gt;
</ol>
</body>

NESTED FRAMES 2 IN HTML

NESTED FRAMES 2 IN HTML


<html>
<head>
<title>  frames </title>
</head>
<frameset cols="30%,20%,*"noresize>
<frameset rows="30%,20%,*"noresize>
<frame src="demo.html" >
<frame src="demo1.html" >
<frame src="demo.html" >
</frameset>
<frame src="demo.html" >
<frame src="demo1.html" >
</frameset>
</html>

NESTED FRAMES IN HTML#nested frames

NESTED FRAMES IN HTML


<html>
<head>
<title> nested frames </title>
</head>
<frame src="chirag.html" noresize>
<frameset cols="45%,*">
<frame src="demo.html" noresize scrolling=auto>
<frame src="demo1.html" noresize scrolling=no>
</frameset>
</frameset>
<noframes>
<h3>
iiiiiiiiiiiiiiiiiiiiii
</h3>
</noframes>
</html>

internet host naming conventions#table

internet host naming conventions


<body>
<h2>internet host naming conventions</h2>
<p>
<strong><em>internet host mostly referred by names</em></strong>
<p>
the following table lists the zone names
<br>
<table border=15 cellpadding=15 cellspacing=8>
<caption align=top>
<h3><blink><font color="#FFFFFF">three letter zone names</font></blink></h3>
</caption>
<tr>
<th>zone
<th>meaning
<tr>
<td><i><font size=-1>com</font></i>
<td><i><font size=-1>commercial organizations</font></i>

<tr>
<td><i><font size=-1>com</font></i>
<td><i><font size=-1>government body &amp;</font></i>

<tr>
<td><i><font size=-1>com</font></i>
<td><i><font size=-1>military sites</font></i>

<tr>
<td><i><font size=-1>com</font></i>
<td><i><font size=-1><a href=demo.html> aaaa</a></font></i>
</table>
</body>

SUPER MARKET PROGRAM IN HTML#form

 FORM OF SUPER MARKET


<html>
<head>
<title>about forms</title>
</head>
<form action=/cgi/get-inf method=post>
<center><h1>galaxy supermarket </h1></center>
<p><i>hi guys!! you can purchase using this web page in a fraction of a second</i>
<p><b><tt><blink>please fill in this page </blink></tt></b>

<pre>
name   <input type=text name=id size=10><br>
address <input type=text name=address size=17><br>
tel no <input type=text name=telno size=10><br>
</pre>
<hr>
<p><h3>mode of payment</h3>
<pre>
credit card <input type=radio name=credit ><br>
identity no<input type=password name=idno size=10><br>
cheque<input type=radio name=cheque><br>
cash  <input type=radio name=cash>
</pre>

<hr>
<p>choose the products from the list provided
<p><select size=5 name=choice multiple>
<option>c101 confectioneries
<option>c102 groceries
<option>c103 gifts
<option>c104 toiletries
<option>c105 miscellaneous
<option>c106 toys
<option>c107 cosmetics
</select>
<p><hr>enter the name of the products to be purchased
<p><textarea name=articles rows=10 cols=65>
</textarea>
<p>
<hr>

<p>
is your first visit! <input type =checkbox name=visit>
<p>thanks for your order
<p><input type=submit name=submit value=sendorder>
<p><input type=reset name=reset value=clear>
</form>
</body>
</html>




FRAME SET 2 IN HTML#demo5

FRAME SET 2 IN HTML

<HTML>
<HEAD>
<TITLE>SuperMarket</TITLE>
</HEAD>
<FRAMESET COLS="40%,60%">
<FRAMESET ROWS="50%,50%">
<FRAME SRC="SAMPLE3.HTML">
<FRAME SRC="SAMPLE2.HTML">
</FRAMESET>
<FRAME SRC="SAMPLE1.HTML">
</FRAMESET>
</HTML>

super market frame set#demo4

 SUPER MARKET FRAME SET

<HTML>
<HEAD>
<TITLE>SuperMarket</TITLE>
</HEAD>
<FRAMESET COLS="40%,60%">
<FRAMESET ROWS="50%,50%">
<FRAME SRC="SAMPLE3.HTML">
<FRAME SRC="SAMPLE2.HTML">
</FRAMESET>
<FRAME SRC="SAMPLE1.HTML">
</FRAMESET>
</HTML>

FRAME SET IN HTML #demo3

 FRAME in html


<html>
<frameset cols="30%,20%">
<frameset rows="50%,50%">
<frame src="chirag.html">
<frame src="demo1.html">
</frameset>
<frame src="demo.html">
</frameset>
</html>

WRITE A PROGRAM IN HTML TO INSERT IMAGE #demo1

 WRITE  A PROGRAM IN HTML TO INSERT IMAGE

 <html>
<head>
<img src= "c:\ORAWIN95\NET80\NET8ASST\IMAGES\create.gif" \\it is the location of your image file location in your system
hspace=4 border=1 height=400
width=300 align=top>
hellow
</font>
</head>
</html>

Write a html program to define tags #demo

Write a html program to define tags 

 

<html>

<a name="bf">  this is a book mark in the first file  </a>

<h1> heading 1</h1>
<hr>
<h2> heading 2</h2>
<h3> heading 3</h3>
<h4> heading 4</h4>
<h5> heading 5</h5>
<h6> heading 6</h6>
<p> indicates a paragraph break this is a paragraph
<br> indicates a line break this is  a line break
this is a normal text
<pre>
             this is a preformatted text
</pre>
<a name="bbbb"> this is another bookmark </a>
<block quote>
 this is another blockquoted text
uhurehyuhyugthyuhyt
</block quote>
<hr>
<br>
<i> this is a italic text</i>
<br>
<br>
<u> this is a underlined text</u>
<br>
<br>
<b> this is a boldtext</b>
<br>
<br>
<em> this is a emphasized text</em>
<br>
<br>
<tt> this is a type written text</tt>
<br>
<br>
<br>
<Strong>type val  strong bold font
font
text
</Strong>
<br>
<br>
<cite>
<cite> highlighted citation text
</cite>
<br>
this is a <sub>subscripted</sub> text
<br>
<br>
this is a <super>superscripted</super> text
<br>
list ordered
<ol>
<li> first
<li> second
<li> third
<li> fourth
<li> fifth
<li> sixth
</ol>
<br>
list unordered
<ul>
<li> first
<li> second
<li> third
<li> fourth
<li> fifth
<li> sixth
</ul>
<br>
<dl>
<dt>
<dt> soup
   <dd> tomato
   <dd> minestorme
   <dd> sweetcurd
<dt>snacks
    <dd> tomtoes
    <dd> Mine storme
    <dd> sweetcurd
    </dl>
    <br>
    <a href="#bf"> this is a normal link to the samefile </a>
    <br>
    <a href="#bf"> this is normal link to samefile</a>
    <br>
    <a href="chirag.html">
    this is a bookmark link to the second file
    gggggggg
     </a>
     <br>
     <a href="#bbbb"> xxxxxxx</a>
     <br>
     <address>
                    this is the author's address in unique format
     </address>
     <br>
     </html>











Friday, 5 April 2019

SEARCHING (Design & Analysis of Algorithms)

SEARCHING

Searching is an operation of data structure to search an item in a list. There are 3 types of searching methods:- Linear search, Binary search, Hashing .

Linear Search:-
In this method the item search in a sequential order starting from 0 index and stop until the last index or the item found.

WAP to search an item using linear search.



#include<stdio.h>
#define MAX 20
int lsearch(int[],int,int);
void main()
{    int a[MAX],n,item,i;
 printf("\nEnter number of element in array:");
 scanf("%d",&n);
 printf("\nEnter %d elements:",n);
 for(i=0;i<n;i++)
              scanf("%d",&a[i]);
 printf("\nEnter the search item:");
 scanf("%d",&item);
 i=lsearch(a,n,item);
 if(i>=0)
    printf("\n%d is at index number %d",item,i);
else
     printf("\n%d is not found",item);
 return 0;
}

int lsearch(int a[],int n,int item)
{             int i;
              for(i=0;i<n;i++)
              {
                             if(a[i]==item)
                                           return i;
              }
              return -1;
}











Binary Search

ž  Binary search algorithm assumes that the items in the list being searched are sorted.
ž  The algorithm begins at the middle of the list in a binary search.
ž  We compare between the search item and the middle element of the array. If match return the index number.
ž  If the item for which we are searching is less than the item in the middle, we know that the item won’t be in the second half of the list.  If the item for which we are searching is greater than the item in the middle, we know that the item won’t be in the first half of the list.
ž  The process continues with each comparison cutting in half the portion of the list where the item might be.
ž  The time complexity of this algorithm is O(log n)

Algorithm to Binary Search

BSearch(A,n,item)
Step 1:- Set low=0
              Set high=n-1;
Step 2:- Repeat step 3 to 9 until low<=high
Step 3:-               Set mid=(low+high)/2
Step 4:-               if (item== A[mid] ) then
Step 5:-                             return mid
Step 6:-               else if( item < A[mid] ) then
Step 7:-                             high=mid -1
Step 8:-               else
Step 9:-                             low=mid + 1
                             [End if]
                 [End loop]
Step 10:- return -1
Step 11:- End

WAP to search an item in a sorted list using binary search.


#include<stdio.h>
#define MAX 20
int bsearch(int[],int,int);
void main()
{
  int a[MAX],n,item,i;
  printf("\nEnter number of element in array:");
  scanf("%d",&n);
  printf("\nEnter %d elements:",n);
  for(i=0;i<n;i++)
              scanf("%d",&a[i]);
  printf("\nEnter the search item:");
  scanf("%d",&item);
  i=bsearch(a,n,item);
  if(i>=0)
    printf("\n%d is at index number %d",item,i);
  else
              printf("\n%d is not found",item);
}
int bsearch(int a[],int n,int item)
{             int l,u,m;
              l=0;u=n-1;
              while(l<=u)
              {             m=(l+u)/2;
                             if(item==a[m])
                                           return m;
                             else if(item<a[m])
                                           u=m-1;
                             else
                                           l=m+1;
              }
              return -1;
}



                                     THANK YOU

SORTING (Design & Analysis of Algorithms)

SORTING

Sorting is an operation of data structure to arrange the data elements in an order either in increasing (ascending) order or decreasing (descending) order.

 Example:
              {2, 1, 5, 3, 2} ®{1, 2, 2, 3, 5}  ascending order
              {2, 1, 5, 3, 2} ®{5, 3, 2, 2, 1}  descending order

Types of Sorting Algorithm
There are several sorting algorithms are used.
       Bubble sort
       Selection sort
       Insertion sort
       Merge sort
       Quick sort
       Heap sort
       Radix Sort
       Address Calculation Sort

Bubble Sort
Traverse a collection of elements
       Move from the front to the end
       “Bubble” the largest value to the end using pair-wise comparisons and swapping.
After one pass only the largest value is correctly placed. All other values are still out of order.
So we need to repeat this process. If we have N elements and if each time we bubble an element, we place it in its correct location. Then we repeat the “bubble up” process N – 1 times.
Arrange the following elements in ascending order using bubble sort
12, 36, 27, 11, 40, 24, 23, 30

Pass 0:
  1. Compare 12 with 36, no change
  2. Compare 36 with 27, swap  so elements are :- 12, 27, 36, 11, 40, 24, 23, 30
  3. Compare 36 with 11, swap so elements are :- 12, 27, 11, 36, 40, 24, 23, 30
  4. Compare 36 with 40, no change
  5. Compare 40 with 24, swap so elements are :- 12, 27, 11, 36, 24, 40, 23, 30
  6. Compare 40 with 23, swap so elements are :- 12, 27, 11, 36, 24, 23, 40, 30
  7. Compare 40 with 30, swap so elements are :- 12, 27, 11, 36, 24, 23, 30, 40

At the end of pass 1 the largest element store at last index number.

Pass 1:
12, 27, 11, 36, 24, 23, 30, 40       - no change
12, 27, 11, 36, 24, 23, 30, 40       - swap
12, 11, 27, 36, 24, 23, 30, 40       - no change
12, 11, 27, 36, 24, 23, 30, 40       - swap
12, 11, 27, 24, 36, 23, 30, 40       - swap
12, 11, 27, 24, 23, 36, 30, 40       - swap
12, 11, 27, 24, 23, 30, 36, 40

Pass 2:
12, 11, 27, 24, 23, 30, 36, 40
11, 12, 27, 24, 23, 30, 36, 40
11, 12, 27, 24, 23, 30, 36, 40
11, 12, 24, 27, 23, 30, 36, 40
11, 12, 24, 23, 27, 30, 36, 40
11, 12, 24, 23, 27, 30, 36, 40

Pass 3:
11, 12, 24, 23, 27, 30, 36, 40
11, 12, 24, 23, 27, 30, 36, 40
11, 12, 24, 23, 27, 30, 36, 40
11, 12, 23, 24, 27, 30, 36, 40
11, 12, 23, 24, 27, 30, 36, 40

Pass 4:
11, 12, 23, 24, 27, 30, 36, 40
11, 12, 23, 24, 27, 30, 36, 40
11, 12, 23, 24, 27, 30, 36, 40
11, 12, 23, 24, 27, 30, 36, 40

Pass 5:
11, 12, 23, 24, 27, 30, 36, 40
11, 12, 23, 24, 27, 30, 36, 40
11, 12, 23, 24, 27, 30, 36, 40

Pass 6:
11, 12, 23, 24, 27, 30, 36, 40
11, 12, 23, 24, 27, 30, 36, 40       - elements are in increasing order

So we need n number of passes start from 0 to n-1
In each pass we ( n-1-pass) number of comparisons.



 
WAP to sort an array using bubble sort.

#include<stdio.h>
void bubble_sort(int [], int);
void main()
{             int a[20],n,i;
printf(“\nenter number of elements to store in array”);
scanf(“%d”,&n);
printf(“\nenter %d elements”,n);
for(i=0;i<n;i++)
              scanf(“%d”,&a[i]);
printf(“\nbefore sort the elements are:\n”);
for(i=0;i<n;i++)
              printf(“\t%d”,a[i]);
bubble_sort(a,n);
printf(“\nafter sort the elements are:\n”);
for(i=0;i<n;i++)
              printf(“\t%d”,a[i]);
}
void bubble_sort(int a[],int n)
{             int pass, i, t;
for(pass=0;pass<n-1;pass++)
{             for(i=0;i<n-1-pass;i++)
{             if(a[i]>a[i+1])
{             t=a[i];
                                                         a[i]=a[i+1];
                                                         a[i+1]=t;
}
}
}
}


Selection Sort
Selection sort algorithm is easy to understand. Sorts an array by making several passes through the array, selecting the next smallest item in the array each time and placing it where it belongs in the array. From the array find out the smallest element from a[0] to a[n-1] and replace with a[0] location, then find out the smallest element from a[1] to a[n-1] and replace with a[1] location and so on.
Time complexity is O(n2).
Arrange the following elements in ascending order using bubble sort
12, 36, 27, 11, 40, 24, 23, 30
Pass 0   :-            12, 36, 27, 11, 40, 24, 23, 30
Pass 1   :-            11, 36, 27, 12, 40, 24, 23, 30
Pass 2   :-            11, 12, 27, 36, 40, 24, 23, 30
Pass 3   :-            11, 12, 23, 36, 40, 24, 27, 30
Pass 4   :-            11, 12, 23, 24, 40, 36, 27, 30
Pass 5   :-            11, 12, 23, 24, 30, 36, 27, 40
Pass 6   :-            11, 12, 23, 24, 30, 27, 36, 40
Pass 7   :-            11, 12, 23, 24, 30, 27, 36, 40
Elements after pass 7 - 11, 12, 23, 24, 30, 27, 36, 40 are in increasing order.

WAP to sort an array using selection sort.

#include<stdio.h>
void selection_sort(int [], int);
void main()
{             int a[20],n,i;
printf(“\nenter number of elements to store in array”);
scanf(“%d”,&n);
printf(“\nenter %d elements”,n);
for(i=0;i<n;i++)
              scanf(“%d”,&a[i]);
printf(“\nbefore sort the elements are:\n”);
for(i=0;i<n;i++)
              printf(“\t%d”,a[i]);
selection_sort(a,n);
printf(“\nafter sort the elements are:\n”);
for(i=0;i<n;i++)
              printf(“\t%d”,a[i]);
}
void selection_sort(int a[],int n)
{             int i,j,pos,min;
for(i=0;i<n-1;i++)
{             min=a[i];
              pos=i;
              for(j=i+1;j<n;j++)
              {             if(a[j]<min)
                             {             min=a[j];
                                           pos=j;
                             }
               }
               a[pos]=a[i];
               a[i]=min;
}}
Insertion Sort
Based on technique of card players to arrange a hand
       Player keeps cards picked up so far in sorted order
       When the player picks up a new card
  Makes room for the new card
  Then inserts it in its proper place


For each array element from the second to the last (nextIndex = 1), Insert the element at nextIndex where it belongs in the array, increasing the length of the sorted sub array by 1.
The number of shifts performed during an insertion is one less than the number of comparisons or, when the new value is the smallest so far, the same as the number of comparisons.


WAP to sort an array using insertion sort.

#include<stdio.h>
void insertion_sort(int [], int);
void main()
{
int a[20],n,i;
printf(“\nenter number of elements to store in array”);
scanf(“%d”,&n);
printf(“\nenter %d elements”,n);
for(i=0;i<n;i++)
              scanf(“%d”,&a[i]);
printf(“\nbefore sort the elements are:\n”);
for(i=0;i<n;i++)
              printf(“\t%d”,a[i]);
insertion_sort(a,n);
printf(“\nafter sort the elements are:\n”);
for(i=0;i<n;i++)
              printf(“\t%d”,a[i]);
}
void insertion_sort(int a[],int n)
{
int i,index,key;
for(index=1;index<n;index++)
{
key=a[index];
              i=index-1;
              while((i>-1)&&(a[i]>key))
              {
                            a[i+1]=a[i];
                             i--;
              }
              a[i+1]=key;
}
}
Divide and Conquer Technique
  1. Divide the problem into two or more similar and smaller subproblems
  2. Recursively solve the subproblems
  3. Combine solutions to the subproblems
The following two sorting method use this technique.
  1. Quick Sort
  2. Merge Sort
Quick sort
       Quick sort divided an array into two parts so that all the elements in the left sub array are less than or equal to a specified value, called the pivot and all elements in the right sub array are greater than from the pivot element.
       We can take any element p as the pivot (generally we take the first element as pivot element).
Partition the remaining elements into two part:-
First Part,         which contains all elements < p
Second Part,    which contains all elements ≥ p
       Recursively sort the First Part and Second Part


Algorithm for Quick sort
Quick_Sort(A, low, high)
Step 1:- if low < high then
Step 2:-               mid= Partition (A, low, high)
Step 3:-               Quick_Sort(A, low, mid–1 )
Step 4:-               Quick_Sort(A, mid+1, high)
              [End if ]
Step 5:- end

Algorithm for Partitioning
Partitioning (A, low, high)
  1. Set pivot value to A[low]
  2. Set i to low and j to high
  3. While (i<j)
  4.       While A[i] < pivot, Increment i
  5.       While A[j] >= pivot, Decrement j
  6.        If i < j, swap A[i] and A[j]
End Loop
  1. Swap A[low] and A[j]
  2. Return j 

Arrange the following elements in ascending order using quick sort.
50, 30, 20, 60, 40, 10, 30, 55

Pass - 1
Select 50 as pivot element. Comparison starts from left to right to find the element greater than from 50. So 60 > 50 (i = 3).  Comparison start from right to left and finds the element less than from 50. So 30 < 50 (j = 5). Then swap between 60 and 30. So elements are 50, 30, 20, 30, 40, 10, 60, 55
Again repeat. 60 > 50 ( I = 6 ), and 10 < 50 ( j= 5 ), but i is not less than j. so swap between 10 and 50. So after pass – 1 elements are:-
10, 30, 20, 30, 40, 50, 60, 55
Pass 2:- 10, 30, 20, 30, 40, 50, 60, 55
Pass 3:- 10, 20, 30, 30, 40, 50, 55, 60

WAP to sort an array using quick sort.

#include<stdio.h>
void quick_sort(int [], int, int);
int partition(int [ ], int, int);
void main()
{             int a[20],n,i;
printf(“\nenter number of elements to store in array”);
scanf(“%d”,&n);
printf(“\nenter %d elements”,n);
for(i=0;i<n;i++)
              scanf(“%d”,&a[i]);
printf(“\nbefore sort the elements are:\n”);
for(i=0;i<n;i++)
              printf(“\t%d”,a[i]);
quick_sort(a,n);
printf(“\nafter sort the elements are:\n”);
for(i=0;i<n;i++)
              printf(“\t%d”,a[i]);
}
void quick_sort(int a[],int low,int high)
{             int mid;
              if(low<high)
              {             mid=partition(a,low,high);
                             quick_sort(a,low,mid-1);
                             quick_sort(a,mid+1,high);
              }
}
int partition(int a[ ], int low, int high)
{             int pivot,  i, j, t;
              pivot=a[low];
              i=low+1;
              j=high;
              while(i<j)
              {
                             while(a[i]<pivot)
                                           i++;
                             while(a[j]>pivot)
                                           j--;
                             if(i<j)
                             {
                                           t=a[i];
                                           a[i]=a[j];
                                           a[j]=t;
                             }
              }
              a[low]=a[j];
              a[j]=pivot;
              return j;
}


Merge Sort
Merge Sort: Algorithm
Merge_Sort (A, low, high)
Step -1:-    if (low < high   )
Step- 2:-              mid = (low + high)/2
Step- 3:-              Merge_Sort(A, low, mid)
Step- 4:-              Merge_Sort(A, mid+1,high)
Step- 5:-              Merge(A, low, mid, high)
              [End if]
Step-6:- End
Merge Algorithm
       Access the first item from both sequences
       While not finished with either sequence
  Compare the current items from the two sequences, copy the smaller current item to the output sequence, and access the next item from the input sequence whose item was copied
       Copy any remaining items from the first sequence to the output sequence
       Copy any remaining items from the second sequence to the output sequence



 WAP to sort an array using merge sort.

#include<stdio.h>
#define SIZE 20
void merge_sort(int [], int, int);
void merge(int [],int, int, int);
void main()
{
int a[SIZE],n,i;
printf(“\nenter number of elements to store in array”);
scanf(“%d”,&n);
printf(“\nenter %d elements”,n);
for(i=0;i<n;i++)
              scanf(“%d”,&a[i]);
printf(“\nbefore sort the elements are:\n”);
for(i=0;i<n;i++)
              printf(“\t%d”,a[i]);
merge_sort(a,n);
printf(“\nafter sort the elements are:\n”);
for(i=0;i<n;i++)
              printf(“\t%d”,a[i]);
}
void merge_sort(int a[], int low, int high)
{             if (low < high)
{
mid = (low + high)/2 ;
merge_sort(a, low, mid);
merge_sort(a, mid+1,high);
merge(a, low, mid, high);
              }
}
void merge(int a[],int low,int mid,int high)
{
              int b[SIZE],i,j,k;
              i=low;
              j=mid+1;
              k=low;
              while((i<=mid) && (j<=high))
              {
                             if(a[i] < a[j])
                             {
                                           b[k]=a[i];
                                           k++;
                                           i++;
                             }
                             else
                             {
                                           b[k]=a[j];
                                           k++;
                                           j++;
                             }
              }            
              while(i<=mid)
              {
                             b[k]=a[i];
                             k++;
                             i++;
              }
              while(j<=high)
              {
                             b[k]=a[j];
                             k++;
                             j++;
              }
              for(i=low;i<=high;i++)
                             a[i]=b[i];
}




THANK YOU








engineering gyan

What is Chat GPT

 What is Chat GPT Chatbot GPT (Generative Pre-prepared Transformer) alludes to a conversational simulated intelligence model created by Ope...