Skip to main content

What is Divide And Conquer Technique

Divide and Conquer is a programming technique which makes the program more efficient to write. And this technique work on the concept of recursion to solve a problem step by step. Generally this technique work in three parts:- Divide:-  Divide the problem into some subproblem. Conquer:-  Conquer the subproblem by calling recursively until subproblem solved. Combine:-  (Optional Step) Combine the subproblem solution. So, that we will get the final problem Solution.  When the subproblems are large enough to solve recursively, we call the recursive case. Once the subproblem becomes small enough that we no longer recursive, we say that the recursion "bottom out" and that we have gotten down to the base case.                          Application of Divide and Conquer Quick Sort Strassen's algorithm for matrix multiplication Merge Sort Counting inversions Binary Search Finding Min and max Divide and Conquer Abstract Algorithm DAC(a,i,j) {   

Sorting numbers using LinkList in C Language

#include<stdio.h>
#include<conio.h>

//creating  a structure for linked list
typedef struct node
{
    int data;
    struct node* next;
}node;     //rename whole structure

// function for creating nodes of linked list
node * createlinkedlist(int n); //return address
void display(node * head);
void sort1(node * head,int n);
int main(){
int n=0;
node* HEAD=NULL;
node* HEAD1=NULL;
printf("how many nodes want to add in a linklist ");
scanf("%d",&n);
HEAD=createlinkedlist(n);
sort1(HEAD,n);

display(HEAD);
return 0;
}

node * createlinkedlist(int n)
{
    int i=0;
    node * head=NULL;
    node * temp=NULL;
    node * p=NULL;
    for(i=0;i<n;i++)
    {
        //creating unattached node
        temp=(node*)malloc(sizeof(node));
        printf("Enter the data for node %d \t",i+1);
        scanf("%d",&(temp->data));
        temp->next =NULL;
        if(head==NULL) //when linked list is empty
        {
            head=temp;
        }
        else
        {
            p=head;
            while(p->next!=NULL)
            {
                p=p->next;

            }
            p->next=temp;
        }
    }
    return head;
}

void display(node * head)
{
    node * a=head;
    while(a!=NULL)
    {
        printf("%d->",a->data);
        a=a->next;
    }
}
void sort1(node* head,int n)
{
    node* p=head;
    node* q=head;
    node* temp=p->next;
    int box=p->data;
    for(int i=1;i<n;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            if(p->data>=temp->data)
            {
                box=p->data;
                p->data=temp->data;
                temp->data=box;

            } temp=temp->next;
        }p=p->next;temp=p->next;


    }

}

Comments

Popular posts from this blog

What is Divide And Conquer Technique

Divide and Conquer is a programming technique which makes the program more efficient to write. And this technique work on the concept of recursion to solve a problem step by step. Generally this technique work in three parts:- Divide:-  Divide the problem into some subproblem. Conquer:-  Conquer the subproblem by calling recursively until subproblem solved. Combine:-  (Optional Step) Combine the subproblem solution. So, that we will get the final problem Solution.  When the subproblems are large enough to solve recursively, we call the recursive case. Once the subproblem becomes small enough that we no longer recursive, we say that the recursion "bottom out" and that we have gotten down to the base case.                          Application of Divide and Conquer Quick Sort Strassen's algorithm for matrix multiplication Merge Sort Counting inversions Binary Search Finding Min and max Divide and Conquer Abstract Algorithm DAC(a,i,j) {   

Bresenham circle drawing program in C

  /* This is the program for bresenham circle drawing  in C */ #include<stdio.h> #include<conio.h> #include<graphics.h> #include<dos.h> void main() { int gdriver = DETECT,gmode,x,y,r,x1,y1; float e; initgraph(&gdriver,&gmode,"C:\\tc\\BGI"); printf("center co-ordinate of x and y position of circle:\n"); scanf("%d %d",&x,&y); printf("input the radius of circle:\n"); scanf("%d",&r); x1=1; y1=r; putpixel(x+0,y+r,RED); putpixel(x+r,y+0,RED); putpixel(x-0,y-r,RED); putpixel(x-r,y-0,RED); e=3-2*r;   while(x1<y1) { if(e<0) { x1=x1+1; e=e+4*x1+6; } else { x1=x1+1; y1=y1-1; e=e+4*(x1-y1)+10; }           putpixel(x+x1,y+y1,1); putpixel(x+y1,y+x1,2); putpixel(x-x1,y+y1,3); putpixel(x-y1,y+x1,4); putpixel(x-x1,y-y1,5); putpixel(x-y1,y-x1,6); putpixel(x+x1,y-y1,7); putpixel(x+y1,y-x1,8); delay(100); } getch(); } /*NOTE:-You have to change the graphics

Extracting all states of India from wikipedia link using Jsoup jar and Java language

/*  * To change this license header, choose License Headers in Project Properties.  * To change this template file, choose Tools | Templates  * and open the template in the editor.  */ package urldatafetch; /**  *  * @author Rishabh  */ import java.io.IOException; import java.io.PrintWriter; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.jsoup.select.Elements; public class testing { public static void main(String[] args) throws IOException {       org.jsoup.nodes.Document doc = Jsoup.connect("https://en.wikipedia.org/wiki/India").get();       org.jsoup.select.Elements tables =doc.select("table");        // org.jsoup.select.Elements rows = doc.select("tr");         PrintWriter pw=new PrintWriter("tabledata.txt");        int i=1;        int j=1;        int k=1;        String state[]=new String[29];      for(org.jsoup.nodes.Element tableo :tables)      {  if(i==1