Skip to main content

Posts

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) {   
Recent posts

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 =NU

Number to Word convert Program in Java

package numbertoword; import java.util.*; /**  *  * @author Rishabh  */ public class NumberToWord {     /**      * @param args the command line arguments      */     static int count,i=0,position=0;     static String arr[];     public void odd(){}     public static void main(String[] args) {         Scanner sc=new Scanner(System.in);             String number=sc.next();             int numlength=number.length();             if(numlength==11||numlength==10)             {  arr=new String[6];                 arr[0]="Arab";                 arr[1]="Crore";                 arr[2]="Lakh";                 arr[3]="Thousand";                 arr[4]="Hundred";                 arr[5]="";             }             if(numlength==9||numlength==8)             {  arr=new String[5];                 arr[0]="Crore";                 arr[1]="lakh";                 arr[2]="thousand";

Extracting all states data like population,economy from a wikipedia link of India using Java Language

package urldatafetch; /**  *  * @author Rishabh  */ import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Iterator; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.jsoup.select.Elements; public class UrlDataFetch { 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");                    int i=1;                    String state[]=new String[29];        ArrayList<String> ar=new ArrayList<>();      for(org.jsoup.nodes.Element tableo :tables)      {  if(i==1 ||i==2 ||i==4){i++;}      else if(i==3)      {  org.jsoup.select.Elements rows=tableo.select("tr");         for(org.jsoup.nodes.Element row :rows)         {             org.jsoup.select.Elements co

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

Reverse Words

Reverse Words Given a list of space separated words, reverse the order of the words. Each line of text contains L letters and W words. A line will only consist of letters and space characters. There will be exactly one space character between each pair of consecutive words. Input The first line of input gives the number of cases, N. N test cases follow. For each test case there will a line of letters and space characters indicating a list of space separated words. Spaces will not appear at the start or end of a line. import java.io.BufferedReader; import java.io.DataInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Scanner; import java.util.Stack; import java.util.StringTokenizer; import java.util.logging.Level; import java.util.logging.Logger; /**  *  * @author Rishabh  */ public class Reversestring  {     public static void main(String[] args)  {         // TODO code applicati

Store Credit program in C language

You receive a credit  C  at a local store and would like to buy two items. You first walk through the store and create a list  L  of all available items. From this list you would like to buy two items that add up to the entire value of the credit. The solution you provide will consist of the two integers indicating the positions of the items in your list. Inp ut The first line of input gives the number of cases,  N .  N  test cases follow. For each test case there will be: One line containing the value  C , the amount of credit you have at the store. One line containing the value  I , the number of items in the store. One line containing a space separated list of  I  integers. Each integer  P  indicates the price of an item in the store. Each test case will have exactly one solution. #include<stdio.h> int main() { int n,c,it,p[1000];   scanf("%d\n",&n);   for(int i=1;i<=n;i++)   {     scanf("%d\n",&c);     scanf("%d\n"