This is my 4th semester project for the course Design and Analysis of Algorithms.
The task was to implement a string matching algorithm to identify complete "dish sets" from a sequence of given ingredients.
The program reads:
- Groups β Sets of ingredients that define different dishes.
- Test cases β Lists of available ingredients.
It then determines whether all dishes can be prepared with the available ingredients, ensuring that each ingredient is only used once per dish.
- Parsing Input: Reads data from a
.txtfile, storing groups and test cases. - Sliding Window Search: Uses a moving window equal to the dish size to check for a complete match.
- Ingredient Removal: Once a dish is found, its ingredients are removed from the list to avoid reuse.
- Final Check: Returns
Trueif all dishes are found in the given ingredients list, otherwiseFalse.
This approach ensures no overlapping or repeated use of ingredients for multiple dishes.
βββ string.cpp # Main C++ implementation
βββ p1_input.txt # Sample input file
βββ p1_v2.txt # Additional test case set 1
βββ p1_v3.txt # Additional test case set 2
βββ p1_v22.txt # Additional test case set 3
- C++ β Core language for implementation.
- File I/O β Reading groups and test cases from
.txtfiles. - Vectors & Strings β Storage and manipulation of ingredient data.
Example from p1_input.txt:
groups = {{'lettuce', 'tomato', 'cucumber'}, {'pasta', 'tomato', 'chicken'}, {'flour', 'sugar', 'eggs', 'milk'}, {'milk', 'sugar', 'custard'}}
Test case 1
nums = ['onions', 'potatoes', 'pasta', 'lettuce', 'tomato', 'cucumber', ...]
----- Test case 1 -----
Dishes: 4
Ingredients: 19
Outcome: True
- Applied string matching logic to real-life analogy (dishes & ingredients).
- Implemented sliding window technique for efficient search.
- Improved skills in C++ file handling and vector manipulation.
- Practiced designing algorithm steps before coding.
This project is for educational purposes only.