Google Search

Monday, February 15, 2016

RED BLACK tree Insertion function

rb_insert( Tree T, node x ) {
/* Insert in the tree in the usual way */
tree_insert( T, x );
/* Now restore the red-black property */
x->colour = red;
while ( (x != T->root) && (x->parent->colour == red) ) {
if ( x->parent == x->parent->parent->left ) {
/* If x's parent is a left, y is x's right 'uncle' */
y = x->parent->parent->right;
if ( y->colour == red ) {
/* case 1 - change the colours */
x->parent->colour = black;
y->colour = black;
x->parent->parent->colour = red;
/* Move x up the tree */
x = x->parent->parent;
}
else {
/* y is a black node */
if ( x == x->parent->right ) {
/* and x is to the right */
/* case 2 - move x up and rotate */
x = x->parent;
left_rotate( T, x );
}
/* case 3 */
x->parent->colour = black;
x->parent->parent->colour = red;
right_rotate( T, x->parent->parent );
}
}
else {
/* repeat the "if" part with right and left
exchanged */
}
}
/* Colour the root black */
T->root->colour = black;
}

C program for Matrix Multiplication:

‪#‎include‬ <stdio.h>
int main()
{
int m, n, p, q, c, d, k, sum = 0;
int first[10][10], second[10][10], multiply[10][10];
printf("Enter the number of rows and columns of first matrix\n");
scanf("%d%d", &m, &n);
printf("Enter the elements of first matrix\n");
for ( c = 0 ; c < m ; c++ )
for ( d = 0 ; d < n ; d++ )
scanf("%d", &first[c][d]);
printf("Enter the number of rows and columns of second matrix\n");
scanf("%d%d", &p, &q);
if ( n != p )
printf("Matrices with entered orders can't be multiplied with each other.\n");
else
{
printf("Enter the elements of second matrix\n");
for ( c = 0 ; c < p ; c++ )
for ( d = 0 ; d < q ; d++ )
scanf("%d", &second[c][d]);
for ( c = 0 ; c < m ; c++ )
{
for ( d = 0 ; d < q ; d++ )
{
for ( k = 0 ; k < p ; k++ )
{
sum = sum + first[c][k]*second[k][d];
}
multiply[c][d] = sum;
sum = 0;
}
}
printf("Product of entered matrices:-\n");
for ( c = 0 ; c < m ; c++ )
{
for ( d = 0 ; d < q ; d++ )
printf("%d\t", multiply[c][d]);
printf("\n");
}
}
return 0;
}

What could be the maximum size of virtual memory

Virtual memory is not limited by size of memory pointers in the machine, virtual memory limits are not the same as addressing memory space. More virtual memory than available in your pointer-based address space using paging can be addressed
Virtual memory upper limits are set by the OS: eg. 32-bit Windows the limit is 16TB, and on 64-bit Windows the limit is 256TB.
Max limitation is physical disk space.
To determine how much virtual memory you need, since the user's system contains the different amount of RAM, it is based on the system. By default, the OS will set the appropriate size for Virtual Memory. The default and appropriate size of Virtual Memory is:
<Amount_Of_System_Memory> * 1.5 = <Default_Appropriate_Size_Of_Virtual Memory>
Personally speaking, to maintain the good overall system performance, you should be using the default size of actual size for Virtual Memory and the triple the value of the size of the main memory for the maximum size of Virtual Memory.

Memory mapped I/O and I/O mapped I/O

The characteristics of isolated I/O or I/O mapped I/O are as follows:
- The devices of I/O are treated in a separate domain as compared to memory.
- A total of 1mb address space is allowed for memory applications.
- In order to maximize the I/O operations ( isolated ) separate instructions are always provided to perform these operations.
- One of the disadvantages is that the data transfer only occurs between the I/O port and the AL, AX registers.
The characteristics of the memory mapped I/O are as follows:
- In such scenarios the devices (I/O) are treated as a part of the memory only.
- Complete 1mb of memory cannot be used as they are a part of the memory.
- In case of memory mapped I/O operations no external separate instructions are required.
- There is data transfer restriction in case of memory mapped instructions.

Uniform Resource Locator (URL)

URL stands for Uniform Resource Locator. It is the address of a web page. Each page has its own unique web address (URL). This is how your computer locates the web page that you are trying to find.
Most web browsers display the URL of a web page above the page in an address bar. A typical URL could have the formhttp://www.example.com/index.html, which indicates a protocol (http), a hostname (www.example.com), and a file name (index.html).

Ping

Ping is a networking utility program or a tool to test if a particular host is reachable. It is a diagnostic that checks if your computer is connected to a server. Ping, a term taken from the echo location of a submarine, sends data packet to a server and if it receives a data packet back, then you have a connection.
example:
ping 172.16.103.1 –t

