Please give answer in python code! Please give answer in python code!

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Please give answer in python code! Please give answer in python code!

Post by answerhappygod »

Please give answer in python code!
Please Give Answer In Python Code Please Give Answer In Python Code 1
Please Give Answer In Python Code Please Give Answer In Python Code 1 (309.5 KiB) Viewed 30 times
Please Give Answer In Python Code Please Give Answer In Python Code 2
Please Give Answer In Python Code Please Give Answer In Python Code 2 (42.75 KiB) Viewed 30 times
Please give answer in python code!
Timing a block of code To handle the timing we'll be wanting to track the time our process spent in the CPU (as oppose to clock-on-the-wall time). Luckily, python's time module can easily help with this. Here's an example of timing a loop that has one-hundred million iterations. def nanosec_to_sec(ns): BILLION = 1000000000 return ns/BILLION print("Beginning the timing code...") num_iterations = 100000000 #one hundred million start_time = time.process_time_ns() #loop that does nothing but repeat, hence the - variable and the keyword pass #which just means do nothing for in range(num_iterations): pass end_time = time.process_time_ns() print("Total time in ns: ", end_time-start_time) print("Total time in sec: , nanosec_to_sec(end_time-start_time)) Notes on time.process_time_ns(): • It returns an int that represents the current number of nanosecond the process has spent in the CPU • If you want seconds, you'll need to convert it, like I did in the example
You will time several methods from Stacks, Queues, and Lists using several values for n (size of the data structure)
Sels You will fill each data structure with an increasing number of elements and record a time for each. For each method, start with a data size of 1000 then increase by 1000, recording another time, and repeat until you've reached 100,000 elements For example. Let's say I want to time Pop for a Stack. I would do the following: 1. Fill a stack with 1000 elements 2. Record time to perform a single pop with that size stack 3. Fill a stack with 2000 elements 4. Record a time to perform a single pop with that size stack 5. Repeat these steps, increasing the size by 1000 each time until I've recorded a time for a stack with 100,000 elements in it Operations to time Operation Popping a single item from a stack Popping all items from a stack Queue's enqueue Linked List get_entry at specifically index 0 Linked List get_entry at specifically the last index Printing all elements in a LinkedList using get_entry
In addition to your code, you will submit graphs (e.g. excel graphs) of the data you've collected. One graph for each operation.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply