#include<iostream>
#include<vector>
using namespace std;
int Frequency(std::vector<int> &v, int k, int start, int end)
{
if (start > end)
return 0;
int mid = (start + end) / 2;
if (v[mid] < k)
return Frequency(v, k, mid + 1, end);
if (v[mid] > k)
return Frequency(v, k, start, mid - 1);
return Frequency(v, k, start, mid - 1) + 1 + Frequency(v, k, mid + 1, end);
}
int main()
{
int arr[] ={2,2,3,3,5,5,5};//Sorted Array
std::vector<int> v(arr, arr+7);
int k;
std::cin>>k;
std::cout<<Frequency(v, k, 0, v.size()-1);
getchar();
}
Saturday, 31 October 2015
Occurence of a number in Sorted Array/Vector using Recursion
Sunday, 18 October 2015
grep - Linux Command
Most of the general linux commands are available online but here i will be covering bit advance feature of some linux commands
grep
We use grep command to search contents in a file or directory.What will be command for searching only in specific extension files in a directory.Lets find out below
grep
We use grep command to search contents in a file or directory.What will be command for searching only in specific extension files in a directory.Lets find out below
- Recursively Search a pattern in all files of a directory use
- To Search a pattern only in files with specific extensions in a directory use
- To Search a pattern in files with multiple extensions in a directory use
- Case insensitive Search of a pattern
Subscribe to:
Posts (Atom)