0% found this document useful (0 votes)
114 views3 pages

ProgrammingProblem Search Part1 New

The document describes a programming problem to design an algorithm that matches web page results to search queries based on keyword relevance. Keywords are assigned integer weights for pages and queries, and the match strength is calculated as the sum of weights for matching keywords. The program must output the top 5 most relevant pages for each query based on this score. Sample input/output is provided to test the solution.

Uploaded by

Shyam Tayal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
114 views3 pages

ProgrammingProblem Search Part1 New

The document describes a programming problem to design an algorithm that matches web page results to search queries based on keyword relevance. Keywords are assigned integer weights for pages and queries, and the match strength is calculated as the sum of weights for matching keywords. The program must output the top 5 most relevant pages for each query based on this score. Sample input/output is provided to test the solution.

Uploaded by

Shyam Tayal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

ProgrammingProblemSearchPart1

Instructions

Solvetheproblemdescribedbelowusing aProgrammingLanguage ofyourchoice.The


objectiveoftheproblemistoallowyoutodemonstratetwoaspects:
Abilitytosolveaproblemtocompletiongivenanylanguage.
Programminganddesignskills,preferableObjectoriented.

Theproblemisprovidedwithsampledatatobeusedfortestingandyoushouldbeableto
demonstratethesolutionusingthesupplieddataeitherthroughafunctionwhichhasallthe
inputdatausedasaharness(whichprintsthesolutionassoonasitisrun)ORthroughasimple
commandinterfacewhereitshouldbepossibletoentertheinputsasmentionedbelowandsee
theoutput.

Userinterfacedesignisnotthemainfocusoftheproblem.Pleasekeepthisinmindandfocus
onsolvingtheproblemfirst.

Resultingsolutionfilesshouldbeaddedtoazipfileandemailedwithinthedeadline
communicatedtoyou.Youwillberequiredtodiscussyoursolutionattheinterviewwhichwillbe
scheduledpostthecodesubmissiondeadline.Wewillalsoaskyoutoenhancethesolutionto
solvethesecondpartoftheproblemwhichisnotherebutwillbesharedbyusduringthe
interview.

ProblemBackground

CompanyLcmeisparticularlyinterestedinimprovingthevolumeandqualityoftraffictothe
publicfacingwebsitesfromsearchengines.Manyofthesesearchenginesarequite
sophisticated,usingadvancedalgorithmsandparallelsearchingtechniquestoprovidefast,
accurateresponses.Thisproblemishowever,somewhatsimpler.

Agroupofwebpageshasbeenclassifiedbyassociatingalistofkeywords,givenindecreasing
orderofrelevance,witheachpage(i.e.,theorderofkeywordsisfromthemostspecifickeyword
totheleastspecific).Forexample,ontheTopGearwebsiteapageonreviewsofFordcarsmay
havethekeywords:Ford,Car,ReviewinthatorderthemostrelevantkeywordisFord.

Queriesalsoincludealistofkeywords,againfrommosttoleastrelevant.Forexample,ina
queryconsistingofthekeywordFordfollowedbythekeywordCar,Fordismoreimportantthan
Car.

Inthisproblemyouaretodeterminethetopfive(orfewer)pagesthatmatcheachofan
arbitrarynumberofqueries.

Todeterminethestrengthoftherelationshipbetweenaqueryandawebpage,assumethe
keywordsforeachpageandeachqueryareassignedintegerweights,indescending
order,startingwithN,whereNisthemaximumnumberofkeywordsallowedforawebpageand
query.

Thestrengthoftherelationshipisthesumoftheproductsoftheweightsassociatedwith
eachkeywordthatappearsbothinthewebpagelistandthequerylist.

Forexample,assumethefollowingwebpagesandkeywordlists:

Page1:Ford,Car,Review
Page2:Toyota,Car
Page3:Car,Ford

ForNequal8,aquerywithkeywordsFordandCarinthatorderyieldsthefollowingstrength
ratings.

Page1:(8x8+7x7)=113
Page2:(7x7)=49
Page3:(8x7)(7x8)=112.

Similarly,aquerywithkeywordsFordandReviewyieldsthefollowingstrengthratings.

Page1:(8x8+7x6)=106
Page2:=0
Page3:(8x7)=56

Input

Inputdataconsistofonelineforeachwebpageandquery.Alineconsistsofacodeletter
followedbyalistofkeywords.CodelettersPandQdenoteapageandaquery.Codeletters
andkeywordsareseparatedbyatleastonespace.PsandQsmayoccurinanyorder.

Pagesareaddedsequentiallystartingwithpageone.Thecaseofcharactersinthekeywordsis
notsignificant.Eachqueryalsohasofalistofbetweenoneand8keywords.Again,casebeing
insignificantforkeywords.Numberthequeriessequentiallystartingwithone.


Output

Foreachquery,identifythe5(orfewer)pagesstoredthatarethemostrelevanttothequery.
Printasinglelinecontainingthequeryidentifier,acolon,andthepageidentifiersofthefive
mostrelevantpagesinthedecreasingorderofrelevance.Pageidentifiersconsistoftheletter
Pfollowedbythepagenumber.QueryidentifiersconsistoftheletterQfollowedbythequery
number.Ifseveralpageshavethesamerelevance,listthembyincreasingpagenumber.Do
notlistpagesthathavenorelationship(zerostrength),eveniffewerthanfivepagesare
identified.

AdditionalConsiderations

Althoughthesearchstrengthalgorithmdescribedhereisquitesimple,developersshouldmake
provisionforsubstitutingamorecomplexmethodinthefutureandconsidertheimpactof
nestedpages.

SampleInput

PFordCarReview
PReviewCar
PReviewFord
PToyotaCar
PHondaCar
PCar
QFord
QCar
QReview
QFordReview
QFordCar
QcookingFrench

OutputfortheSampleInput

Q1:P1P3
Q2:P6P1P2P4P5
Q3:P2P3P1
Q4:P3P1P2
Q5:P1P3P6P2P4
Q6:

Endofproblem

You might also like