MySQL Query to Select Top N Rows Efficiently

AmitDiwan
Updated on 02-Jul-2020 06:31:24

423 Views

Use index to select top n rows efficiently. Let us first create a table −mysql> create table DemoTable (StudentName varchar(100), StudentScore int ); Query OK, 0 rows affected (0.66 sec)ExampleInsert some records in the table using insert command −mysql> insert into DemoTable values('John', 34); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('Carol', 55); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('Bob', 58); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('Sam', 38); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Mike', 48); Query OK, 1 row ... Read More

Multidimensional Associative Arrays in PHP: How to Retrieve Values

AmitDiwan
Updated on 02-Jul-2020 06:30:47

2K+ Views

Multidimensional arrays store multiple arrays whereas associative arrays store key-value pairs as data. Grouped relation between data can be stored in multidimensional associative arrays.Example Live DemoOutputJoe 20An array is defined that contains various attributes of an employee. The employee array is accessed based on the index names and the data is displayed on the console.

Check Multidimensional Nature of an Array in PHP

AmitDiwan
Updated on 02-Jul-2020 06:28:53

2K+ Views

The ‘rsort’ function can be used to check if an array is multidimensional or not. It takes one parameter, i.e the array that needs to be checked and returns yes or no depending on the nature of the array.Example Live DemoOutputIs the array multi-dimensional? bool(true)An array is defined that contains string elements. A function named ‘multi_dim’ is defined that sorts the elements of the array using ‘rsort’. The ‘isset’ function is then used to perform ‘AND’ operation on the elements of the array. This would help understand if the array has a single dimension or is multi-dimensional.Read More

Different Ways of Checking if an Array is Empty in PHP

AmitDiwan
Updated on 02-Jul-2020 06:27:29

550 Views

Using the ‘sizeof’ functionLet us see an example −Example Live DemoOutputThe array is empty!An array can be checked to see if it is empty or not in multiple ways. One method is to use the ‘sizeof’ function that sees if the array is empty. If yes, the size would be 0, thereby confirming the array being empty.Using the ‘empty’ functionExample Live DemoOutputThe array is non-empty The array is empty!Another method to check if an array is empty or not is to use the ‘empty’ function, that checks to see the contents of the array, and if nothing is present, says it is ... Read More

Removing Empty Array Elements in PHP

AmitDiwan
Updated on 02-Jul-2020 06:23:49

683 Views

To remove empty array elements in PHP, the code is as follows −Example Live DemoOutputAfter removing null values from the array, the array has the below elements -This 91 102 is a sampleAn array is defined, that contains strings, numbers and ‘null’ values. The ‘foreach’ loop is used to iterate over the elements and if a value is empty, i.e. it contains null, then it is deleted from the array. The relevant array is displayed again that wouldn’t contain null values.

Binary Search Bisect in Python

Arnab Chakraborty
Updated on 02-Jul-2020 06:15:22

2K+ Views

Here we will see the bisect in Python. The bisect is used for binary search. The binary search technique is used to find elements in sorted list. The bisect is one library function.We will see three different task using bisect in Python.Finding first occurrence of an elementThe bisect.bisect_left(a, x, lo = 0, hi = len(a)) this function is used to return the left most insertion point of x in a sorted list. Last two parameters are optional in this case. These two are used to search in sublist.Examplefrom bisect import bisect_left def BinSearch(a, x):    i = bisect_left(a, x)   ... Read More

A Number Link Game

sudhir sharma
Updated on 02-Jul-2020 05:37:51

752 Views

Number link is a type of logic puzzle involving finding paths to connect numbers in a grid.A simple example of a Numberlink puzzle The solution to the Numberlink puzzleRules − The player has to pair up all the matching numbers on the grid with single continuous lines (or paths). The lines cannot branch off or cross over each other, and the numbers have to fall at the end of each line (i.e., not in the middle). It is considered that a problem is well-designed only if it has a unique solution and all the cells in the grid are filled, ... Read More

Add All Greater Values to Every Node in a Given BST

sudhir sharma
Updated on 01-Jul-2020 14:57:28

260 Views

A BST or binary search tree is a form of binary tree that has all left nodes smaller and all right nodes greater than the root value. For this problem, we will take a binary tree and add all the values greater than the current node to it. the problem “ add all greater values to every node in BST” is simplified as for a BST add all the node values that are greater than the current node value to that node value.Add all greater values to each node in the BST Problem Statement:Given a Binary Search Tree (BST), we ... Read More

C++ Program for Odd-Even Sort (Brick Sort)

Arnab Chakraborty
Updated on 01-Jul-2020 14:31:25

523 Views

Here we will see how the brick sort works. The Brick sort is one modification of bubble sort. This algorithm is divided into two parts. These parts are odd part and even parts. In the odd part we will use the bubble sort on odd indexed items, and in the even part we will use the bubble sort on even indexed elements. Let us see the algorithm to get the idea.AlgorithmbrickSort(arr, n)begin    flag := false    while the flag is not true, do       flag := true       for i := 1 to n-2, increase ... Read More

HTML DOM Input Time stepUp Method

AmitDiwan
Updated on 01-Jul-2020 14:18:00

126 Views

The HTML DOM Input Time stepUp() method defines the number of minutes the Time field should increase.SyntaxFollowing is the syntax −Calling stepUp() method with a number, which by default is equal to 1inputTimeObject.stepUp(number)ExampleLet us see an example of Input Time stepUp method − Live Demo Input Time stepUp()    form {       width:70%;       margin: 0 auto;       text-align: center;    }    * {       padding: 2px;       margin:5px;    }    input[type="button"] {       border-radius: 10px;    } Time-stepUp( ) ... Read More

Advertisements