File containing a specified number of phone records.

Assignment Help Basic Computer Science
Reference no: EM13977182

In this assignment we will hope to demonstrate the efficiency of dictionaries over lists for certain types of tasks. Most specifically, the task will be looking up telephone numbers of people in a phonebook data structure.To do this you will write two programs: one that creates data files to process, and a second that does timing comparisons for phone number queries in two different data structures.

Program 1:

This program will create a data file containing a specified number of phone records. The program should ask the user for a file name and the desired number of records. Each record in the file will contain three values separated by spaces: a first name, a last name, and a phone number.

Write a generator function that will return a randomly generated phone record when called. For the random generation, we will use a different function from the random module called choice(). You can pass this function a string containing characters to choose from, and it will randomly pick one. For the random record do the following. For both the first and last name, create strings of length 4, where each character is a randomly chosen lower case letter. For the phone number, this can be 7 characters long, where each character is a randomly chosen digit, 0-9. Yield a list that contains these three values, similar to what we saw in class. This function should have one parameter, which is the total number of records it should generate. You can then iterate through these records using a for loop, and you can write one line to your data file for each record generated.

Program 2:

This program will do timing tests. It should begin by reading the name of a data file to process. You should iterate through the lines of this file to create a list of phone records, where each phone record is a list of the three values: first name, last name, and phone number. You should also write a binary search function, that when passed a list and a name, will return the phone number for that name if it exists, or the value None if it does not. Write an iterative binary search routine rather than a recursive function (which is slower). Include in your code the comparison function we wrote in class for comparing names for a sort.

Next you will do a timing comparison. For the first timing, you should begin by creating a sorted version of the phone record list. You can use the sorted() function and pass it the phone record list and the name of the name comparison function. Then write a loop that iterates through every name in the original list, calling the binary search function to locate the corresponding phone number in the sorted list. You do not need to print out the search results. To compute how much time the sorting and searching takes, you can using the time() function in the time module. By calling this function before you start a task, and then after you are done with the task, you can subtract these two values to determine how long the task took. Time the sorting process. Then time the search loop. You should print out these two times.

For the second timing, you should create a dictionary, where the key for the dictionary is a string formed of the last name and first name, with a comma in between (just like we did in class), and the value stored in the dictionary is the phone number. Then use the same loop that iterates through every name in the original list, looking up the name in the dictionary to locate the corresponding phone number. You do not need to print out the number. Time the dictionary creation process. Then time the search loop. You should print out these two times.

What to turn in:

You should turn in the source code for the two programs. You should use your first program to create a set of data files that range in size from 100 to 10 million phone records. Then run each of these files through your second program to get timing results. Make a small table that compares these timing values for each of the different file sizes to see how the performance of using a list degrades in comparison to using the dictionary. Submit this table as well.

Reference no: EM13977182

Questions Cloud

How much does the melting of ice change entropy of world : A 4.55kg block of ice at 0.00oC falls into the ocean and melts. The average temperature of the ocean is 3.55oC, including all the deep water. By how much does the melting of this ice change the entropy of the world? (J/K)
What is the volume of liquid and the volume of vapor : Ten kilograms of saturated mixture are contained in a container at 70 C and a dryness fraction of 0.6. what is the volume of liquid, the volume of vapor, and the pressure of the mixture?
Cheverly paper company case : In response to increasing competition, a major paper distributor in the Washington metropolitan area with headquarters in Cheverly, Maryland wants to expand its presence along the east coast. The objective is to have one warehouse facility in a ma..
What length does the observer measure for the spaceship : A 499-m long spaceship passes by an observer at the speed of 2.40x108 m/s. What length does the observer measure for the spaceship?
File containing a specified number of phone records. : This program will create a data file containing a specified number of phone records. The program should ask the user for a file name and the desired number of records. Each record in the file will contain three values separated by spaces: a first ..
What is the mass of the second ball : A 0.280-kg ball makes an elastic head-on collision with a second ball initially at rest. The second ball moves off with one fourth the original speed of the first ball. What is the mass of the second ball?
Stock price and number of shares outstanding : Obtain the financial information you need for Home Depot.a. Go to Nasdaq.com, enter Home Depot's stock symbol (HD) and go to "Summary Quotes" onthe left-hand side. Get the current stock price and number of shares outstanding.
What recommendation concerning ability of the food service : Prepare a brief report with the items noted so it is ready for Dr. Starr at the next meeting. What is your recommendation concerning the ability of the food service to be self-supporting
What is the acceleration of the masses : A 5 kg and a 2 kg masses are connected by a massless string, which is wrapped around a frictionless pulley. The moment of inertia of the pulley is I = 0.1 kg m2 with radius R = 0.2 m. All surfaces are frictionless. The string does not slip on the ..

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Identifies the cost of computer

identifies the cost of computer components to configure a computer system (including all peripheral devices where needed) for use in one of the following four situations:

  Input devices

Compare how the gestures data is generated and represented for interpretation in each of the following input devices. In your comparison, consider the data formats (radio waves, electrical signal, sound, etc.), device drivers, operating systems suppo..

  Cores on computer systems

Assignment : Cores on Computer Systems:  Differentiate between multiprocessor systems and many-core systems in terms of power efficiency, cost benefit analysis, instructions processing efficiency, and packaging form factors.

  Prepare an annual budget in an excel spreadsheet

Prepare working solutions in Excel that will manage the annual budget

  Write a research paper in relation to a software design

Research paper in relation to a Software Design related topic

  Describe the forest, domain, ou, and trust configuration

Describe the forest, domain, OU, and trust configuration for Bluesky. Include a chart or diagram of the current configuration. Currently Bluesky has a single domain and default OU structure.

  Construct a truth table for the boolean expression

Construct a truth table for the Boolean expressions ABC + A'B'C' ABC + AB'C' + A'B'C' A(BC' + B'C)

  Evaluate the cost of materials

Evaluate the cost of materials

  The marie simulator

Depending on how comfortable you are with using the MARIE simulator after reading

  What is the main advantage of using master pages

What is the main advantage of using master pages. Explain the purpose and advantage of using styles.

  Describe the three fundamental models of distributed systems

Explain the two approaches to packet delivery by the network layer in Distributed Systems. Describe the three fundamental models of Distributed Systems

  Distinguish between caching and buffering

Distinguish between caching and buffering The failure model defines the ways in which failure may occur in order to provide an understanding of the effects of failure. Give one type of failure with a brief description of the failure

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd