Pergunta

I am very new to Data Structures and Algorithms. I want to use recursion + stack/queue in a grocery store inventory program that I am making. However, I can't come up with any good ways of using recursion in a manner that contributes and is relevant to my grocery store inventory system.

I know recursion can be used for the tower of hanoi, coming up with palindromes and other random things like making patterns. However, I am not sure how to apply it to a grocery store inventory system such that it provides value to the staff who interacts with the program.

I don't know how to implement recursion and I just need ideas on what I can possibly do with it, in a way that adds value to my grocery store inventory application. Would an order system be able to use recursion in an effective way?

Foi útil?

Solução

One way to use recursion would be a product search function, using a simple Binary Search Tree or something similar to store the data. https://en.wikipedia.org/wiki/Binary_search_tree

Adding, removing, and modifying inventory items would be fairly simple and something commonly covered in a Data Structures class.

As far as using a queue, you could build a list of inventory changes with the form (product_id,count_change) that you could process through using your search feature discussed earlier.

Also, the ability to read the inventory from a text file and write it back out would easily exercise these concepts and make it easier to identify bugs as you are developing.

Outras dicas

An inventory system doesn't seem to offer a lot of opportunities for this kind of thing. If you are doing this for work, I would agree with amon that trying to force in such a solution is not really a great idea. It will devalue the solution that you are producing. Recursion can come with some performance penalties as well, depending on a number of factors. When it's good fit, though, it can really simplify things.

The best I can come up with for this at the moment would be a restocking algorithm. Let's say a store has run out of something e.g. toilet paper. You need to try to find the closest warehouses and/or distributors that can provide you with some.

You could implement this with a recursive strategy. To start, you need a tree with a single root node. Under this, you could add 'distributors' and 'warehouses'. Under that, you have increasingly smaller subsets of each. This could be based on physical location (which is probably what you want for your own warehouses.) For distributors, maybe you might want to split it up by both company and location.

Probably, you can solve this adequately with just a straight-forward loop. The main benefit of a recursive strategy here would be if you want to parallelize the search. To make that worthwhile, the search space would need to be pretty large, most likely.

Licenciado em: CC-BY-SA com atribuição
scroll top