Posts

Showing posts from February, 2021

Computing square roots of numbers with Newton's method(Implementation in python)

Newton's method In this short article I will introduce you to how you can write a small python script that calculates square root of any number you give provided that your initial guess converges. You will also gain bragging rights on knowing how those smart guys calculate square roots of numbers in your calculator. From calculus we know that we can approximate functions by linearisation with the gradient of the said function and an example of this is the Taylor expansion series. In this article we will talk about the Newton's method which is used for estimating a solution of an equation of the form . I will explain how this works in the subsequent paragraph. From the equaltion of the line we know that or maybe you're more familiar with the equation of a slope given by . In Newton's method, we set to zero and solve for to obtain . Where a is our initial guess. Subsequently we plug the obtained as a and do this repeatedly till our solution gets close enough t...

Sorting Algorithms

Sorting algorithms Sorting Algorithms (Brief intro) In this article, I will describe the most popular sorting algorithms and implement them from their definitions. The little background story of my burgeoning interest in data structures and algorithms generally lies in the fact that I like hacking. However my decision to formally acquaint myself with the subject was precipitated by a potential job interview and I have not looked back since. Now lets get to it. Types of sort algorithms In place algorithms: these algorithms don't need additional memory. Stable algorithms: these algorithms don't change the original order of things after sorting. Bogo sort This algorithm is basically not your go to algorithm except you have a super computer. It basically gets all the possible permutations of the list to be sorted and then checks if they are sorted. The implementation can be seen below. xxxxxxxxxx # Here you need to sort with the permutation of all possibilities # Basically...