This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class RecursiveBinarySearch { | |
| public static int RecursiveBinarySearch(int[] arr, int start, int end, int target) { | |
| if( start > end ) { | |
| return -1;//target negasit | |
| } | |
| int mid = start + (end - start) / 2; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class IterativeBinarySearch { | |
| public static int IterativeBinarySearch(int[] arr, int target) { | |
| int start = 0;//limita inferioara | |
| int end = arr.length - 1; //limita superioara | |
| while( start <= end ) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| int binary_search0(int *arr, int lo, int hi, int key) { | |
| if(lo > hi) { | |
| return -1; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <vector> | |
| using namespace std; | |
| int iterativeBinarySearch(const vector<int>&arr, int target) { | |
| int start = 0; | |
| int end = arr.size() - 1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <vector> | |
| /* | |
| T = 7 | |
| 9 | |
| 1 1 1 2 2 2 3 3 3 | |
| */ | |
| using namespace std; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <vector> | |
| using namespace std; | |
| //programare dinamica | |
| class Solution { | |
| public: | |
| vector<vector<int>> generate(int numRows) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <vector>//template | |
| //bubblesort, selection by minimum, insertion sort | |
| //2 3 9 4 -1 23 4 54 | |
| // | |
| using namespace std; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| class Solution { | |
| //n = 18 | |
| public: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| int main(int argc, char const *argv[]) | |
| { | |
| unsigned n;//input n natural | |
| cin>>n; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| void fb() { | |
| int n; | |
| scanf("%d", &n); | |
| int arr[ n ]; | |
| for(int i = 0; i < n; ++i) scanf("%d", &arr[i]); |