To generate a row index, use ROW_NUMBER(). Let us first create a table −mysql> create table DemoTable ( Name varchar(40) ); Query OK, 0 rows affected (0.49 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Chris'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values('Chris'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('Robert'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('Robert'); Query OK, 1 row affected (0.14 sec) mysql> insert into ... Read More
You can use REGEXP. Let us first create a table −mysql> create table DemoTable ( Name varchar(100) ); Query OK, 0 rows affected (1.61 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('JohnSmith'); Query OK, 1 row affected (0.73 sec) mysql> insert into DemoTable values('John Doe'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('DavidMiller'); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable values('Carol Taylor'); Query OK, 1 row affected (0.27 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following ... Read More
Mark and Sweep algorithmMark and Sweep algorithm looks out for objects 'which are unreachable' rather than objects 'which are no longer needed'. This algorithm is the improvement of Reference-counting algorithm.This algorithm actually goes through 3 important steps. Root: In general, a root is a global variable that is used in the code. A window object in javascript can act as a root. This algorithm uses global object root to find whether the objects are reachable or unreachable.This algorithm then monitors every root and also their children. While monitoring, some objects which are reachable are marked and remaining objects which are ... Read More
Memory leaks in JavaScriptJavaScript is called garbage collected language, that is when variables are declared, it will automatically allocate memory to them. When there are no more references for the declared variables, allocated memory will be released. Memory leaks or most of the memory related problems will occur while releasing the memory. Some common JavaScript leaks 1) Accidental global variablesWhen a undeclared variable is referenced, javascript creates a new variable in the global object. In the following Example-1 let's say the purpose of languages is to only reference a variable in the "myArray" function. If we don't use var to declare it ... Read More
In this section we will see how to find the area of a triangle in 2D coordinate space using matrix determinants. In this case we are considering the space is 2D. So we are putting each points in the matrix. Putting x values at the first column, y into the second and taking 1 as the third column. Then find the determinant of them. The area of the triangle will be half of the determinant value. If the determinant is negative, then simply take the absolute value of it.$$Area\:=\:absolute\:of\begin{pmatrix}\frac{1}{2} \begin{vmatrix} x_1\:\:y_1\:\:1 \ x_2\:\:y_2\:\:1 \ x_3\:\:y_3\:\:1 \end{vmatrix} \end{pmatrix}$$Here we are assuming ... Read More
In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven a list iterable as input, we need to display odd numbers in the given iterable.Here we will be discussing three different approaches to solve this problem.Approach 1 − Using enhanced for loopExamplelist1 = [11, 23, 45, 23, 64, 22, 11, 24] # iteration for num in list1: # check if num % 2 != 0: print(num, end = " ")Output11, 23, 45, 23, 11Approach 2 − Using lambda & filter functionsExample Live Demolist1 = [11, 23, 45, 23, ... Read More
In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven a list iterable, we need to print all the negative numbers in the list.Here we will be discussing three approaches for the given problem statement.Approach 1 − Using enhanced for loopExamplelist1 = [-11, 23, -45, 23, -64, -22, -11, 24] # iteration for num in list1: # check if num < 0: print(num, end = " ")Output-11 -45 -64 -22 -11Approach 2 − Using filter & lambda functionExample Live Demolist1 = [-11, 23, -45, 23, -64, -22, -11, ... Read More
In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven a dictionary, we need to find the three highest valued values and display them.Approach 1 − Using the collections module ( Counter function )Example Live Demofrom collections import Counter # Initial Dictionary my_dict = {'t': 3, 'u': 4, 't': 6, 'o': 5, 'r': 21} k = Counter(my_dict) # Finding 3 highest values high = k.most_common(3) print("Dictionary with 3 highest values:") print("Keys: Values") for i in high: print(i[0], " :", i[1], " ")OutputDictionary with 3 highest values: Keys: Values r : 21 t ... Read More
In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven a number we need to convert into a binary number.Approach 1 − Recursive SolutionDecToBin(num): if num > 1: DecToBin(num // 2) print num % 2Exampledef DecimalToBinary(num): if num > 1: DecimalToBinary(num // 2) print(num % 2, end = '') # main if __name__ == '__main__': dec_val = 35 DecimalToBinary(dec_val)Output100011All the variables and functions are declared in the global scope as shown below −Approach 2 − Built-in SolutionExample Live Demodef ... Read More
In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven list input, we need to find the largest numbers in the given list .Here we will discuss two approachesUsing sorting techniquesUsing built-in max() functionApproach 1 − Using built-in sort() functionExample Live Demolist1 = [18, 65, 78, 89, 90] list1.sort() # main print("Largest element is:", list1[-1])OutputLargest element is: 90Approach 2 − Using built-in max() functionExample Live Demolist1 = [18, 65, 78, 89, 90] # main print("Largest element is:",max(list1))OutputLargest element is: 90ConclusionIn this article, we learnt about the approach to find largest number in a list.