Tree Node Data Structure, Quicksort Algorithm, and BFS Algorithm with Python for Department Store’s Shops, Categories and Products

Project with Data Structures and Algorithms for Python

Tree Node Data Structure, Quicksort Algorithm, and BFS Algorithm with Python for Department Store’s Shops, Categories and Products

1.Idea:

Build a system of stores with their categories and products.

2.Requirements:

  • In this system we must be able to add and delete a product.

  • The user must be able to search for a product by its name, in which store, and in which category is this product.

3.My Girgub Repo: GitHub - scallopy/product_search

4.In script.py I create my own minimal sets of data and show Data Structure of my Project and how algorithms work.

5.What I use in my Project?

  • I use Tree data structures to store data in my project.

  • I use quicksort algorithm to sort products by name after adding a new product.

  • I use Breadth_First Algorithm to serch for a product by name and to save and show path to this product in the Data Structure.

  • I use 1. Breadth-First search algorithm to remove a product in department store by product name.

  • I represent my Tree Node Data Structure like this:

Department Store
├─Hardware Store
...├─Bath
...├─Tools
......├─Hand Tools
.........├─['Asterisks', 'Description', 1222]
.........├─['Mine', 'Description', 23]
.........├─['Nolan', 'Description', 34]
.........├─['Some', 'Something', 121]
.........├─['This', 'Thisthing', 12]
......├─Electrical Tools
...├─Building Materials
...├─Cleaning
...├─Lighting
......├─['Lamp', 'lighting', 24]
├─Souvenirs
├─Services

6.Refactoring:
I removed unused code and add a user input to search for a product.

7.Blog Post in Medium

Hi, when I tried your program the tree nodes did not print at line 41 in script.py and I got a ‘UnicodeEncodeError’ that says the ‘charmap’ codec cannot encode some of the characters. I’m using python 3, so I’m not sure why it’s not working…

Python would be 3.8. I have not Python3.5 and I can’t try with it. But you can change python version in your terminal or cmd:
In terminal run:

$ python --version
Python 3.8.4
$ python3.8 script.py

or

$ which python3.8
/usr/bin/python3.8
$ alias python="/usr/bin/python3.8"
$ python3.8 script.py

Python would be 3.8. I do not have Python3.5 and I can’t try with it. But you can change python version in your terminal or cmd:
In terminal run:

$ python --version
Python 3.8.4
$ python3.8 script.py

or

$ which python3.8
/usr/bin/python3.8
$ alias python="/usr/bin/python3.8"
$ python3.8 script.py

На нд, 27.02.2022 г. в 23:10 ч. ca_aicode via Codecademy Forums <codecademy@discoursemail.com> написа:

Hi, I’m using python 3.8 as well, but 3.8.10 not 3.8.4. Maybe it cannot encode the special characters you use to make your tree structure, but I have used those characters in codecademy’s code editor before. Your blog post is very descriptive and I can see in the output you posted that the bfs algorithm works with the tree nodes you made. And I actually just ran the script and it works with different characters (hyphens) to print the tree because you used indentation to show the subtrees. All of the searches worked and the only issue I had was it only accepts the exact name of the product and it’s not clear which words you should type. Also at the bottom of the program it says the ‘Some’ product was removed and maybe that’s from your test code…sry for the long reply, I wanted to give feedback!

Hi, thank you for your feedback. I tried to show more of my functions and at the end of the script.py I remove product “Some”. I hope that my solution was useful for you because your feedback was very useful for me. Thank you!

With regards!
Petya Velikova

На пн, 28.02.2022 г. в 22:15 ч. ca_aicode via Codecademy Forums <codecademy@discoursemail.com> написа:

I used a binary search tree for my project so it was interesting to see a tree node data structure without a tree class, but I remember this method from the codecademy lessons and it works for hierarchical data like yours

Thanks for feedback!