Friday, 12 October 2018

Recommended Books for Gate

Many computer science aspirants may aspire to clear GATE.So, in this article I want to share some of the books which I found to be worth sharing and may help in your preparation.

Programming in C-The C Programming Language by Dennis Ritchie

C programming has good weightage in Gate and the questions are easy to answer if you master the concepts from this book.

Links to get the book    Amazon     Flipkart

Data structures-Data Structures using C by Tenenbaum

The book is highly recommended. Beginners may find it a tough read. But then it pays off eventually with the reader ending up with a good understanding of data structures

Links to get the books  Amazon     Flipkart

Algorithms

I would like to talk about two books as far as Algorithms is concerned.The first book is known as bible for computer science, Introduction to Algorithms by Coremen.
The other book is Algorithms and data structures made easy by Narasimha karumanchi.It has good problems with clear explanation

Link for Introduction to algorithms    Amazon       Flipkart
Link for Data structures and algorithms Made Easy   Amazon     Flipkart

Theory of computation-An Introduction to formal languages by Peter Lenz

It covers all topics with clear explanation and good problems at the end of each chapter.If one goes through this book nicely it will help you to score full marks as far as TOC for GATE is concerned.

Links for the book    Amazon   Flipkart

Operating Systems-Operating System Concepts by Galvin

This is very interesting and covers the entire Gate Syllabus.It has good explanation that anyone could understand the concepts very easily.

Links for the book   Amazon    Flipkart

Databases-Fundamentals of Database systems

It is an excellent book for gate.very well compiled information and user specific language helps you to understand the concepts easily. 

Links for the book   Amazon    Flipkart

Computer Networks-Data Communications and Networking by Forouzan

Most of the aspirants feel CN is a bit difficult but this book  is really interesting and the concepts are very clear with diagrams.

Links for the book Amazon    Flipkart

Compiler Design-Compilers:Principlles,Techniques,Tools by Ullman

This is most recommended book for compilers that has good concepts with clear explanation and exercise problems.

Links  for the book  Amazon   Flipkart

Computer Organisation-Computer System Architecture by Morris Mano

This is the clear and easy understandable book for Gate.The exercise problems are good for practise

Links for the book   Amazon    Flipkart

Digital Logic Design-Modern Digital Electronics by R Jain

This book covers the basics very well.The concepts are very clear with neat explanation.The exercise problems are recommended.

Links for the book  Amazon   Flipkart

All the very best !!!!!!!




Thursday, 10 August 2017

Sieve of Eratosthenes

Sieve of Eratosthenes is one of the efficient method of finding the prime numbers in a given range.It is popularly known as Prime Sieve.The steps  involved are
1.create a range from 2 to any given range n.
2.let p be a variable initially equals to 2 (the first prime number)
3.Remove all the multiples of p
4.Now,p equals to the next number greater than p that is unmarked,If there was no such number, then you can stop.
5.Otherwise, p now equal this number (which is the next prime),
Example
 Lets find the prime numbers from 2 to 30

1.Create a list from 2 to 30

  2  3  4  5  6 7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26 27  28  29  30 31 
  32  33 34 35 36 37 38 39 40

 Initially p is 2 so,mark all the multiples of 2
 
  2  3  4  5  6 7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26 27  28  29  30 31    
  32 33 34 35 36 37 38 39 40

   Now p is equal to the next unmarked number i.e., 3


Now mark all the multiples of 3

   2  3  4  5  6 7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26 27  28  29  30 31 
  32  33  34  35  36  37  38  39  40


Now p is equal to the next unmarked number , i.e., 5

Now  mark all the multiples of 5

   2  3  4  5  6 7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26 27  28  29 30 31 
  32  33  34  35  36  37  38  39  40

  The algorithm continues to find the next unmarked number and continues to mark all its multiples but it doesn’t  produce any change in the current list.

So  finally we obtained the prime numbers from 2 to 30 as

     2  3  5  7  11  13  17  19  23  29 31 37

Thus, it is as simple as that !!!!

Now lets look into the Implementation in C …..


