Problem in Many Binary Search Implementations

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

143 Views

We know that the binary search algorithm is better than the linear search algorithm. This algorithm takes O(log n) amount of time to execute. Though most of the cases the implemented code has some problem. Let us consider one binary search algorithm function like below −Exampleint binarySearch(int array[], int start, int end, int key){    if(start key)          return binarySearch(array, start, mid-1, key);          return binarySearch(array, mid+1, end, key);    }    return -1; }This algorithm will work fine until the start and end reaches a large number. If the (start + end) ... Read More

Any DataType in C++ Boost Library

karthikeya Boyini
Updated on 30-Jul-2019 22:30:26

251 Views

The boost library has large range of functionalities. The any datatype is one of them. Any datatype is used to store any type of values in variable. Some other languages like javascripts, python, we can get this kind of datatypes. In C++ we can get this feature only using boost library.Example#include "boost/any.hpp" #include using namespace std; main() {    boost::any x, y, z, a; //define some variable of any datatype    x = 20; //Store x as integer    cout >> "x : " >> boost::any_cast(x) >> endl; //display the value of x    y = 'A'; //Store y ... Read More

Static Keyword in C++ vs Java

Smita Kapse
Updated on 30-Jul-2019 22:30:26

659 Views

In C++ or Java we can get the static keyword. They are mostly same, but there are some basic differences between these two languages. Let us see the differences between static in C++ and static in Java.The static data members are basically same in Java and C++. The static data members are the property of the class, and it is shared to all of the objects.Examplepublic class Test {    static int ob_count = 0;    Test() {       ob_count++;    }    public static void main(String[] args) {       Test object1 = new Test();   ... Read More

SQL Insert Items from List or Collection into Table using JDBC

Rishi Raj
Updated on 30-Jul-2019 22:30:26

6K+ Views

To insert the contents of a database to a collection, Connect to the database and retrieve the contents of the table into a ResultSet object using the SELECT Query.DriverManager.registerDriver(new com.mysql.jdbc.Driver()); String mysqlUrl = "jdbc:mysql://localhost/mydatabase"; Connection con = DriverManager.getConnection(mysqlUrl, "root", "password"); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("select * from MyPlayers");Create a Java class to hold the contents of each record, with a variable and, setter and getter methods for each column (with suitable datatype).For example, if the table sample in the database has two fields with the details −Column name: ID, datatype: INT(11)Column name: Name, datatype VARCHAR(255)Then, the variable ... Read More

Insert 8-Byte Integer into MongoDB using JavaScript Shell

Anvi Jain
Updated on 30-Jul-2019 22:30:26

226 Views

You can use below syntax for inserting an 8-byte integer in MongoDB through JavaScript shell −anyVariableName= {"yourFieldName" : new NumberLong("yourValue")};To display the above variable, you can use the variable name or printjson(). Following is the query to insert 8 byte integer in MongoDB −> userDetail = {"userId" : new NumberLong("98686869")}; { "userId" : NumberLong(98686869) }Let us display the above variable value using variable name. The query is as follows −> userDetailThis will produce the following output −{ "userId" : NumberLong(98686869) }Let us display the variable value using printjson() −> printjson(userDetail); This will produce the following output −{ "userId" : NumberLong(98686869) }

Change Header Background Color of a Table in Java

Anvi Jain
Updated on 30-Jul-2019 22:30:26

2K+ Views

To change header background color, at first get the header background −JTableHeader tableHeader = table.getTableHeader();Now, set the background color using set Background() −tableHeader.setBackground(Color.black);Above, we have used the Color class to set the color.The following is an example to change the header background color of a JTable −Examplepackage my; import java.awt.Color; import java.awt.Font; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.table.JTableHeader; public class SwingDemo {    public static void main(String[] argv) throws Exception {       Integer[][] marks = {          { 70, 66, 76, 89, 67, 98 },          { 67, 89, 64, ... Read More

PHP stripos Equivalent in MySQL

Kumar Varma
Updated on 30-Jul-2019 22:30:26

167 Views

The stripos() equivalent in MySQL is INSTR(), which returns the position of the first occurrence of a string in another string. Following is the syntax −select instr(yourColumnName, yourWord) As anyAliasName from yourTableName;Let us first create a table −mysql> create table DemoTable    -> (    -> Title text    -> ); Query OK, 0 rows affected (1.22 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('MySQL is my favourite subject'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('MongoDB is not my favourite subject'); Query OK, 1 row affected (0.20 sec)Display ... Read More

Check If Strings Are Rotations of Each Other

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

929 Views

Here we will see one program that can tell whether two strings are rotation of each other or not. The rotation of strings is like −Suppose two strings are S1 = ‘HELLO’, and S2 = ‘LOHEL’ So they are rotation of each other. By rotating HELLO three position to the left it will be LOHEL.To solve this problem, we will concatenate the first string with itself, then check whether the second one is present in the concatenated string or not. So for HELLO, it will be HELLOHELLO. Then this concatenated string contains the LOHEL. [HELLOHELLO].AlgorithmisRotation(str1, str2)begin    if lengths of ... Read More

The feclearexcept in C++

Samual Sam
Updated on 30-Jul-2019 22:30:26

67 Views

The feclearexcept() function is used to clear the supported floating point exceptions represented by the excepts.This function returns 0, if all exceptions are cleared, or the exception value is 0. And returns nonzero value for some exceptions.To use this function, we have to enable the FENV_ACCESS. This will give our program to access the floating point environment to test the exception raised.Example#include #include #include #pragma STDC FENV_ACCESS on using namespace std; main() {    feclearexcept(FE_ALL_EXCEPT);    sqrt(-5);    if (fetestexcept(FE_INVALID))       cout >> "sqrt(-5) will generate FE_INVALID" >> endl; }Outputsqrt(-5) will generate FE_INVALIDRead More

Collision Free Protocols

Arushi
Updated on 30-Jul-2019 22:30:26

19K+ Views

In computer networks, when more than one station tries to transmit simultaneously via a shared channel, the transmitted data is garbled. This event is called collision. The Medium Access Control (MAC) layer of the OSI model is responsible for handling collision of frames. Collision – free protocols are devised so that collisions do not occur. Protocols like CSMA/CD and CSMA/CA nullifies the possibility of collisions once the transmission channel is acquired by any station. However, collision can still occur during the contention period if more than one stations starts to transmit at the same time. Collision – free protocols resolves ... Read More

Advertisements