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
C++ Articles - Page 671 of 719
304 Views
The binary search works on the divide and conquer principle as it keeps dividing the array into half before searching. For applying the binary search algorithm, the given array should be sorted. Since the array is sorted we do not need to search the minimum element in the array. In this article, the given array has strictly decreasing elements in the left sub-array till it reaches the minimum element and the right sub-array has strictly increasing elements. For example: {40, 30, 20, 10, 25, 35}. In this example, the array is decreasing till it ... Read More
525 Views
The binary search works on the divide and conquer principle as it keeps dividing the array into half before searching. For applying the binary search algorithm, the given array should be sorted. Since the array is sorted we do not need to search the maximum element in the array. Here, the given array is a Bitonic array. A bitonic array is an array in which the left sub-array has strictly increasing elements till it reaches the peak element and the right sub-array has strictly decreasing elements. For example: {10, 20, 30, 40, 35, 25}. In this example, the array is ... Read More
998 Views
Linear search is a sequential searching algorithm where we traverse every element within the input array and compare it with the key element to be found. The minimum element refers to the smallest element in the array. In this article, we have an array of integers. Our task is to find the minimum element in that array using linear search. Here are the three approaches you can use to find the minimum element: Using Value Using Index Using Pointer Using Value In this approach, ... Read More
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
563 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
452 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
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