- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 7346 Articles for C++
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
381 Views
This is a C++ Program to find the maximum element of an array using Binary Search Tree. The time complexity of this program is O(log(n)).AlgorithmBegin Construct the Binary Search Tree using the given data elements. Next traverse the root pointer to the rightmost child node available. Print the data part of the node as the maximum data element of the given data set. Print the Depth of the maximum data. EndExample Code#include using namespace std; struct node { int d; node *left; node *right; }; ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
757 Views
This is a C++ Program to find the minimum element of an array using Linear Search approach. The time complexity of this program is O(n).AlgorithmBegin Assign the data element to an array. Assign the value at ‘0’ index to minimum variable. Compare minimum with other data element sequentially. Swap values if minimum value is more then the value at that particular index of the array. print the minimum value. EndExample Code#include using namespace std; int main() { int n, i, minimum, a[10] = {1, 6, 7, 10, 12, 14, 12, 16, 20, 26}; char ch; minimum = a[0]; cout
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
215 Views
In uniform binary search here we implement binary search using a lookup table. It is an improvement in binary search since table lookup is faster than a shift and addition. The time complexity of this approach is O(log(n)).AlgorithmBegin Assign the data to the array in a sorted manner. Calculate the maximum length of lookup array and declare a new array ‘del’. Assign the values to the lookup array as n/2, n/4 and so on till ‘0’, where n is the length of the data array. Call UniBinarySearch() function. Assign mid to the value at ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
387 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
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
209 Views
In this program, we need to extract the Kth largest element from a sequence. the time complexity of this technique can be improved by approaching the problem using max-heap. The time complexity of this program is O(n + k*log(n)).AlgorithmBegin Send the max of the heap to the end of the sequence. Heapify the remaining sequence. Repeat the process for ‘k’ times. Print the final state of the array. Print the max from the heap extracted from kth iteration as a result. End.Example Code#include using namespace std; void MaxHeapify(int a[], int i, int n) { ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
2K+ Views
In this program we need to. Implement binary search to find the existence of a search sequence in a binary search tree. The worst case time complexity of Binary search is O(n) but for the average case O(log(n)).AlgorithmBegin Construct binary search tree for the given unsorted data array by inserting data into tree one by one. Take the input of data to be searched in the BST. Now starting from the root node, compare the data with data part of the node. if data < temp->d, move the temp pointer to the left child. if ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
369 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
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
248 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
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
453 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
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
3K+ Views
Quick sort is based on divide-and-conquer. The average time complexity of this algorithm is O(n*log(n)) but the worst case complexity is O(n^2). To reduce the chances of the worst case here Quicksort is implemented using randomization.Algorithmpartition(int a[], int l, int h)Begin pivot = h Index = l start = l and end = h while start < end do while a[start] pivot do end = end – 1 done if start < end then swap a[start] with a[end] ... Read More