FTP

FTP is a client-server protocol that relies on two communications channels between client and server: a command channel for controlling the conversation and a data channel for transmitting file content. Clients initiate conversations with servers by requesting to download a file. Using FTP, a client can upload, download, delete, rename, move and copy files on a server. A user typically needs to log on to the FTP server, although some servers make some or all of their content available without login, also known as anonymous FTP.
Connect using FTP
To connect to another computer using FTP at the MS-DOS prompt, command line, or Linux shell type FTP and press Enter. Once in FTP, use the open command to connect to the FTP server, as shown in the example below.
open ftp.example.com
In the above example, you'd substitute example.com for the domain name or IP addressof where you are connecting. An example would be open 192.168.1.12.
Note: By default, the open command uses the TCP port 21 to make the FTP connection. If a different TCP port is needed for connecting to the domain name or IP address you are using, enter the port number after the domain name or IP address in the open command.
Once connected, a username and password prompt will appear. Once these credentials have been entered, the server allows you to browse, send, or receive files, depending on your rights. Some servers may also allow anonymous logins using guest or an e-mail address.
Send and receive a file in FTP
To get files from the server onto your own computer, use the get command as shown in the example below. In this example, you would get the file myfile.htm.
get myfile.htm

Sunday, February 14, 2016

c program to print pascal triangle:

‪#‎include‬ <stdio.h>
long factorial(int);
int main()
{
int i, n, c;
printf("Enter the number of rows you wish to see in pascal triangle\n");
scanf("%d",&n);
for (i = 0; i < n; i++)
{
for (c = 0; c <= (n - i - 2); c++)
printf(" ");
for (c = 0 ; c <= i; c++)
printf("%ld ",factorial(i)/(factorial(c)*factorial(i-c)));
printf("\n");
}
return 0;
}
long factorial(int n)
{
int c;
long result = 1;
for (c = 1; c <= n; c++)
result = result*c;
return result;
}

C Program example of Nested Structure

‪#‎include‬ <stdio.h>
struct Employee
{
char ename[20];
int ssn;
float salary;
struct date
{
int date;
int month;
int year;
}doj;
}emp = {"Pritesh",1000,1000.50,{22,6,1990}};
int main(int argc, char *argv[])
{
printf("\nEmployee Name : %s",emp.ename);
printf("\nEmployee SSN : %d",emp.ssn);
printf("\nEmployee Salary : %f",emp.salary);
printf("\nEmployee DOJ : %d/%d/%d", \
emp.doj.date,emp.doj.month,emp.doj.year);
return 0;
}

C program to reverse a string using recursion

‪#‎include‬ <stdio.h>
#include <string.h>
void reverse(char*, int, int);
int main()
{
char a[100];
gets(a);
reverse(a, 0, strlen(a)-1);
printf("%s\n",a);
return 0;
}
void reverse(char *x, int begin, int end)
{
char c;
if (begin >= end)
return;
c = *(x+begin);
*(x+begin) = *(x+end);
*(x+end) = c;
reverse(x, ++begin, --end);
}

C program to reverse a string using pointers

‪#‎include‬<stdio.h>
int string_length(char*);
void reverse(char*);
main()
{
char string[100];
printf("Enter a string\n");
gets(string);
reverse(string);
printf("Reverse of entered string is \"%s\".\n", string);
return 0;
}
void reverse(char *string)
{
int length, c;
char *begin, *end, temp;
length = string_length(string);
begin = string;
end = string;
for (c = 0; c < length - 1; c++)
end++;
for (c = 0; c < length/2; c++)
{
temp = *end;
*end = *begin;
*begin = temp;
begin++;
end--;
}
}
int string_length(char *pointer)
{
int c = 0;
while( *(pointer + c) != '\0' )
c++;
return c;
}

HCF program with multiple numbers in c

#include<stdio.h>
int main(){
int x,y=-1;
printf("Insert numbers. To exit insert zero: ");
while(1){
scanf("%d",&x);
if(x<1)
break;
else if(y==-1)
y=x;
else if (x<y)
y=gcd(x,y);
else
y=gcd(y,x);
}
printf("GCD is %d",y);
return 0;
}
int gcd(int x,int y){
int i;
for(i=x;i>=1;i--){
if(x%i==0&&y%i==0){
break;
}
}
return i;
}

HCF (Highest common factor) program with two numbers in c

#include<stdio.h>
int main(){
int n1,n2;
printf("\nEnter two numbers:");
scanf("%d %d",&n1,&n2);
while(n1!=n2){
if(n1>=n2-1)
n1=n1-n2;
else
n2=n2-n1;
}
printf("\nGCD=%d",n1);
return 0;
}

