Posts

Showing posts from 2012

Write a program to solve the problem of tower of Hanoi with 3 pegs and N discs

#include #include class hanoi { int n; char peg_a, peg_b, peg_c; public: void towers_hanoi(int n, char peg_a, char peg_b, char peg_c); }; void hanoi::towers_hanoi(int n, char peg_a, char peg_b, char peg_c) { if (n<=0) { cout << "\nIllegal operation" ; } else if (n==1) { cout << "\nMove disk from :\t" << peg_a << "\tto\t" << peg_c; } else { towers_hanoi(n-1, peg_a, peg_c, peg_b); towers_hanoi(1, peg_a, peg_b, peg_c); towers_hanoi(n-1, peg_b, peg_a, peg_c); } } void main() { hanoi obj; int n; clrscr(); cout << "\nEnter numbers of disk :\t" ; cin >> n; obj.towers_hanoi(n, 'A', 'B', 'C'); getch(); }

Write a menu driven program to a) Find the length of a string b) concatenate two strings c) to extract a substring from a given string d) Finding and replacing a string by another string in a text (Use pointers and user-defined functions)

#include #include #include #include #include class string_manipulation { public: void lenstr(char *); void concatenate(char *, char *, char *); int str_rep(char *, char *, int c[]); void extract(); }; void string_manipulation::lenstr(char *p) { int len = 0; while (*p++) { len ++; } cout << "The length of the string is : " < }

Write a program to convert the given infix expression into its postfix form

#include #include #include #include int TOP = -1, rank = 0; char STACK[50]; class infix_exp { public: void PUSH(char item); char POP(); int F(char symbol); int G(char symbol); int RANK(char symbol); int infix_postfix(char infix[ ], char postfix[ ]); };

explain classification of PRAM model

explain classification of PRAM model The PRAM model is an extension of the familiar RAM model of sequential computation that is used in algorithm analysis. We will use the synchronous PRAM which is defined as follows. 1. There are p processors connected to a single shared memory. 2. Each processor has a unique index 1 <=   i <=   p called the processor id . 3. A single program is executed in single-instruction stream, multiple-data stream (SIMD) fashion. Each instruction in the instruction stream is carried out by all processors simultaneously and requires unit time, regardless of the number of processors.

Gustafson’s law

Image
Gustafson’s law :- Gustafson's Law says that if you apply   P   processors to a task that has serial fraction   f , scaling the task to take the same amount of time as before, the speedup is Gustafson demonstrated with a 1024-processor system that the basic presumptions in Amdahl’s Law are inappropriate for massive parallelism [Gustafson88]. Gustafson found that the underlying principle that “the problem size scales with the number of processors, or with a more powerful processor, the problem expands to make use of the increased facilities is inappropriate” [Gustafson88]. Gustafson’s empirical results demonstrated that the parallel or vector part of a program scales with the problem size. Times for vector start-up, program loading, serial bottlenecks, and I/O that make up the serial component of the run do not grow with the problem size

Moore law and Amdahl law

  Moore law :- The   observation   that   steady   technological   improvements   in miniaturization   leads   to   a   doubling   of   the   density   of   transistors   on   new integrated   circuits   every   18   months.   In   the   mid-1960s,   Gordon   Moore (born   1929),   one   of   the   founders   of   Intel   corporation ,   observed   that the   density   of   transistors   had   been   doubling   every   year,   although   the pace   slowed   slightly   in   the   following   years.   The   18-month   pattern   heldtrue   into   the   21st   century,   though   as   technology   approaches   thepoint   where   circuits   ar...

Life cycle of Servlet

Image
Life cycle of Servlet :- The life cycle of a servlet can be categorized into four parts: 1.      Loading and Inatantiation:  The servlet container loads the servlet during startup or when the first request is made. The loading of the servlet depends on the attribute of web.xml file. If the attribute has a positive value then the servlet is load with loading of the container otherwise it load when the first request comes for service. After loading of the servlet, the container creates the instances of the servlet.

