Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Algorithims words.dat is just a file with 5757 5 letter words. 1. Consider the 5-letter words in the text file words.dat that was posted for

Algorithims

image text in transcribed

words.dat is just a file with 5757 5 letter words.

1. Consider the 5-letter words in the text file words.dat that was posted for Homework 4. Define an undirected graph whose vertex set is exactly the set of words in this file. The edges of this graph connect every pair of words w and u' if and only if w and u' differ in exactly one letter. For example, the words above and abode would be connected by an edge, since they differ only in the 4th letter. Let us call this the word graph. Write a program t of the word graph. To build an adjacency list representation that provides efficient access, first read the words from the file into an array W of size 5,757. Since the words appear in the file in sorted order, they can be placed in W in sorted order without much effort. Now build a second array, called A, such that for any word w, if w appears in slot i in array W, then slot i in the array A points to the list of the neighbors of w in the word graph. Now add two functions neighbors and degree to your program. Each function should take as arguments the arrays A and W and a word w. The neighbors function should return an array of all the neighbors of w in the word graph and the degree function should return the number of neighbors of w in the word graph. In order for these functions to be efficient, you should use binary search to figure out which slot in W the word w appears in. hat reads from words.dat and constructs an adjacency list representation Now use your code to answer the following questions: (a) What is the highest degree in the word graph? (b) Which are the words that have this highest degree? (c) Which are the words that have degree 0 in the word graph? (d) What is the total number of edges in the word graph? 1. Consider the 5-letter words in the text file words.dat that was posted for Homework 4. Define an undirected graph whose vertex set is exactly the set of words in this file. The edges of this graph connect every pair of words w and u' if and only if w and u' differ in exactly one letter. For example, the words above and abode would be connected by an edge, since they differ only in the 4th letter. Let us call this the word graph. Write a program t of the word graph. To build an adjacency list representation that provides efficient access, first read the words from the file into an array W of size 5,757. Since the words appear in the file in sorted order, they can be placed in W in sorted order without much effort. Now build a second array, called A, such that for any word w, if w appears in slot i in array W, then slot i in the array A points to the list of the neighbors of w in the word graph. Now add two functions neighbors and degree to your program. Each function should take as arguments the arrays A and W and a word w. The neighbors function should return an array of all the neighbors of w in the word graph and the degree function should return the number of neighbors of w in the word graph. In order for these functions to be efficient, you should use binary search to figure out which slot in W the word w appears in. hat reads from words.dat and constructs an adjacency list representation Now use your code to answer the following questions: (a) What is the highest degree in the word graph? (b) Which are the words that have this highest degree? (c) Which are the words that have degree 0 in the word graph? (d) What is the total number of edges in the word graph

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

10th Edition

0137916787, 978-0137916788

More Books

Students also viewed these Databases questions

Question

c. What were you expected to do when you grew up?

Answered: 1 week ago

Question

4. Describe how cultural values influence communication.

Answered: 1 week ago

Question

3. Identify and describe nine cultural value orientations.

Answered: 1 week ago