Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Programming Articles - Page 2837 of 3366
2K+ Views
A Binary Search Tree (BST) is a type of binary tree such that the left subtree has elements smaller than the root element and the right subtree has elements greater than the root element. In this article, our task is to search for an element in the given Binary Search Tree. Characteristics of Binary Search Tree Here are some of the characteristics of the BST: The left subtree of the BST has elements less than the root element. The right subtree of the BST has elements greater than the root ... Read More
540 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
422 Views
Self-Organizing list basically updates the list of given range of items on the basis of last searched item. In this method, the sequential searching approach is used. This algorithm shifts the more important data to the beginning of the list. The time complexity of this search technique is O(n).AlgorithmBegin Function FibonacciSearch(). Calculate the mid value using ‘start+fib[index-2]’ expression. If the chosen item is equal to the value at mid index, print result and return to main. If it is lesser than the value at mid index, proceed with the left sub-array. If it is more ... Read More
614 Views
Binary Search and Sequential or Linear Search both are used in computer programming to search an element. The time complexity of Binary Search is O(log(n)) and Sequential Search is O(n).AlgorithmBegin Algorithm for Binary Search: BinarySearch() function with ‘arr’ the array of data and ‘n’ the number of values, start and end index, iteration count and element to be searched in the argument list. Increment 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 iteration value on successful search. EndExample Code#include ... Read More
3K+ Views
The quick sort technique is based on the partitioning of an array into smaller sub-arrays. It is based on the divide-and-conquer algorithm. The average time complexity of this algorithm is O(n*log(n)), but the worst complexity is O(n^2). To reduce the chances of the worst case, we implement the quick sort technique using randomization. In this article, we have an array having 6 elements. Our task is to sort the given array using the quick sort technique while avoiding the worst-case complexity. How to Implement Quick Sort with Given Complexity Constraint? In the ... Read More
356 Views
Stooge Sort is a recursive sorting algorithm used to sort the given data. The stooge sort divides the array into two overlapping parts, 2/3 each and then sort the array in three steps by sorting first then second and again first part. The worst case time complexity of this algorithm is O(n^2.7095). In this article, we have an unsorted array. Our task is to implement the stooge sort algorithm for sorting the given array in C++. Example Here is an example of sorting the given array using stooge sort: Input: array = {5, 3, 8, 4, 2, 7} ... Read More
2K+ Views
Shaker sort is a variation of bubble sort and is both a stable and comparison based sorting algorithm. The shaker sort is also known as cocktail sort or bidirectional bubble sort as it sorts the array in both directions. In this article, we have an unsorted array. Our task is to implement the shaker sort in C++ to sort the given array. Example The following example sorts the unsorted array using the shaker sort: Input: array = {5, 1, 4, 2, 8, 0, 2} Output: Sorted array = {0, 1, 2, 2, 4, 5, 8} The ... Read More
17K+ Views
In the 0-1 knapsack problem, a set of items is given, each with a weight and a value. We need to determine the number of each item to include in a collection so that the total weight is less than or equal to the given limit and the total value is as large as possible. In this article, we will discuss how to solve the 0-1 knapsack problem using dynamic programming. Dynamic Programming is a technique where we solve problems by breaking them into smaller sub-problems. If a subproblem is solved multiple times, DP stores the results so that we ... Read More
727 Views
Use the fromArray() method to create a Pair Tuple from Array.Let us first see what we need to work with JavaTuples. To work with Pair class in JavaTuples, you need to import the following package −import org.javatuples.Pair;Note − Steps to download and run JavaTuples program. If you are using Eclipse IDE to run Pair Class in JavaTuples, then Right Click Project ->Properties ->Java Build Path ->Add External Jars and upload the downloaded JavaTuples jar file.The following is an example −Exampleimport org.javatuples.Pair; public class Demo { public static void main(String[] args) { ... Read More
163 Views
Java does not have built-in tuple support; to use the tuple, we use the third-party library called Javatuples. This library provides classes representing fixed-size tuples of different sizes. The Septet class is one of these classes that represents a tuple with 7 values. Creating a Septet Tuple in Java We can create a Septet in Java in the following ways: Using a Constructor Using fromCollection() method Using with() method Using fromArray() method Using a Constructor The constructor of the Septet class ... Read More