10101010:2和3都用文字输入看看结果咋样吧。图片可能效果不好

2. Text indexing Write a program that builds an index from a large piece of text, then does fast searches to find the position of query strings within the text. Your program should take two filenames as command-line arguments: the text file (which we refer to as the corpus) and a file containing the queries. Assume that both files contain only lower-case letters, blanks, and newline characters, with queries in the query file delimited by newline characters. Your program should read the corpus, store it as a (potentially huge) string, and build an index for it, as discussed below. Then it should read queries one by one, assuming one query per line in the second named file on the command line, and print out the position in the corpus where each query first appears. For example, for the corpus corpus.txt: it was the best of times it was the worst of times it was the age of wisdom it was the age of foolishness it was the epoch of belief it was the epoch of incredulity it was the season of light it was the season of darkness it was the spring of hope it was the winter of despair and the query file query.txt, the result of java TextIndexing corpus.txt query.txt should be 69 wisdom 176 season 87 age of foolishness -- age of fools 19 times indicating that wisdom appears at character position 69, age of fools does not appear, the first occurrence of times is at character position 19, and so forth. There are numerous different ways to solve this problem, all with different characteristics in terms of ease of implementation, space requirements, and time requirements. You may begin with a brute-force implementation. That is, don't build an index at all: just search through the corpus for each query string. This solution is fine if the corpus is tiny, or if there are not many queries. But this method is much too slow when the corpus is huge and there are a huge number of queries, so to get a higher score on this program, you will need to implement a faster solution. Another possible approach is to take advantage of Symbol Table to build indices. You may modify the codes on the slides, or write your own code from scratch. Important note: Get the brute-force solution working first. Not only will it provide a framework for more complicated solutions (like the code we usually provide) but also it will give you a way to compute correct output for comparison when debugging more complicated solutions.

3. Small World Phenomenon The small-world experiment comprised several experiments conducted by Stanley Milgram and other researchers examining the average path length for social networks of people in the United States. The research was groundbreaking in that it suggested that human society is a small-world-type network characterized by short path-lengths. The experiments are often associated with the phrase "six degrees of separation", although Milgram did not use this term himself. In brief, this phenomenon suggests that every two people in the world, related to each other via people they know. In this assignment you will investigate the six degrees of Kevin Bacon. Two actors or actresses are linked if they appeared in a movie together. The Kevin Bacon number of an actor is the shortest chain of links that leads to Kevin Bacon. For example, Robert De Niro has a Kevin Bacon number of 1 because he appeared in Sleepers with Kevin Bacon. Elvis Presley's number is 2: although Elvis did not appear in any movie with Kevin Bacon, he was in Change of Habit with Edward Asner, and Asner appeared in JFK with Kevin Bacon. Your task is to read in a file containing a list of movies and the actors that appeared in them and compute the Kevin Bacon numbers for each actor. You will then read in a list of actors from standard input and print out a shortest chain of movies that leads each actor back to Kevin Bacon. Input format. In addition to the massive list of movies and casts from the Internet Movie Database, we include some smaller data files that include only a specific subset of movies (IMDB_Input.txt). Each line in the data file consists of a movie title, followed by a list of actors and actresses that appeared in that movie, delimited by the character '/'. Here is an abbreviated example: Picture Perfect (1997)/Aniston, Jennifer/Bacon, Kevin/Dukakis, Olympia/Mohr, Jay Planes, Trains & Automobiles (1987)/Bacon, Kevin/Candy, John/Martin, Steve/Robins, Laila Use a command-line parameter to enter the name of the movie database file. You will also read in a list of actors from standard input, one per line. Output format. First, print out a table of the distribution of Kevin Bacon numbers, namely number of actors with each Kevin Bacon number. Bacon number Frequency ------------------------- 0 1 1 1494 2 127791 3 239671 4 36475 5 2965 6 275 7 39 8 47 9 99 10 15 11 2 infinity 9703 Then, for each actor and actress read from standard input, print out their Kevin Bacon number and a shortest chain of movies that connect them to Kevin Bacon. Here's an example. Dane, Cynthia has a Bacon number of 3 Dane, Cynthia was in "Solstice (1994)" with Scott, Dennis Scott, Dennis was in "What About Bob? (1991)" with Murray, Bill Murray, Bill was in "Wild Things (1998)" with Bacon, Kevin Hints. The program finds the nearest relation between actors and Kevin Bacon (Kevin Bacon number of an actor) by reading from a file via Breadth First Search algorithm over a graph. It creates a graph by adjacency lists of actors which represents relations between actors. Two actors played in the same movie means they are related to each other by the movie. Then, program finds every single actor's Kevin Bacon number by using Breadth First Search algorithm over the graph and prints number of actors with each Kevin Bacon number. Afterwards, it keeps asking the user for an actor to show relation between this actor and Kevin Bacon, and printing the relation between actors until a special character or command has been typed (‘E’ for instance).

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值