Anvi Jain

Anvi Jain

427 Articles Published

Articles by Anvi Jain

Page 33 of 43

C++ Program to Implement Traveling Salesman Problem using Nearest Neighbour Algorithm

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 1K+ Views

Here is a C++ Program to Implement Traveling Salesman Problem using Nearest Neighbour Algorithm.Required functions and pseudocodesAlgorithmBegin    Initialize c = 0, cost = 1000;    Initialize g[][].    function swap() is used to swap two values x and y.    function cal_sum() to calculate the cost which take array a[] and size of array as input.    Initialize sum = 0.    for i = 0 to n       compute s+= g[a[i %3]][a[(i+ 1) %3]];    if (cost >s)       cost = s    function permute() is used to perform permutation:       if ...

Read More

MySQL format time with lowercase am/pm?

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 804 Views

To format MySQL time with lowercase am/pm, use the LOWER() as well as DATE_FORMAT().Let us first create a table −mysql> create table formatTime    -> (    -> LoginTime time    -> ); Query OK, 0 rows affected (0.56 sec)Following is the query to insert records in the table using insert command −mysql> insert into formatTime values('12:40:34'); Query OK, 1 row affected (0.20 sec) mysql> insert into formatTime values('14:10:58'); Query OK, 1 row affected (0.13 sec) mysql> insert into formatTime values('16:56:40'); Query OK, 1 row affected (0.18 sec) mysql> insert into formatTime values('10:12:14'); Query OK, 1 row ...

Read More

C++ program to Check if a Given Binary Tree is an AVL Tree or Not

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 2K+ Views

AVL tree is a self-balancing Binary Search Tree where the difference between heights of left and right subtrees cannot be more than one for all nodes.This is a C++ program to check if a given Binary Tree is an AVL Tree or not.AlgorithmBegin function AVL() returns true if the given tree is AVL otherwise false.    if(root == NULL)       return 1    leftheight = height(root->left)    rightheight = height(root->right)    if(abs(leftheight-rightheight) left) && AVL(root->right))       return 1    return 0 EndExample#include using namespace std; class nod { //node declaration    public:    int data; ...

Read More

Reorder integer except for value 0 with MySQL?

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 133 Views

To reorder integer except for value 0, use the below syntax −select *from yourTableName order by yourColumnName=0 ,yourColumnName;Let us first create a table −mysql> create table reorderIntegerExcept0    -> (    -> value int    -> ); Query OK, 0 rows affected (0.70 sec)Following is the query to insert records in the table using insert command −mysql> insert into reorderIntegerExcept0 values(90); Query OK, 1 row affected (0.17 sec) mysql> insert into reorderIntegerExcept0 values(10); Query OK, 1 row affected (0.21 sec) mysql> insert into reorderIntegerExcept0 values(0); Query OK, 1 row affected (0.18 sec) mysql> insert into reorderIntegerExcept0 values(40); ...

Read More

How to generate different random numbers in a loop in C++?

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 4K+ Views

Let us see how to generate different random numbers using C++. Here we are generating random numbers in range 0 to some value. (In this program the max value is 100).To perform this operation we are using the srand() function. This is in the C++ library. The function void srand(unsigned int seed) seeds the random number generator used by the function rand.The declaration of srand() is like below −void srand(unsigned int seed)It takes a parameter called seed. This is an integer value to be used as seed by the pseudo-random number generator algorithm. This function returns nothing.To get the number ...

Read More

C++ Program to Implement Direct Addressing Tables

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 737 Views

This is a C++ program to implement Direct Addressing Tables. Direct Addressing Tables are used when each element has a key drawn from a universal set S = {0, 1, . . . ,n − 1} where n isn’t too large and each key is unique. It facilitates fast insertion, searching and deletion operations.Functions and pseudocodesBegin    insert():       Take the table variables word and key as argument.       T[ x.key ] = x, where x is a value of key.    delete():       Take the table variables word and key as argument.   ...

Read More

C++ Program to Implement Gauss Jordan Elimination

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 6K+ Views

This is a C++ Program to Implement Gauss Jordan Elimination. It is used to analyze linear system of simultaneous equations. It is mainly focused on reducing the system of equations to a diagonal matrix form by row operations such that the solution is obtained directly.AlgorithmBegin    n = size of the input matrix    To find the elements of the diagonal matrix:    Make nested for loops j = 0 to n and i = 0 to n       The element in the first row and the first column is made 1       and then the ...

Read More

C++ Program to Apply Above-Below-on Test to Find the Position of a Point with respect to a Line

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 629 Views

This is a C++ program to apply Above-Below-on Test to find the position of a point with respect to a Line. For any point t (xt, yt) on the plane, its position with respect to the line L connecting m and n is found by calculating the scalar s −Y = A xt + B yt + CIf Y< 0, t lies in the clockwise halfplane of L; if Y>0, t lies on the counter-clockwise halfplane; if Y= 0, t lies on L.AlgorithmBegin    Take the points as input.    For generating equation of the line, generate random numbers for ...

Read More

C++ Program to use above below primitive to test whether two lines intersect

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 254 Views

Here is a C++ program to use above below primitive to test whether two lines intersect. It can be used to test whether a line intersects a line segment. It does if and only if one endpoint of the segment is to the left of the line and the other is to the right.AlgorithmBegin    For generating equation of the first line, generate random numbers for coefficient of x and y by using rand at every time of compilation.    For generating equation of the second line, generate random numbers for coefficient of x and y by using rand at ...

Read More

C++ Program to Optimize Wire Length in Electrical Circuit

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 388 Views

This is a C++ Program to optimize Wire Length in Electrical Circuit.AlgorithmBegin    Function optimizeLength() :    1) Declare a array dist[N].    2) sptSet[i] will be true if component i is included in shortest    path tree or shortest distance from src to i is finalized.    3) Initialize all distances as INFINITE and stpSet[] as false    4) Distance of source component from itself will be always 0.    5) Run a for loop cnt = 0 to N-2, Find shortest path for all components.       A) Pick the minimum distance component from the set of ...

Read More
Showing 321–330 of 427 articles
« Prev 1 31 32 33 34 35 43 Next »
Advertisements