Server Side Programming Articles

Page 2095 of 2109

C++ Program to Implement Hash Tables with Double Hashing

Samual Sam
Samual Sam
Updated on 30-Jul-2019 3K+ Views

A hash table is a data structure which is used to store key-value pairs. Hash function is used by hash table to compute an index into an array in which an element will be inserted or searched.Double hashing is a collision resolving technique in Open Addressed Hash tables. Double hashing uses the idea of using a second hash function to key when a collision occurs.This is a C++ program to Implement Hash Tables chaining with double hashing.AlgorithmFor search a key:Begin    Declare Function SearchKey(int k, HashTable *ht)       int hashVal= HashFunc1(k, ht->s)       int stepSize= HashFunc2(k, ...

Read More

C++ Program to Implement Hash Tables with Linear Probing

Samual Sam
Samual Sam
Updated on 30-Jul-2019 10K+ Views

A hash table is a data structure which is used to store key-value pairs. Hash function is used by hash table to compute an index into an array in which an element will be inserted or searched.Linear probing is a collision resolving technique in Open Addressed Hash tables. In this method, each cell of a hash table stores a single key–value pair. If a collision is occurred by mapping a new key to a cell of the hash table that is already occupied by another key. This method searches the table for the following closest free location and inserts the ...

Read More

C++ Program to Perform Operations in a BST

Daniol Thomas
Daniol Thomas
Updated on 30-Jul-2019 3K+ Views

         A Binary Search Tree is a sorted binary tree in which all the nodes will have following properties−The right sub-tree of a node has a key greater than to its parent node's key.The left sub-tree of a node has a key lesser than to its parent node's key.All key values are distinct.Each node cannot have more than two children.Class Descriptions:Begin    class BST to declare following functions:       search() = To search an item in BST.       initialize temp = root;       while(temp != NULL)          Increase ...

Read More

What is difference between int and const int& in C/C++?

Smita Kapse
Smita Kapse
Updated on 30-Jul-2019 4K+ Views

Here we will see what are the differences between int and const_int& in C or C++.The int is basically the type of integer type data. And const is used to make something constant. If there is int& constant, then it indicates that this will hold the reference of some int type data. This reference value is constant itself. So the const is redundant. The compiler may return warning or some error.The const int& is same as int const&. So this refers to a constant integer. The integer cannot be modified through the reference.

Read More

Is it legal to recurse into main() in C++?

Jennifer Nicholas
Jennifer Nicholas
Updated on 30-Jul-2019 170 Views

In C or C++, the main function is like other functions. So we can use the functionalities that are present in some other functions, also in the main function.In the following program, we will see how the main() is using recursively to print some numbers in reverse order.Example Code#include using namespace std; int main () {    static int x = 10;    cout

Read More

What is 0 (zero) - A decimal literal or An octal literal in C++

Nitya Raut
Nitya Raut
Updated on 30-Jul-2019 687 Views

The 0 (Zero) before a number is basically the octal literal.In C/C++ we can use octal literals by typing a zero before the actual number. For example, if an octal number is 25, then we have to write 025.Example Code#include int main() {    int a = 025;    int b = 063;    printf("Decimal of 25(Octal) is %d", a);    printf("Decimal of 63(Octal) is %d", b); }OutputDecimal of 25(Octal) is 21 Decimal of 63(Octal) is 51

Read More

C++ Program to Implement a Binary Search Algorithm for a Specific Search Sequence

Ankith Reddy
Ankith Reddy
Updated on 30-Jul-2019 631 Views

In this Program we need to implement binary search to find the existence of a search sequence in an array. The time complexity of Binary search is O(log(n)).Required steps and pseudocodesBegin    BinarySearch() function has ‘arr’ the array of data and ‘n’ the number of values, start and end index, iteration count and b[0] be the element to be searched in the argument list.    Increment the iteration counter and compare the item value with the a[mid].    If item < a[mid] choose first half otherwise second half to proceed further.    Return index value to main.    In main(), ...

Read More

C++ Program to Represent Graph Using Incidence List

George John
George John
Updated on 30-Jul-2019 385 Views

This program represents a graph using incidence list and the time complexity of this algorithm is O(e).AlgorithmBegin Take the input of the number of vertex ‘v’ and edges ‘e’ and also take the input of ‘e’ pairs of vertexes of the given graph in e[][]. For each edge print the corresponding vertex involved in that connection. EndExample Code#include using namespace std; int main() { int i, v, e, j, c; coutv; coute; int edge[e][2]; for(i = 0; i < e; i++) { cout

Read More

How do I use the conditional operator in C/C++?

Chandu yadav
Chandu yadav
Updated on 30-Jul-2019 326 Views

This conditional operator is also known as the Ternary Operator. This operator has three phase.Exp1 ? Exp2 : Exp3;where Exp1, Exp2, and Exp3 are expressions. Notice the use and placement of the colon. The value of a ? expression is determined like this: Exp1 is evaluated. If it is true, then Exp2 is evaluated and becomes the value of the entire ? expression. If Exp1 is false, then Exp3 is evaluated and its value becomes the value of the expression.The ? is called a ternary operator because it requires three operands and can be used to replace if-else statements, which ...

Read More

What's the difference between assignment operator and copy constructor in C++?

Ankith Reddy
Ankith Reddy
Updated on 30-Jul-2019 820 Views

The Copy constructor and the assignment operators are used to initialize one object to another object. The main difference between them is that the copy constructor creates a separate memory block for the new object. But the assignment operator does not make new memory space. It uses reference variable to point to the previous memory block.Copy Constructor (Syntax)classname (const classname &obj) { // body of constructor }Assignment Operator (Syntax)classname Ob1, Ob2; Ob2 = Ob1;Let us see the detailed differences between Copy constructor and Assignment Operator.Copy ConstructorAssignment OperatorThe Copy constructor is basically an overloaded constructorAssignment operator is basically ...

Read More
Showing 20941–20950 of 21,090 articles
Advertisements