Data Structures in Action: Using Binary Search Trees for Hierarchical File Systems

python 301 data structure represent hierarchical system

Problem We want to represent a hierarchical file system structure using a data structure. Folders can contain other folders and files. We need efficient access and organization for navigating through this hierarchy. Data Structure Implementation Class node Class File System Example usage Explanation This example demonstrates how a BST can be used to organize and efficiently search for files and folders within a hierarchical file system structure. You could extend this concept to include additional information within the nodes (e.g., file size, creation date) and implement functionalities like deleting files/folders…

Data Structures in Action: Using stack for undo/redo functionality in a text editor

python 301 data structure undo/redo functionality a text editor

Problem We want to implement undo/redo functionality in a text editor. When a user makes changes to the document, those edits should be stored for potential undo actions. Additionally, after undoing an edit, the user should be able to redo it. Data Structures Implementation Stack Class TechEditor Example usage You can similarly implement a redo function using a queue (optional) Explanation This example showcases how a stack can be used to maintain a history of edits, enabling users to undo their actions in a text editor. You could extend this…

Data Structures in Action: Using LinkedList for Efficient Order Tracking

python 301 data structure Efficient order tracking

Problem You’re building a simple task management application. Tasks have descriptions and priorities (high, medium, low). You need to efficiently add, remove, and display tasks while maintaining their order based on priority (high priority at the beginning). Data Structure Implementation Build Node Add Task Adds a new task with the given description and priority to the linked list. Args:description: Description of the task (string)priority: Priority level (string: “high”, “medium”, “low”) Remove task Removes the first task with the matching description from the linked list. Args:description: Description of the task to…

Data Structures in Action: Using Tuple for analyzing movie ratings

python 301 data structure analyzing movie rating

Problem You have a dataset containing movie titles, release years, and user ratings (1-5 stars). You want to analyze the data to calculate average ratings per movie and identify movies with consistently high or low ratings. Data Structure: Algorithm: Implementation Movies data (a list of tuples) Analyze movie ratting Analyze and print the result The result Benefits of using Tuples:

Data Structures in Action: Using Dictionary for managing a grocery store’s inventory

python 301 data structure managing grocery store

Problem You are tasked with managing a grocery store’s inventory. The store keeps track of various items with their names, prices, and stock quantities. You need to develop a Python program that efficiently handles this data and provides functionalities for the store staff (add, remove, update, display all, search, …). Solution Dictionary: An ideal choice to store item information. Each item can be a key, and its value can be a dictionary containing details like price and stock quantity (e.g., {“name”: “apple”, “price”: 2.5, “stock”: 100}). Implementation Add an item Allows adding…