#include "stdio.h"
#include "math.h"
int main(void) {
 // your code goes here
 int a[40],n=40,i,j;
 for(i=0;i< n;i++)
 a[i]=1;
 for(i=2;i< sqrt(n);i++)
 {
  if(a[i])
  for(j=i;i*j< n;j++)
  {
   a[i*j]=0;
  }
 }
 printf("primes from 2 to 40");
 for (i = 2;i< n; i++)
        if (a[i])
            printf("%d\n", i);
 
 return 0;
 

Output


primes from 2 to 40
2
3
5
7
11
13
17
19
23
29
31
37

Thursday, 3 August 2017

Pointers


In any programming language the variables are stored in some memory locations with some addresses.Some programming languages like c,provides a way for accessing these memory locations .This facility is provided with a well known concept called pointers.So,lets look at pointers

What is a pointer?

Most of the programmers feel pointers as difficult but its little bit tricky.Inshort,pointers are the variables that can store address of another variables. lets define a pointer

int *p;

The above declaration confirms that p is an integer pointer.* is used to indicate a variable as a pointer variable.

Example

int main()
{
 int *p,a=10;
 p=&a;
 printf("The address of a is %d\n",p);
 printf("The value of a is %d%",*p);
}

Output

The address of a is 339631052
The value of a is 10

From the above code,it is clear that the address of variable a is stored in p.address operator(&) is used to get the address of a variable.* is a dereferenceing operator used to retrieve the value stored in the address location.

Arithmetic operations on pointers:

The following are the invalid arithmetic operations on pointers.

  • Addition
  • Multiplication
  • Division
  • Modulo

The above operations are invalid because pointers contain addresses so performing the above operations on pointers results meaningless results. However,Subtraction is legal among pointers as it results to the offset between the addresses.

Interesting concepts of pointers


Pointer array vs array of pointers


pointer array


Pointer array is a pointer pointing to an array.
int main() 
{
 int *p,arr[5],i;
 p=&arr; // p is pointing to array arr
 for(i=0;i<5;i++)
 {
     scanf("%d",&arr[i]);
 }
 for(i=0;i<5;i++)
 {
     printf("%d",*(p+i));
 }
    return 0;
}

Output

12345

Array of pointers

Array of pointers is an array containing addresses as array elements.

   
int main()
{
 int *arr[5],i;
 for(i=0;i<5;i++)
 {
  arr[i]=&i;
 }
 for(i=0;i<5;i++)
 {
  printf("%d\n",*arr[i]);
 }
}

Output

0
1
2
3
4

function pointer vs pointer to function


pointer to function


Function pointer is a pointer typically points to the block of executable code.

Example

void code(int i)
{
 printf("value of i is %d",i);
}
int main()
{
 void (*fun_ptr)(int)=&code;
 (*fun_ptr)(5);
 return 0;
}

Output

value of i is 5

Here we need an extra bracket around function pointer like fun_ptr,otherwise it becomes void *fun_ptr*(int) which is a function returning pointer.

function pointer

function pointer is function that returns pointer.

int *fun();
int main()
{
    int *ptr;
    ptr=fun();
    printf("%d",*ptr);
}
int *fun()
{
    int *pointer=malloc(sizeof(*pointer));
    *pointer=10;
    return pointer;
}

Output

10

Thursday, 15 June 2017

Time Complexity Of Algorithms


The time complexity of an algorithm is the time required for an algorithm for its complete execution.The time complexity of an algorithm usually depends on the size of the input.

Some common time complexities

The time complexity of various algorithms would be constant O(1),Linear O(n),quadratic O(n2),Exponential O(2n),factorial O(n!) etc

Now let us see some of the time complexities.

O(1)

The time complexity of an algorithm is said to be O(1),If it requires same amount of time for execution regardless of the size of the input.

Example:

It takes constant time to access an element in an array of any size.

O(n)

The time complexity of an algorithm is said to be O(n),If the time of execution of the algorithm increases linearly with increase in size of the input.

Example

int main(void) {
int arr[5],i;
printf("enter 5 integers\n");
for(i=0;i<5;i++)
scanf("%d",&arr[i]);
printf("It takes linear time access the elements of an array\n");
for(i=0;i<5;i++)
printf("%d",arr[i]);
 return 0;
}

Output

enter 5 integers
1
2
3
4
5
It takes linear time access the elements 
of array
12345

O(logn)

The time complexity of an algorithm is said to be O(logn),If the time of execution of the algorithm increases logarithmically with increase in size of the input.

O(loglogn)

The time complexity of an algorithm is said to be O(loglogn),If the loop variables are increased or decreased by a constant amount.

int main() 
{
 
int i,n=2,c=3;
for(i=2;i<=n;i=pow(i,c))
printf("Code Titans\n");
return 0;
}

Output

Code Titans

O(nc)

The time complexity of an algorithm is said to be O(nc) which is nothing but the time required to execute the innermost loop.

Example for n2

int main() {
int i,j;
for( i=0;i<3;i++)
{
    for(j=0;j<2;j++)
    {
        printf("Code Titans\n");
    }
}
 return 0;
}

Output

Code Titans
Code Titans
Code Titans
Code Titans
Code Titans
Code Titans

O(cn)

The time complexity of an algorithm is said to be O(cn),If the time of execution of the algorithm increases exponentially with increase in size of the input.

Example

Brute force method of n-queen problem take O(nn)

O(n!)

Some algorithms take factorial time for their execution which are considered as the slowest algorithms.

Example

Travel Sales person

Thursday, 18 May 2017

Properties Of Binary Trees

Trees are non linear data structures mostly used for hierarchical representation.
A binary tree is a tree in which every node will have at most two children. Before going to the properties of such binary trees,let us see two important types of binary trees.

Complete Binary Tree

It is the binary tree in which all levels except the last,is completely filled and all the nodes are as far left as possible.

Example 


       
                 
               

Almost Complete Binary Tree


A binary tree is said to be almost complete binary tree when all the leaves of the tree are either at d or d-1 level.here, d is the depth of the tree.

Tuesday, 16 May 2017

Storage Classes

Storing the data for execution is the heart of the programming.What actually matters is accessing the stored data.So,lets See how to perform these interesting tasks...

What is scope and life time of variables?


 Scope of a variable is actually the area of our program where we can access our variables.
 life time of variable is the time for which the variable has a valid memory.

What is storage class?


Any variable/function that exists inside the program will have scope and life time.This scope and life time of variables is described through storage class.

we have four storage classes.


1)auto
2)extern
3)static
4)register

Tuesday, 2 May 2017

Abstract Classes Vs Interfaces

It is a bit confusion about when to use an abstract class and when to use an interface.So lets see the differences between abstract classes and interfaces,so that we can use them appropriately!!

Real World Scenario


Let us consider a class wholesaler which represents a wholesale shop with textbooks and stationary like pens, pencils,papers and notebooks

class Wholesaler
{
 void textbooks()
 {}
void stationary();
 {}
}