Monday, 2 March 2020

Python Programs

#Program to print natural numbers
n=int(input("enter number"))
for i in range(1,n+1):
  print(i,end=' ')

#Program to print 1 to n natural numbers and find the sum also
n=int(input("enter n value"))
print("natural numbers between 1 to {0}".format(n))
sum=0
for i in range(1,n+1):
   print(i,end=' ')
   sum=sum+i
print("\nsum of natural numbers are:{0}".format(sum))

#Reading and Printing of array elements
a=[]
n=int(input("enter n value"))
for i in range(n):
  a.append(int(input("enter elements into an array")))
for i in range(n):
   print(a[i]) 

# Calculate Factorial of a given number using functions
def fact(n):
   f=1;
   for i in range(1,n+1):
     f=f*i
   return f
n=int(input("enter n value"))
print("factorial of {0} is {1}".format(n,fact(n)))

Friday, 31 January 2020

Context Free Grammar

A Context Free Grammar(CFG) is defined as G=(V,T,P,S) where
V=Finite set of Variables
T=Finite set of Terminals
P=Production rule which can be defined as 𝝰→𝛃 where 𝝰𝟄V and 𝞫→(V U T)*
S is a starting production

Example:

S→aSb|𝟄 is a grammar which accepts the language contains equal number of a's and equal number of b's

similarly

S→aSa|bSb|𝟄 is grammar which generates even length plaindrome

S→aSa|bSb is grammar which generates odd length palindrome

Saturday, 25 January 2020

/*Program to check whether two strings are Anagram or Not*/

Anagram Definition:

An anagram of a string is another string that contains same characters, only the order of characters can be different

Example: Weak, Wake
                 Mad, Dam

/* Program using Java*/

class StringAnagram
{
public static void main(String[] a) throws Exception
{
boolean flag=true;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); 
System.out.println("enter two strings");
str1=br.readLine();
str2=br.readLine();  
 int n1 = str1.length;
 int n2 = str2.length;
        if (n1 != n2)
            return false;
        char[] ch1 = new char[str1.length()];
        for (int i = 0; i < str1.length(); i++) {
            ch1[i] = str1.charAt(i);
        char[] ch2 = new char[str2.length()];
        for (int i = 0; i < str1.length(); i++) {
            ch2[i] = str1.charAt(i);
      
        Arrays.sort(str1);
        Arrays.sort(str2);
    
        for (int i = 0; i < n1; i++)
            if (str1[i] != str2[i])
               flag=false;
        if(flag==true)
                System.out.println("Strings are Anagram");
       else
                System.out.println("Strings are not Anagram");
 }
}

Monday, 15 July 2019

Java Program to Convert Uppercase Character to Lowercase Character

/*Aims to convert Uppercase Character to Lowercase Character */

import java.util.Scanner;

public class JavaProgram
{
    public static void main(String[] input)
    {
        char ch;
        int temp;
        Scanner scan = new Scanner(System.in);
        
        System.out.print("Enter a Character in Uppercase : ");
        ch = scan.next().charAt(0);
  
        temp = (int) ch;
        if((temp>=97)&&(temp<=122)) 
               temp = temp + 32;// The difference between the ASCII Codes of Lower case and Uppercase is 32
        ch = (char) temp;
  
        System.out.print("Equivalent Character in Lowercase = " + ch);
    }
}

 

Scalable Computing Over Internet

The above Video contains different types of Computing Techniques, Differences between HPC and HTC, Multithreading Concepts, Differences between CPU and GPU, etc.,

Tuesday, 25 June 2019

Parallelism in Cloud Computing


Degrees of Parallelism
The number of parallel execution servers associated with a single operation is known as the degree of parallelism(DOP).
We can apply parallelism only when the problem broken into discrete pieces to be solved simultaneously.
Types of parallelism
1.      Data Level Parallelism
It is parallelization across multiple processors in parallel computing environments.
For eg., if we want to sum of array elements in sequential execution, the time taken by the process is n*Ta . If we want to execute the same job as a data parallel job on 4 processors the time taken would reduce to (n/4)*Ta+merging overhead time units.
2.      Task Level Parallelism
It covers the execution of computer programs across multiple processors on same or multiple machines.  For eg., task parallelism would be an application creating thread for doing parallel processing where each thread is responsible for performing a different operation.
                                              

3.      Instruction Level Parallelism
It is a measure of how many of the instructions in a computer program can be executed simultaneously.
For eg.,  a=b+c, d=e+f, x=a+b
Out of these three instructions, two instructions executed individually. The third one depends on the result of first and second operations.
4.      Bit Level Parallelism
It is a form of parallel computing based on increasing processor word size. Increasing the word size reduces the number of instructions the processor must execute in order to perform an operation on variables whose sizes are greater than the length of the word.


Wednesday, 17 May 2017

NON-DETERMINISTIC FINITE AUTOMATA (NFA)

A Non-Deterministic Finite Automata is defined as a five tuple notation as like DFA:

N=(Q,𝜮,𝜹,q0,F)

where Q is set of finite number of states
𝜮 is an input alphabet
𝜹 be the transition function which can be defined as 𝜹:QX𝜮->2Q Here QX𝜮 represents the Cartesian product of the sets Q & 𝜮 and 2Q is the power set of Q
q0 be the starting state.
F be the set of final states.

The main difference between NFA and DFA is

1. For every input alphabet there is only one transition in DFA and in NFA more than one transition is acceptable for every input alphabet.

2. In DFA transition is must for every input alphabet whereas in NFA user may or may not give the transition to each input alphabet.

3. In DFA only one path is used to say whether the string is accepted or rejected where as in NFA number of paths  occur and if all the paths die the string is rejected otherwise any one of the paths gives the accepted path.