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
| class Solution { | |
| public boolean isPalindrome(String s) { | |
| StringBuilder tmp = new StringBuilder(); | |
| //Time Complexity: O(n) | |
| for(char c: s.toCharArray()) { |
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
| import java.io.*; | |
| import java.util.*; | |
| public class Rucsac { | |
| public static void main(String[] args) throws IOException { | |
| BufferedReader fin = new BufferedReader(new FileReader("rucsac.in")); |
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
| Brute-force --->> incerci toate variantele posibile | |
| Backtracking - te intorci daca nu mai poti inainta | |
| Greedy - >alegi mereu cea mai buna decizie locala | |
| - decizii pas cu pas | |
| - nu revii asupra alegerilor |
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
| /* | |
| for(int i = 1; i <= n; ++i) { | |
| for(int j = 1; j <= n; ++j) { | |
| } | |
| } | |
| O(n^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
| input: | |
| numar de obiecte, capacitate rucsac | |
| urmatoarele linii: | |
| greutate obiecte, profit obiect | |
| 5 10 | |
| 3 2 | |
| 4 3 |
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
| /* | |
| Divide et impera versus Dynamic Programming | |
| f(5) | |
| f(4) f(3) | |
| f(3) f(2) f(2) f(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> | |
| //2 for-uri...O(n^2) | |
| //n * 2^n | |
| /* | |
| A = {1,2,3} numarul de submultimi = 8 pentru ca avem 2^3 subsets | |
| 1. backtracking | |
| 2. iterativ |
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
| //Fibonacci Sequence | |
| //0,1,1,2,3,5,8,13,21, 34,.....infinit | |
| //Algoritmul Naiv | |
| //Big O Notation: O(2^n) | |
| /* | |
| long long fib_exponential(int 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
| /* | |
| Sortare rapida: Quicksort | |
| Big O Notation: n log n | |
| v = [1,2,8,7,9]; | |
| Bubble Sort : O(n^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
| /* | |
| Complexitatea Algoritmilor | |
| ------------------------- | |
| Prin complexitatea unui algoritm intelegem de fapt costul, masurat cu ajutorul unor anumiti parametri | |
| (timp de executie, memoria necesara, numarul de operatii). PEntru a calcula complexitatea unui algoritm , avem nevoie sa decidem | |
| care sunt acesti parametri si sa gasim o functie determinare a costului corespunzatoare. | |
| Notatii Teta 0, O, Omega |