Server Side Programming Articles - Page 2335 of 2650

C++ Program to Perform Uniform Binary Search

Ravi Ranjan
Updated on 18-Aug-2025 16:07:46

425 Views

In this article, we have a sorted array of integers. Our task is to perform a uniform binary search to search for a target element. What is Uniform Binary Search? The uniform binary search is an improved version of the binary search algorithm where we use a pre-computed lookup table instead of calculating the middle element every time. The lookup table has elements that are powers of 2, starting from the larger value to 0, to decide the step for next iteration. The time complexity for uniform binary search is O(log n).Consider the following example scenarios to understand the ... Read More

C++ Program to Search Sorted Sequence Using Divide and Conquer with the Aid of Fibonacci Numbers

George John
Updated on 30-Jul-2019 22:30:25

564 Views

In this C++ program we implement a Divide and Conquer approach using Fibonacci numbers. Using Fibonacci numbers, we calculate mid of data array to search the data item. The time complexity of this approach is O(log(n)).AlgorithmBegin    Assign the data to the array in a sorted manner.    Take input of the element to be searched.    Call FibonacciSearch() function.    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 ... Read More

C++ Program to Find kth Largest Element in a Sequence

Ravi Ranjan
Updated on 18-Apr-2025 16:55:33

454 Views

In this article, we have an unsorted array. Our task is to find the kth maximum element of that array using C++. Here is an example to understand the meaning of k. If k =2, you can say the second highest value, for k =3, the third highest value. The approaches that we will be using are mentioned below: Using Sorting Using Max Heap Using Min Heap Using Quick Select Using Binary Search Tree Using ... Read More

C++ Program to Search for an Element in a Binary Search Tree

Ravi Ranjan
Updated on 16-Jun-2025 17:41:41

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

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

Ankith Reddy
Updated on 30-Jul-2019 22:30:25

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

C++ Program to Perform Searching Using Self-Organizing Lists

George John
Updated on 30-Jul-2019 22:30:25

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

C++ Program to Compare Binary and Sequential Search

Chandu yadav
Updated on 30-Jul-2019 22:30:25

615 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

C++ Program to Implement Quick Sort with Given Complexity Constraint

Ravi Ranjan
Updated on 03-Jun-2025 17:46:44

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

C++ Program to Perform Stooge Sort

Ravi Ranjan
Updated on 12-May-2025 16:50:14

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

C++ Program to Perform the Shaker Sort

Ravi Ranjan
Updated on 12-May-2025 16:50:32

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

Advertisements