Posts

Showing posts with the label programming

NumPy

Image
NumPy is a python library used for applying high-level mathematical functions to multi-dimensional arrays and matrices. In our case it would help us in vectorization. Vectorization refers to the solution which allow the application of operations to an entire set of arrays at once instead of applying it one element at a time (as is done in case of loops) Vectorization is much much faster than the traditional loops and most computer can do it more efficiently ( Here is a sample of code to demonstrate just how fast it is) But before we start with matrices and vectorization and broadcasting and what not, let's start with the very basics and learn how to make and modify matrices NumPy is usually enabled by default, nevertheless. You can check check it from the Anaconda Navigator   (if you don't know about Anaconda Navigator and don't know how to install packages, check the following link ) Now, Open Jupyter notebooks, go to whatever folder you want to save the file in and let&#

Linked List

Image
Shall we start with the typical definition then? According to Wikipedia : In  computer science , a  linked list  is a linear collection of data elements, whose order is not given by their physical placement in memory. Instead, each element  points  to the next.   If this isn't clear (and I know it's not), lemme tell you how it's different from arrays and then the concept shall make itself more clear as we proceed from there. We can imagine an array as a long-ass bench in a class with a certain seating capacity (say 9), and there are 7 people sitting in it currently. When we initialize an array, we have to set it to a particular size. That size might be 7, 9, 10, or 100, or 1000 or whatever. But if we don't know exactly how many people are going to sit, how do we decide the size? If we take a huge-ass bench (big size array), it'll take a lot of space in the class (in computer memory), but if enough students don't show up, all that extra space would be wasted.  Co

Solving Sudoku

Image
What is Sudoku? So, before getting into the details of solving Sudoku with a computer program, before discussing its algorithm and going through all its steps, it’s only fair to introduce the game of Sudoku to everyone who’s unaware of what Sudoku is, or someone who kinda knows what it is, but has forgotten the exact rules. So, here’s what Sudoku is : (image source: https://en.wikipedia.org/wiki/Sudoku ) Sudoku is a number puzzle seen as a 9x9 grid that’s only partially filled by numbers from 1 to 9. The user has to completely fill in all the blank spaces, following 3 basic rules : 1 .  All the rows  of the Sudoku should have all the numbers (from 1 to 9) 2 .  All the columns should   have all the numbers (from 1 to 9) 3 .  And each of the sectors should   have all the numbers (again, from 1 to 9) Sectors are the smaller boxes (3x3) within the Sudoku, marked usually with thicker lines. The above image is an example of a Sudoku puzzle. It’s fairly