Write a menu driven program to perform insert and delete operations in a circular linked list

#include #include #include #include #include int insbeg(int item); int inspos(int item); int insend(int item); int length(); int delbeg(); int delpos(); int delend(); struct node {             int info;             struct node *link; }; typedef struct node n1; n1 *last = NULL; n1 *currptr, *newnode, *preptr;

Write a program to add two polynomials using a linked list

#include #include #include struct poly_node {             int coeff, expo;             struct poly_node *link; }; typedef struct poly_node poly; poly *insert_polynode(int, int, poly*);

Depth first search (DFS)

This is a very simple type of brute force searching techniques. The search begins by expanding the initial node i.e. by using an operator generate all successors of the initial node and test them. This procedure finds whether the goal can be reached or not but the path it has to follow has not been mentioned. Diving downward into a tree as quickly as possible performs DFS searches. Algorithm:

Breadth First Search (BFS)

This is also a brute force search procedure like DFS. We are searching progresses level by level. Unlike DFS which goes deep into the tree. An operator employed to generate all possible children of a node. BFS being a brute force search generates all the nodes for identifying the goal. ALGORITHM:

Write a short note on Best first search ?

Best-first search, rather than plunging as deep as possible into the tree (as in   depth-first search ), or traversing each level of the tree in succession (as in   breadth-first search ), uses a heuristic to decide at each stage which is the best place to continue the search. Best-first search in its most basic form consists of the following algorithm (adapted from   Pearl, 1984): The first step is to define the OPEN list with a single node, the starting node. The second step is to check whether or not OPEN is empty. If it is empty, then the algorithm returns failure and exits. The third step is to remove the node with the best score, n, from OPEN and place it in CLOSED. The fourth step “expands” the node n, where expansion is the identification of successor nodes of n. The fifth step then checks each of the successor nodes to see whether of not one of them is the goal node. If any successor is the goal node, the algorithm returns success and the solution, which c...
Hiiiii to all........pls frnds....before download the content from this blog...plss join this site and like my facebook page also ......  http://www.facebook.com/Prasenrajblog.......thanks to all......

Difference between TCP and UDP

TCP UDP Reliability : TCP is connection-oriented protocol. When a file or message send it will get delivered unless connections fails. If connection lost, the server will request the lost part. There is no corruption while transferring a message. Reliability : UDP is connectionless protocol. When you a send a data or message, you don't know if it'll get there, it could get lost on the way. There may be corruption while transferring a message. Ordered : If you send two messages along a connection, one after the other, you know the first message will get there first. You don't have to worry about data arriving in the wrong order. Ordered : If you send two messages out, you don't know what order they'll arrive in i.e. no ordered Heavyweight : - when the low level parts of the TCP "stream" arrive in the wrong order, resend requests have to be sent, and all the out of sequen...

To display list of C program files and directories.

#include #include #include void main() {             clrscr();             printf("********** List of C Program files **********\n");             system("dir *.c /w");             printf("\n********** List of C Program directories **********\n");             system("dir /ad"); }

To convert hexadecimal to decimal numbers.

#include #include #include #include void main() {             char hex[' '], c;             int i,len,dec[' '],total;             clrscr();             do             {

To print whether the number entered is even or odd, using conditional operator

#include #include void main() {             int num;             char c;             clrscr();             do             {                         printf("Enter any number:\t");                         scanf("%d",&num);                         num%2==0 ? printf("\nNumber is even\n") : printf("\nNumber is odd\n");       ...

Write a menu driven program to create a linked list and to perform insert and delete operations

#include #include #include #include #include int insbeg(int item); int inspos(int item); int insend(int item); int delbeg(); int delpos(); int delend(); struct node {             int info;             struct node *link; }; typedef struct node n1; n1 *start = NULL; n1 *currptr, *newnode, *preptr; class list {             public:                         int create();                         int display();                         i...