This repository is only for uploading homework.
This Python script is designed to identify the greatest non-negative subset from a randomly generated list of integers. It iterates through the list, extracting subsets of non-negative integers and comparing them to find the subset with the largest sum. In the end, it graphs the time of execution against the readings of the mainset.
- The script generates a list
mainsetcontaining 1000 random integers between -100 and 100. - It initializes several lists and variables to keep track of subsets and their sums.
- It iterates through each element of
mainset, adding non-negative integers tolastsubsetwhile measuring the time it takes to do each iteration. - When encountering a negative integer, it checks if there's more than one negative integer in a row.
- If the current
lastsubsethas a greater sum than the previously identified greatest subset, it updatesgreatestsubset. - Finally, it prints the
greatestsubsetand the sum of its elements in addition to the graphing of reads vs time.
- Ensure you have Python installed on your system as well as the library matplotlib.
- Copy the provided code into a Python file (e.g.,
greatest_subset.py). - Run the script using a Python interpreter.
- View the output to see the greatest non-negative subset and the sum of its elements.
[-54, -17, 57, -63, 22, 86, -15, 81, -97, 33, -33, 35, -92, -25, -12, 6, -20, -9, 58, -52, 57, -77, -81, -41, -93, -32, -87, -35, 28, -16, 33, 8, -69, -58, -31, -58, -26, -35, -51, 27, 72, 77, -5, -24, 29, -12, 14, -92, -80, -77, -12, -24, 22, -2, 58, 33, -48, -58, -20, 3, -2, 52, 44, -68, -95, 64, 12, 20, 80, -5, 68, -17, 28, 32, 59, 6, 37, -82, 66, 52, 56, -15, 14, -74, -36, -53, -3, 13, -41, 59, -49, 100, 66, -87, 92, -6, -99, -46, 23, -31]
[27, 72, 77]
176- Python 3.x
randommodule (built-in)matplotlibmodule
This script was written by Murguia Ortiz Joaquin de Jesus.
The script consists of two main components:
- Linked List Implementation: The script defines a Node class for linked list nodes and a LinkedList class to handle linked list operations such as adding nodes at the front or end and printing the list.
- Speed Comparison Function: The script includes a function compare_speed(n) to compare the speed of writing data to a linked list and a NumPy array of length n. Inside compare_speed(n), instances of linked list and NumPy array are created, data is written into them, and the time taken is measured.
- A linked list is implemented in the script.
- The script then proceeds to write 10000 elements on each the linked list and a numpy array.
- Finally, it compares the times of writing by graphing them side by side.
- Ensure you have Python installed on your system.
- Copy the provided code into a Python file (e.g.,
listvsnumpy.py). - Run the script using a Python interpreter.
- View the output.
- Python 3.x
Numpymodulematplotlibmodule
This script was written by Murguia Ortiz Joaquin de Jesus.
This Python script provides an implementation of a binary tree data structure, along with methods to insert nodes, perform traversals, search for specific nodes, and print subtrees rooted at specific nodes.
##Features BinaryTree Class: Represents the binary tree and includes methods for insertion, traversal, search, and printing subtrees. TreeNode Class: Represents a node in the binary tree. Insertion: Method to insert new nodes into the binary tree. Inorder Traversal: Method to perform an inorder traversal of the binary tree. Node Search: Method to search for a node with a specific value in the tree. Print Subtree: Method to print the subtree rooted at a specific node.
- The
insertmethod allows adding new nodes to the binary tree. When a node is inserted, it is placed in the appropriate position based on its value. If the value is less than the current node's value, it is inserted into the left subtree; if it's greater, it goes into the right subtree. - The
inorder_traversalmethod performs an inorder traversal of the binary tree. In this traversal, nodes are visited in the order left subtree, current node, right subtree. This results in the values being printed in sorted order. - The
search_nodemethod allows searching for a node with a specific value in the binary tree. It performs a recursive search starting from the root node and traversing left or right based on the comparison of values until the target node is found. - The
print_subtreemethod prints the subtree rooted at a specific node. It performs an inorder traversal starting from the given node, printing the values of the nodes in the subtree.
- Ensure you have Python installed on your system.
- Copy the provided code into a Python file (e.g.,
binarytree.py). - Run the script using a Python interpreter or change the example values to make your own binarytree.
- View the output.
- Python 3.x
This script was written by Murguia Ortiz Joaquin de Jesus.


