A spanning tree with assigned weight less than or equal to the weight of every possible spanning tree of a weighted, connected and undirected graph $G$, it is called minimum spanning tree (MST). The weight of a spanning tree is the sum of all the weights assigned to each edge of the spanning tree. Following are two most popular algorithms to find a minimum spanning tree (MST).Kruskal's AlgorithmKruskal's algorithm is a greedy algorithm that finds a minimum spanning tree for a connected weighted graph. It finds a tree of that graph which includes every vertex and the total weight of ... Read More
Let us first create a table −mysql> create table DemoTable666(AdmissionDate varchar(200)); Query OK, 0 rows affected (0.57 sec)Insert some records in the table using insert command −mysql> insert into DemoTable666 values('Sat, 20 Jul 2019 04:29:35'); Query OK, 1 row affected (1.12 sec) mysql> insert into DemoTable666 values('Fri, 02 Oct 2018 12:19:15'); Query OK, 1 row affected (1.05 sec) mysql> insert into DemoTable666 values('Sun, 01 Aug 2016 11:10:05'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable666 values('Fri, 06 Nov 2015 04:06:05 -0500'); Query OK, 1 row affected (0.24 sec)Display all records from the table using select statement −mysql> ... Read More
The TIMESTAMPDIFF() calculates the difference between two dates or datetime expressions. Let us first create a table −mysql> create table DemoTable665( PunchInTime datetime, PunchOutTime datetime, Details INT(11) AS (ABS(TIMESTAMPDIFF(second, PunchInTime, PunchOutTime))) )ENGINE=MyISAM; Query OK, 0 rows affected (0.23 sec)Insert some records in the table using insert command −mysql> insert into DemoTable665(PunchInTime, PunchOutTime) values('2019-09-21 9:30:10', '2019-09-21 04:34:56'); Query OK, 1 row affected (0.05 sec) mysql> insert into DemoTable665(PunchInTime, PunchOutTime) values('2019-11-11 10:00:20', '2019-11-11 05:30:16'); Query OK, 1 row affected (0.04 sec)Display all records from the table using select statement −mysql> select *from DemoTable665;This will produce the following output −+---------------------+---------------------+---------+ ... Read More
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
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP