subject

This code is for python Searching for Data
In this lab we'll compare the time it takes to search for an item in a list vs searching for it in a binary search tree.
Part 1: Populating and Searching a List
To get started create a function, populate, that takes as a parameter a positive integer n, populates a list of length n with random integers in the range of [0, n] and returns that list.
Next create a function that takes as a parameter a list and an integer and returns True if that integer is found in the list and False if it is not.
Finally, in your main script call your function for a value of n to get a list of length n and then go through that list and look for each element in that list within the list and print out that count. Needless to say if you did everything right you should print out n
Part 2: Populating and Searching a Binary Search Tree
Download the provided BST. py module. This module is a stripped down implementation of a Binary Search Tree and associated Node class.
The BST class has the following public methods:
Constructor - Creates an empty binary search tree.
append(value) - Creates a Node with the value value and inserts it into the BST.
isin(value) - Returns True if value is found in a Node of the BST and False otherwise.
Change your main script so that your populate function creates both a list and a Binary Search Tree with the same random n elements and returns them both. In addition, change your main script so that with in looks for all the values of the list within the list, that it also counts how many times those values exist in the BST and prints that number out as well.
Part 3: Timing
Now let's time how long it takes to look for all n values within both the list and the BST! To do this, first import the time module. The time module has a time() function that returns the system time. Get this value before checking the list for all the values and then again after you're done checking the list. Print out the difference in these times. Now do the same thing for searching the BST!
Part 4: Plot n vs. time
Finally onto the cool stuff! In the previous parts you were asked to just use some arbitrary value of n. Now let's do everything you did in Part 3 but for a range of values of n. In particular let's go from n=1 to n=10,000 in steps of 1000. Keep track of the times for each of these runs for searching both the list and the BST so that you can plot them!As a reminder, we can use the matplotlib library to help us plot. So first import matplotlib. pyplot as plt. If you cannot import this module, then you may need to install (pip) matplotlib. Then you can make use of the following methods:
plt. plot(xvals, yvals, label='text') - Adds a plot of xvals vs yvals to the current figure with a label saying 'text'. Doing this several times superimposes the plots.
plt. legend() - This will "enable" the labels to be shown as a legend.
plt. show() - This displays the figure.
Finally, plot n vs average list search time and n vs average BST search time.

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 06:50
Match the personality traits with their description
Answers: 1
question
Computers and Technology, 23.06.2019 08:00
Michael has written an e-mail to his employees that describes a new product special that will be introduced to the customers next week. by taking time to make sure the e-mail is well written, logical, and organized, michael has made sure his message has the characteristics of a) effective communicationb) ineffective communicationc) barriers to communicationd) workplace communication
Answers: 2
question
Computers and Technology, 24.06.2019 10:00
When writing a business letter, how many times can you use the same merge field in a document? once once, unless using the address block feature unlimited it will depend on the type of document you choose
Answers: 1
question
Computers and Technology, 24.06.2019 21:30
Computer security/cybersecurity1) each of the following code fragments contains a number of security vulnerabilities. for each fragment, identify these security vulnerabilities and, for each vulnerability, discuss at least one way that it could be improved. note that in your discussion of how each vulnerability could be improved, you do not need to re-write a new version of the program in c; simply discuss your solution, either in pseudocode or in 1-2 sentences.a) /* file descriptor leak */#include #include int main(int argc, char *argv[]){ char *filepath = argv[0]; char *shellpath = argv[1]; file *passwords; passwords = fopen(filepath, "r"); /* read the password and do something with it */ /* . . */ /* fork and execute alternative shell */ execl(shellpath, "shell", null); }b)#include /* assume the following function is written for an electronic storefront. the user will enter the id of the item to be ordered, as well as the quantity of units that they would like to purchase. the program will then lookup the price for the price for the item using a predefined function, and return the total cost of the order.*/int gettotalcost(){ char itemid[9]; int price, unitsordered, cost; printf(" enter the 9-digit id of the item to be ordered: "); scanf("%s", & itemid); /* lookup the price according to the itemid */ price = getpricebyid(itemid); printf(" enter the quantity of units to be ordered: "); scanf("%d", & unitsordered); cost = price * unitsordered; return cost; }c)#include /* the following function is intended to return a user's full name by concatenating the user's first and last name into a single string and then returning that string. */char *getfullname(char *firstname, char *lastname, int max_len){ char fullname[max_len]; strcpy(fullname, firstname); strcat(fullname, " "); strcat(fullname, lastname); return fullname; }d)#include /* the following code snippet runs through the list of cli arguments entered and displays them to the console. */int main(int argc, char *argv[]){ int i; printf("you've entered the following arguments: "); for(i = 0; i < argc; i++){ print(argv[i]); printf("\n"); } /* */}
Answers: 2
You know the right answer?
This code is for python Searching for Data
In this lab we'll compare the time it takes to se...
Questions
question
Business, 03.07.2020 21:01
question
Mathematics, 03.07.2020 21:01
Questions on the website: 13722367