Stack

What is Stack? 

     In computer science, a stack is an abstract data type that serves as a collection of elements, with two principal operations: push, which adds an element to the collection, and. pop, which removes the most recently added element that was not yet removed. 

-Wikipedia

     Consider a stack of chairs as shown in the picture below. Here, the chairs the kept one on the other which shows that when you add a new chair (push) you should place it at the top of the stack and when you need to take, you should take (pop) it from the top. If you need to take the fifth chair from the top, you are supposed to take out the first four chairs and you get your fifth chair. This makes true for the statement, “You take the chair which you placed most recently” otherwise, First In Last Out (FILO) or Last In First Out (LIFO). This concept is implemented in the data structure where the values can be placed in this order if we need.

stack example

More on implementation on a Stack

     Stack has memory whenever implemented in a program. When the memory of the values pushes into a stack gets collectively more than the memory of the stack then the problem occurs as Stack OverflowIf n values stored in the stack get popped from it and when popping the non-existing (n+1)th value then the problem occurs as Stack Underflow.

Implementation of Stack in Python

class Stack:
def __init__(self):
self.items = []

   def push(self, item):
self.items.append(item)

   def pop(self):
return self.items.pop()

Time Complexity: O(n) when accessing and searching values in the stack, O(1) when inserting or deleting a value in the stack.
Space Complexity: O(n)

Like and Follow this blog. Support our Facebook page. Feel free to contact us for your queries. Mail us your queries to askregins@gmail.com

From,

Maria Irudaya Regilan J

Advertisements
Support our Fb page “The Code Table”

     Hi everyone! I am happy to announce the Facebook page we have started today! Thank you for your support to our blog and we are expecting the same support for you for our page too. Our page is focused on people to experience a new way of programming. We are there to present the pattern programs, aptitude questions, programming snippets, and algorithms.

     Mail us your feedback on this blog (www.regilanj.wordpress.com) and on our facebook page (www.facebook.com/thecodetable/) to askregins@gmail.com. Like and follow our page. Thank you. From, Maria Irudaya Regilan J

Learning Big O Notations – Time Complexity | Part 2

Look at part 1 of this post “Learning Big O Notations” to gather the idea on the complexity of the algorithms. In this article, we can look at various other time complexities. The Time complexity is the computational complexity that describes the amount of time it takes to run an algorithm. Time complexity is commonly estimated by counting the number of elementary operations performed by the algorithm, supposing that each elementary operation takes a fixed amount of time to perform. Thus, the amount of time taken and the number of elementary operations performed by the algorithm is taken to differ by at most a constant factor. –Wikipedia

O(1)

Consider a simple program of finding a given number whether it is an even number or an odd number.

          if number mod 2 == 0    {

              print “The given number is an even number”   }

          else   {

               print “”The given number is an odd number”   }   }

The above program has a constant time of running where the input is independent to the time taken by this algorithm to compute.

O(N)

Consider an array of integer elements adding 2 to each.

for (int i=0; i<array.length; i++)   {

     array[i] = array[i] + 2;   }

The above code has a loop running for n iterations representing the size of array n.

O(N²)

Consider the addition of two 2 – dimensional arrays of integers arrayA and arrayB.

for (int i=0; i<arrayA.rowlength; i++)   {

    for (int j=0; j<arrayB.columnlength; j++)   {

         sumarray[i][j] = arrayA[i][j] + arrayB[i][j];   }   }

The above code has two nested loop which will run for n * n iterations to get the result.

O(N³)

Consider the multiplication of two 2 – dimensional arrays of integers arrayA and arrayB.

sum = 0

for (int i=0; i<arrayA.rowlength; i++)   {

   for (int j=0; j<arrayB.columnlength; j++)   {

      for (int k=0; k<arrayA.columnlength; k++)   {

         sum = sum + arrayA[i][k] * arrayB[k][j];   }

      sum[i][j] = sum;

      sum = 0;   }    }

The above has three nested loops which will run for n * n * n iterations to get the result. Note that the number loops does not equals to the power to the N of the complexity. It is noted only the number of iterations it should make to yield the result.

O(log N)

Consider an array of integers ranging from 1 to 100. Now, you need to find a number from that array. You follow a way called binary searching, where you split the total range into two halves and check where would the number you need to search fall. You repeat the same procedure again and again and finally, you get the result.

1_h-9gysybCLfvBIYNyUTwuQ.jpeg

When you keep on dividing the iterations again and again to gain the result then the algorithm will fall on this complexity.

Learning from what we learned before,

consider the following code,

for (int i=total; i>0; i/=2)   {

    for (int j=0; j<i; j++)   {

        print “Hello”   }   }

