Advanced Search
Search Results
297 total results found
2. Compile-Time Polymorphism
2.1 Function Overloading Definition: Multiple functions with the same name but different parameters. #include <iostream> #include <string> using namespace std; class Printer { public: // Overloaded print functions void print(int value) { cout ...
3. Runtime Polymorphism
3.1 Virtual Functions Definition: Functions that can be overridden in derived classes and are resolved at runtime. #include <iostream> #include <string> using namespace std; class Animal { protected: string name; public: Animal(string n) : name(n...
4. Practical Applications
4.1 Complete Example: Drawing Application #include <iostream> #include <vector> #include <string> #include <cmath> using namespace std; // Abstract base class class Shape { protected: string color; double x, y; // Position public: Shape(stri...
1. Introduction to DP
What is DP? Dynamic programming (DP) is defined as a powerful design technique that successfully combines the correctness of brute force algorithms with the efficiency of greedy algorithms. The fundamental idea of dynamic programming is to remember the solutio...
Code & Examples 1
DP for Fibonacci Problem To illustrate Dynamic Programming, let's look at the classic Fibonacci Sequence. The rule is simple: each number is the sum of the two preceding ones ($F(n) = F(n-1) + F(n-2)$), starting with 0 and 1. 1. The Original Solution (Naive Re...
Code & Examples 2
Knapsack Problem Given n items where each item has some weight and profit associated with it and also given a bag with capacity W, [i.e., the bag can hold at most W weight in it]. The task is to put the items into the bag such that the sum of profits associate...