Find g.c.d of two number using c program:

‪#‎include‬<stdio.h>
int main(){
int x,y,m,i;
printf("Insert any two number: ");
scanf("%d%d",&x,&y);
if(x>y)
m=y;
else
m=x;
for(i=m;i>=1;i--){
if(x%i==0&&y%i==0){
printf("\nHCF of two number is : %d",i) ;
break;
}
}
return 0;
}

LCM program in c with multiple numbers

#include<stdio.h>
int lcm(int,int);
int main(){

int a,b=1;
printf("Enter positive integers. To quit press zero.");
while(1){
scanf("%d",&a);
if(a<1)
break;
else if(a>b)
b = lcm(a,b);
else
b = lcm(b,a);
}
printf("LCM is %d",b);
return 0;
}
int lcm(int a,int b){
int temp = a;
while(1){
if(temp % b == 0 && temp % a == 0)
break;
temp++;
}
return temp;
}

LCM program in c with two numbers (Other logic) :

#include<stdio.h>
int lcm(int,int);
int main(){
int a,b,l;
printf("Enter any two positive integers ");
scanf("%d%d",&a,&b);
if(a>b)
l = lcm(a,b);
else
l = lcm(b,a);
printf("LCM of two integers is %d",l);
return 0;
}
int lcm(int a,int b){
int temp = a;
while(1){
if(temp % b == 0 && temp % a == 0)
break;
temp++;
}
return temp;
}

Definition of LCM (Least common multiple):

LCM of two integers is a smallest positive integer which is multiple of both integers that it is divisible by the both of the numbers.
For example: LCM of two integers 2 and 5 is 10 since 10 is the smallest positive numbers which is divisible by both 2 and 5.
LCM program in c with two numbers :


‪#‎include‬<stdio.h>
int main(){
int n1,n2,x,y;
printf("\nEnter two numbers:");
scanf("%d %d",&n1,&n2);
x=n1,y=n2;
while(n1!=n2){
if(n1>n2)
n1=n1-n2;
else
n2=n2-n1;
}
printf("L.C.M=%d",x*y/n1);
return 0;
}

TYPES OF NUMBER:abundant number

A number that is smaller than the sum of its aliquot parts (proper divisors). Twelve is the smallest abundant number – the sum of its aliquot parts is 1 + 2 + 3 + 4 + 6 = 16 – followed by 18, 20, 24, and 30.
A weird number is an abundant number that is not semiperfect; in other words, n is weird if the sum of its divisors is greater than n, but n is not equal to the sum of any subset of its divisors. The first few weird numbers are 70, 836, 4030, 5830, and 7192. It isn't known if there are any odd weird numbers.
A deficient number is one that is greater than the sum of its aliquot parts. The first few deficient numbers are 1, 2, 3, 4, 5, 7, 8, and 9. Any divisor of a deficient (or perfect) number is deficient. A number that is not abundant or deficient is known as a "perfect number".

TYPES OF NUMBER:algebraic number:

A real number that is a root of a polynomial equation with integer coefficients. For example, any rational number a/b, where a and b are non-zero integers, is an algebraic number of degree one, because it is a root of the linear equation bx - a = 0. The square root of two is an algebraic number of degree two because it is a root of the quadratic equation x2 - 2 = 0. If a real number is not algebraic, then it is a transcendental number. Almost all real numbers are transcendental because, whereas the set of algebraic numbers is countably infinite, the set of transcendental numbers is uncountably infinite (see infinity).

TYPES OF NUMBER: amicable numbers

A pair of numbers, also known as friendly numbers, each of whose aliquot parts add to give the other number. (An aliquot part is any divisor that doesn't include the number itself).
The smallest amicable numbers are 220 (aliquot parts 1, 2, 4, 5, 10, 11, 20, 22, 44, 55, and 110, with a sum of 284) and 284 (aliquot parts 1, 2, 4, 71, and 142, with a sum of 220). This pair was known to the ancient Greeks, and the Arabs found several more. In 1636 Pierre de Fermat rediscovered the amicable pair 17296 and 18416; two years later René Descartes rediscovered a third pair, 9363584 and 9437056. In the 18th century Leonhard Euler drew up a list of more than 60. Then, in 1866, B. Nicoló Paganini (not the violinist!), a 16-year-old Italian, startled the mathematical world by announcing that the numbers 1184 and 1210 were friendly. This second lowest pair of all had been completely overlooked. Today, the tally of known amicable numbers has grown to about two and half million. No amicable pair is known in which one of the two numbers is a square. An unusually high proportion of the numbers in amicable pairs ends in either 0 or 5.