Form the above code, we have two loops where the outer loop ‘i’ runs for log N times and the inner loop ‘j’ runs for times. So, with these predictions, we cannot conclude that we have O(N * log N) time complexity for the whole algorithm. Since the outer loop reduces the total N size by half at each iteration we can say that we have N + (N/2) + (N/4) + … + 1 iterations => N [1 + (1/2) + (1/4) + … + (1/N)] => N [1 + (1)] => 2 * N => O(N).

Like and comment on this post and make sure you follow our blog to get notified at any time. Like and follow our Facebook page.

From,

Maria Irudaya Regilan J

Learning Big O notations | Part 1

     Big O notation is a mathematical notation that describes the behavior of a function when the argument tends towards a particular value or infinity. Big O notation is used in Computer Science to describe the performance or complexity of an algorithm. Big O specifically describes the worst-case scenario and can be used to describe the execution time required or the space used.

Consider the following example,

     boolean contains (array, x)   {

         for each element in array     {

             if element == x {

                 return true } } }

In the above code, the loop has n iterations in the array which is said to be N. For a worst case scenario it can be written as O(N) where N represents the size of the array n.

Consider the example,

    void pairs (array) {

        for each x in array {

            for each y in array {

                print x, y } } }

In the above code, the nested loops have n x n iterations in the array which is said to be N x N. For a worst case scenario it can be written as O(N x N) => O(N²) where N represents the size of the array n or it can also be written as O(M) if M = N².

Some of the points that have to be followed on Big O notation

(i) If you have two different steps in algorithm add up those steps and drop the constants.

consider the example,

void display (arrayA)   {

for each element in arrayA   {

print element   }

for each element in arrayA    {

print element    }    }

In the above code, the loop has n iterations in the array which is said to be N and the same loop is repeated twice. For a worst case scenario, it can be written as O(N+N) => O(2N) => O(N) where N represents the size of the array n.

   (ii) Use different variables for different inputs

consider the example,

int count(arrayA, arrayB)     {

int count = 0

for a in arrayA   {

for b in arrayB    {

if a == b    {

count = count + 1    }   }   }

return count   }

In the above code, the loop of arrayA has m iterations and the loop of arrayB has n iterations which are said to be M and N respectively. For a worst case scenario, it can be written as O(M * N) where M and N represent the size of the array m and array n respectively.

(iii) Drop the non dominating terms

consider the following example.

function doSomething (array)   {

max = NULL

for a in array   {

print a   }

for a in array   {

for b in array   {

print max(a, b)   }   }   }

In the above code, the first loop has time complexity of O(N) and the second loop has the complexity of O(N²). When on finding the complexity of the whole code, we need to add and hence the result will be O(N + N²) where it lies between the complexities between O(1 * N²) => O(N²) and O(2 * N²) => O(N² + N²). So we can eliminate the non-dominate term N and hence can be written as O(N²).

Like and comment on this post and make sure you follow our blog to get notified at any time. Like and follow our Facebook page.

From,

Maria Irudaya Regilan J

Sending e-Mail using Python

Python is a powerful language which helps us to do anything which we dream of. In other words we can narrate python as the easiest way to make our dreams come true. In this article we are going to learn on how to send email to any person.

The python code for sending email is as follows:

 

import smtplib   #this imports the smtp library

server=smtplib.SMTP(“smtp.gmail.com”,587)   #we are using the gmail server, its port number for sending our mails

server.starttls()   #it returns an acknowledgement as it is ready to send mails

server.login(<sender_mail>,<sender_password>)   #filling up the authentication details

server.sendmail(<sender_mail>,<receiver_mail>,<your message>)   #sending the mail

server.quit()   #turning off the server

 

By,

Maria Irudaya Regilan J

You can also surf our blog to learn more things on python! Go to search bar and type python for interesting articles.

IMAGE PROCESSING

Introduction

Image processing is method to perform some operation on an image, in order to get an enhanced image or to extract some useful information from it. The analysis and manipulation of a digitized image, especially in order to improve. It’s improve the content and quality of an image and its design to manipulate digital image. Now a days image processing is widely used in many field the theoretical basics of image processing, along with its application, is an extensive topic that cannot be adequately covered here but that has been presented in a number of texts dedicated exclusively to this.

For example: Defence, medical image, bio-imaging, neuro-imaging, computer vision. It analysis the dark image to identify the clear image.

With a minimum investment, one can reality enhance contract, quantify intensity, detect edges, and apply various mathematical operation in this processing. Crop the image to remove unwanted clutter. Improve the visual appearance of images to a human viewer.

Analog Filters for Data Conversion

It is a type of signal processing in which input is an image and output may be image or characteristics/feature association with image. The method used for image processing are analog and digital image processing. Analog or visual techniques of image processing can be used forthehard copies like print out and photographs.

