A graph can be represented using Adjacency Matrix way.Adjacency MatrixAn Adjacency Matrix A[V][V] is a 2D array of size V × V where $V$ is the number of vertices in a undirected graph. If there is an edge between Vx to Vy then the value of A[Vx][Vy]=1 and A[Vy][Vx]=1, otherwise the value will be zero.For a directed graph, if there is an edge between Vx to Vy, then the value of A[Vx][Vy]=1, otherwise the value will be zero.Adjacency Matrix of an Undirected GraphLet us consider the following undirected graph and construct the adjacency matrix −Adjacency matrix of the above undirected ... Read More
Mathematics can be broadly classified into two categories −Continuous Mathematics − It is based upon continuous number line or the real numbers. It is characterized by the fact that between any two numbers, there are almost always an infinite set of numbers. For example, a function in continuous mathematics can be plotted in a smooth curve without breaks.Discrete Mathematics − It involves distinct values; i.e. between any two points, there are a countable number of points. For example, if we have a finite set of objects, the function can be defined as a list of ordered pairs having these objects, ... Read More
The eval() method parses the expression passed on to this method and runs the expression within the program. In other words, it interprets a string as code inside a python program.SyntaxThe Syntax for eval is as below −eval(expression, globals=None, locals=None)WhereExpression − It is the python expression passed onto the method.globals − A dictionary of available global methods and variables.locals − A dictionary of available local methods and variables.In the below example we allow the user to cerate an expression and run a python program to evaluate that expression. So it helps in create dynamic code.Example Live Demo# expression to be evaluated ... Read More
The TIMESTAMP data type is used for values containing both date and time parts. Let us first create a table −mysql> create table DemoTable662( UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY, UserName varchar(100), UserPostDate datetime ); Query OK, 0 rows affected (0.50 sec)Following is the query for valid default timestamp values −mysql> alter table DemoTable662 MODIFY COLUMN UserPostDate TIMESTAMP NOT NULL DEFAULT current_timestamp; Query OK, 0 rows affected (1.81 sec) Records: 0 Duplicates: 0 Warnings: 0Let us check the description of table once again −mysql> desc DemoTable662;This will produce the following output −+--------------+--------------+------+-----+-------------------+----------------+ | Field | ... Read More
Manytimes we need to split a given string into multiple parts based on some delimiter. Python provides a function named split() which can be used to achieve this. It also provides a way to control the delimiter and number of characters to be considered as delimiter.ExampleIn the below example we a string containing many words and space in between. But there are two space characters between Banana and grape. Accordingly the split happens. When no parameter is supplied each space is taken as a delimiter. Live Demostr = "Apple Banana Grapes Apple"; print(str.split()) print(str.split(' ', 2))OutputRunning the above code gives us ... Read More
The OR operator gives true result when any one operand is true. Let us now see an example and create a table −mysql> create table DemoTable663(ClientId int, ClientName varchar(100), ClientAge int); Query OK, 0 rows affected (0.55 sec)Insert some records in the table using insert command −mysql> insert into DemoTable663 values(100, 'Chris', 45); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable663 values(101, 'Robert', 29); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable663 values(102, 'John', 45); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable663 values(103, 'Chris', 35); Query OK, 1 row affected ... Read More
Let us first create a table and set default values −mysql> create table DemoTable803(UserId int DEFAULT 101, UserName varchar(100) DEFAULT 'Chris'); Query OK, 0 rows affected (1.18 sec)Insert some records in the table using insert command. For the values we are not inserting, the default values will get set automatically −mysql> insert into DemoTable803 values(102, 'Chris'); Query OK, 1 row affected (0.34 sec) mysql> insert into DemoTable803(UserName) values('Mike'); Query OK, 1 row affected (0.48 sec) mysql> insert into DemoTable803(UserId) values(103); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable803 values(); Query OK, 1 row affected (0.22 sec) mysql> ... Read More
Many times we need to look into the python documentation for some help on functions, modules etc. Python provides a help function that gives us this needed results.SyntaxHelp(‘term’) Where term is the word on which we want the help.ExampleIn the below example we seek to find help on the word time. The output comes from python documentation and it is quite exhaustive. Live Demoprint(help('time'))OutputRunning the above code gives us the following result −Help on built-in module time: NAME time - This module provides various functions to manipulate time values. DESCRIPTION There are two standard representations of time. One is the ... Read More
To extract from datetime column, you can use date() along with trim(). Here, trim() is used to remove whitespace while comparing. Let us first create a table −mysql> create table DemoTable661(Duedate datetime); Query OK, 0 rows affected (0.57 sec)Insert some records in the table using insert command −mysql> insert into DemoTable661 values(' 2019-01-21 12:02:21'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable661 values(' 2019-07-11 11:55:59 '); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable661 values('2019-11-21 04:00:59 '); Query OK, 1 row affected (0.10 sec)Display all records from the table using select statement −mysql> select ... Read More
We sometimes arrive at a situation where we have two lists and we want to check whether each item from the smaller list is present in the bigger list or not. In such case we use the filter() function as discussed below.SyntaxFilter(function_name, sequence name)Here Function_name is the name of the function which has the filter criteria. Sequence name is the sequence which has elements that needs to be filtered. It can be sets, lists, tuples, or other iterators.ExampleIn the below example we take a bigger list of some month names and then filter out those months which does not have ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP