Convert YYYYMMDD Integer to Date

AmitDiwan
Updated on 26-Sep-2019 06:51:43

301 Views

For this, you can use the DATE() function. Let us first create a table −mysql> create table DemoTable (    Number int ); Query OK, 0 rows affected (0.48 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(20190108); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(20161231); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(20170411); Query OK, 1 row affected (0.09 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+----------+ | Number   | +----------+ | 20190108 | ... Read More

Find Average of Column Values in MySQL Using Aggregate Function

AmitDiwan
Updated on 26-Sep-2019 06:48:43

120 Views

Let us first create a table −mysql> create table DemoTable (    Number int ); Query OK, 0 rows affected (0.79 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(56); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(78); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(89); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(98); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values(91); Query OK, 1 row affected (0.35 sec) mysql> insert into DemoTable values(96); Query OK, 1 row affected ... Read More

Check If a Directed Graph Is Connected in C++

Arnab Chakraborty
Updated on 25-Sep-2019 14:54:52

2K+ Views

To check connectivity of a graph, we will try to traverse all nodes using any traversal algorithm. After completing the traversal, if there is any node, which is not visited, then the graph is not connected.For the directed graph, we will start traversing from all nodes to check connectivity. Sometimes one edge can have only outward edge but no inward edge, so that node will be unvisited from any other starting node.In this case the traversal algorithm is recursive DFS traversal.Input − Adjacency matrix of a graph0100000100000111000001000Output − The Graph is connected.Algorithmtraverse(u, visited) Input: The start node u and the ... Read More

Fleury's Algorithm for Printing Eulerian Path or Circuit in C++

Arnab Chakraborty
Updated on 25-Sep-2019 14:53:48

2K+ Views

Fleury’s Algorithm is used to display the Euler path or Euler circuit from a given graph. In this algorithm, starting from one edge, it tries to move other adjacent vertices by removing the previous vertices. Using this trick, the graph becomes simpler in each step to find the Euler path or circuit.We have to check some rules to get the path or circuit −The graph must be a Euler Graph.When there are two edges, one is bridge, another one is non-bridge, we have to choose non-bridge at first.sChoosing of starting vertex is also tricky, we cannot use any vertex as ... Read More

Python Program for Fibonacci Numbers

Pavitra
Updated on 25-Sep-2019 14:18:17

646 Views

In this article, we will learn about the solution and approach to solve the given problem statement.Problem statement −Our task to compute the nth Fibonacci number.The sequence Fn of Fibonacci numbers is given by the recurrence relation given belowFn = Fn-1 + Fn-2with seed values (standard)F0 = 0 and F1 = 1.We have two possible solutions to the problemRecursive approachDynamic approachApproach 1 −Recursive ApproachExample Live Demo#recursive approach def Fibonacci(n):    if n

Check Consecutive Occurrences of '1' in Binary String using C++

Arnab Chakraborty
Updated on 25-Sep-2019 14:03:49

221 Views

Here we will see another interesting problem. We have to write a code that accepts a string, which has following criteria.Every group of consecutive 1s, must be of length 2every group of consecutive 1s must appear after 1 or more 0sSuppose there is a string like 0110, this is valid string, whether 001110, 010 are not validHere the approach is simple. we have to find the occurrences of 1, and check whether it is a part of sub-string 011 or not. If condition fails, for any substring then return false, otherwise true.Example Live Demo#include using namespace std; bool isValidStr(string str) ... Read More

Check If a Binary String Has a 0 Between 1s in C++

Arnab Chakraborty
Updated on 25-Sep-2019 13:56:06

182 Views

Here we will see one interesting problem. We have to check whether a string has 0 in between a 1s or not. If not, then the string is valid, otherwise invalid.Suppose there are three strings −100011110100000111110001111101111From these three strings, only B is valid, because there is no 0 inside the stream of 1sTo solve this problem, we will find the index of first 1 present in the string, and also find the index of the last 1. Then we will check, is there any 0 from these two indices, if so, then return false, otherwise true (as valid)Example Live Demo#include ... Read More

Check for Integer Overflow in C++

Arnab Chakraborty
Updated on 25-Sep-2019 13:50:57

379 Views

The only safe way is to check for overflow before it occurs. There are some hacky ways of checking for integer overflow though. So if you're aiming for detecting overflow in unsigned int addition, you can check if the result is actually lesser than either values added. So for example, Exampleunsigned int x, y; unsigned int value = x + y; bool overflow = value < x; // Alternatively "value < y" should also workThis is because if x and y are both unsigned ints, if added and they overflow, their values can't be greater than either of them as ... Read More

Find One's Complement of an Integer in C++

Arnab Chakraborty
Updated on 25-Sep-2019 13:34:21

3K+ Views

In this section, we will see how to find the 1’s complete of an integer. We can use the complement operator to do this task very fast, but it will make 32bit complemented value (4-bype integer). Here we want complement of n bit numbers.Suppose we have a number say 22. The binary equivalent is 10110. The complemented value is 01001 which is same as 9. Now the question comes, how to find this value? At first we have to find number of bits of the given number. Suppose the count is c (here c = 5 for 22). We have ... Read More

Difference Between Sums of Odd and Even Digits in Python

Pavitra
Updated on 25-Sep-2019 13:20:27

612 Views

In this article, we will learn about the solution and approach to solve the given problem statement.Problem statement −Given an integer, we need to calculate if the difference between the sum of odd digits and sum of even digits is 0 or not.The brute-force approach will be calculating the sum of all even and odd digits in the numbers and subtracting them to compute the answer.To reduce the computational time we use the concept of mental mathematics .The above constraints holds true only if the numbers are divisible by 11. So here in the implementation given below we check the ... Read More

Advertisements