TYPES OF IMAGE PROCESSING:

  • Image to image transformation
  • Image to information transformation
  • Information to image transformation

Processing Image

IMAGE TO IMAGE TRANSFORMATION:

  • Enhancement to make image more useful and pleasing.
  • Restoration to remove the grid.
  • Geometry to scaling, sizing, zooming, morphing one object to another.

Image Processing in Medical

IMAGE TO INFORMATION TRANFORMATION:

  • Image statistics is histogram. Histogram is the fundamental tool for analysis and image processing.
  • Imagecompression.
  • Image analysis is segmentation, feature extraction, patternrecognition.
  • Computer-aided detection and diagnosis(CAD).

INFORMATION TO IMAGE TRANFORMATION:

  • Decompression to compressed image data.
  • Reconstruction of image slices from CT or MRI raw data.
  • Computer graphics, animation and virtual reality(synthetic object).

COMPUTER GRAPHICS:

We don’t often think of computer graphics as image processing because it processing 2D and 3D image definition files rather than the resulting image themselves. It is fine point, but worthy of note. Example include maps, posters, videos and movies.

MEDICAL IMAGING:

This type focuses on processing that helps with issues detection and diagnosis. Example include; Biological (non-invasive visualization of biological processes) and Neuroimaging (visualization of the nervous system).

OVERVIEW OF IMAGE PROCESSING:

Image processing refer to quantitative analysis and/or algorithm applied to digital image data. It allow generation of 3D parametric maps and implies calculation of values that should be ultimate (replication, rater-independent) .
Digital processing techniques help in manipulation of the digital image by computers. As raw data from imaging sensors from satellite platform contains deficiencies.The Three general phases of processing that all types of data have to undergo while using digital technique are pre-processing, enhancement and display, information extraction.

When looking under water with a camera, the user is hampered by low contract, color change and interference. Imagery may undergo a shift in hue with respect to the original scene due to filtering of the water. A color correction and restoring the original color of the scenario as well as possible.

Overview of Image Processing

While PERFORMING this sub-pixel estimation, adaptive image integration reduce temporal noise,which in turn decreases sea snow. A main drawback of such method is that applying only contract enhancement will also amplify camera noise and sea snow. Note that not only is the contract of the contrast of the object enhanced, but the sea snow.

Follow our blog for more articles and ideas on programming language. We also provide cheat sheets for many widely used programming languages!

From,

Jayashree Mohan | ECA at Regins

Jayashree Mohan 🙂

(Executive Content Advisor)

Quantum Computing

What is it?

Quantum computing studies computation systems (quantum computers) that make direct use of quantum-mechanical phenomena, such as superposition and entanglement, to perform operations on data.

quantum computing section.jpg

  • Quantum computers are different from binary digital electronic computers based on transistors. Quantum computation uses quantum bits, which can be in superpositions of states rather than encoding of data into bits.
  • A Quantum Turing machine is a theoretical model of such a computer, and is also known as the universal quantum computer.

qtm.png

  • It takes advantage of the strange ability of subatomic particles to exist in more than one state at any time. Due to the way the tiniest of particles behave, operations can be done much more quickly and use less energy than classical computers.

 How it is useful?

Quantum computers uses qubits which are combination of bits. Consider an electron that either in the position of Stop(0) or on motion(1). This is the principle followed by our computers. But in quantum computers, a new state is introduced called Superposition. It is the state where both 0 and 1 exists  at the same time. Therefore, the cases in which the inputs will be are 00, 01, 10 and 11.

I13-11-qbit.jpg

Now we can see that one qubits can hold information of 2 bits. This is interesting right? Also, another interesting matter between these bits is the concept of Entanglement. It is the concept in which both the classical bits in a single quantum bit is connected. In simple words, two classical bits in a quantum bit is subject to change if one of its pair changes.

download (4).jpg

Why it is not replaced?

Qubits do not make the things work faster but it make multiple things to work faster when combined.

Slide4

The speed of a classical computer and quantum computer is same on opening a MS word document but the speed of quantum computer won’t be slow on editing 50 MS Word documents which makes the classical computers slow.

Is it existing?

Yes. Quantum computers are not different in physical structure but it is a processor.

download (5)          NASA and Google are currently using quantum computers for their research and development purposes. D’ WAVE is the quantum computing company who were in research on making computers to think.images (12)

Quantum computers are made to solve unanswerable question like ‘what is the factorial of 500?’ or ‘Are we alone?’. Next time, when you see a quantum computer just don’t forget to ask a question to it.

Catch up more cool stuffs from our blog. We have some many categories like Programming and Education that may help you. Follow the blog to receive latest updates.

From,

Maria Irudaya Regilan J