Given a large file of integers, search for a particular element in it using multi-threading.
Input : 1, 5, 7, 10, 12, 14, 15, 18, 20, 22, 25, 27, 30, 64, 110, 220 Output :if key = 20 Key element found Input :1, 5, 7, 10, 12, 14, 15, 18, 20, 22, 25, 27, 30, 64, 110, 220 Output :if key = 202 Key not present
Prerequisite : Multi-threading
First create n threads. Then, divide array in to four parts one section for each thread and apply linear search on individual section using multhreading and check whether the key element is present or not.
Command : g++ -pthread linear_thread.cpp
Key not present
Exercise: The above code divides array into four subarrays. Extend this to take a parameter that decides number of divisions (or threads).
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Linear Search vs Binary Search
- Linear Search
- Sentinel Linear Search
- C/C++ Program for Linear Search
- Java Program for Linear Search
- Multithreading in C
- Multithreading in C++
- Repeatedly search an element by doubling it after every successful search
- Why is Binary Search preferred over Ternary Search?
- Interpolation search vs Binary search
- Best First Search (Informed Search)
- Median of two sorted arrays of different sizes | Set 1 (Linear)
- Meta Binary Search | One-Sided Binary Search
- Sublist Search (Search a linked list in another list)
- K'th Smallest/Largest Element in Unsorted Array | Set 2 (Expected Linear Time)
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.