Professional Documents
Culture Documents
AlgorithmsInterviewQuestions | 35960
1.Definetheconceptofanalgorithm.
Analgorithmisanywelldefinedcomputationalprocedurethattakessomevalue(orsetofvalues)asinputandproducessomevalue(orsetof
values)asoutput.Inshort,itcanbeseenasasequenceofcomputationalstepsthattransformtheinputintotheoutput.
2.Whataretheargumentspresentinpatternmatchingalgorithms?
ThesearethefollowingargumentswhicharepresentinpatternmatchingAlgorithms.
1)Subject,
2)Pattern
3)Cursor
4)MATCH_STR
5)REPLACE_STR
6)REPLACE_FLAG
3.ExplainthefunctionSUBinalgorithmicnotation?
Inthealgorithmicnotationratherthanusingspecialmarkersymbols,generallypeopleusethecursorpositionplusasubstringlengthtoisolate
asubstring.ThenameofthefunctionisSUB.
SUBreturnsavaluethesubstringofSUBJECTthatisspecifiedbytheparametersiandjandanassumedvalueofj.
4.InAlgorithmiccontexthowwouldyoudefinebookkeepingoperations?
Usuallywhenauserwantstoestimatetimeheisolatesthespecificfunctionandbrandsitasactiveoperation.Theotheroperationsinthe
algorithm,theassignments,themanipulationsoftheindexandtheaccessingofavalueinthevector,occurnomoreoftenthantheadditionof
vectorvalues.Theseoperationsarecollectivelycalledas bookkeepingoperations .
5.Defineanddescribeaniterativeprocesswithgeneralstepsofflowchart?
Therearefourpartsintheiterativeprocesstheyare
Initialization:Thedecisionparameterisusedtodeterminewhentoexitfromtheloop.
Decision:Thedecisionparameterisusedtodeterminewhethertoremainintheloopornot.
feedback
Computation:Therequiredcomputationisperformedinthispart.
Update:Thedecisionparameterisupdatedandatransfertothenextiterationresults.
6.Staterecursionanditsdifferenttypes?
Recursionisthenamegiventothetechniqueofdefiningasetoraprocessintermsofitself.Thereareessentiallytwotypesofrecursion.The
firsttypeconcernsrecursivelydefinedfunctionandthesecondtypeofrecursionistherecursiveuseofaprocedure.
7.Defineandstatetheimportanceofsubalgorithmincomputationanditsrelationshipwithmainalgorithm?
Asubalgorithmisanindependentcomponentofanalgorithmandforthisreasonisdefinedseparatelyfromthemainalgorithm.Thepurpose
ofasubalgorithmistoperformsomecomputationwhenrequired,undercontrolofthemainalgorithm.Thiscomputationmaybeperformedon
zeroormoreparameterspassedbythecallingroutine.
8.Nameanythreeskillswhichareveryimportantinordertoworkwithgeneratingfunctions.
Thethreemostimportantskillswhichareusedextensivelywhileworkingwithgeneratingfunctionsare
1)Manipulatesummationexpressionsandtheirindices.
2)Solvealgebraicequationsandmanipulatealgebraicexpressions,includingpartialfunctiondecompositions.
3)Identifysequenceswiththeirgeneratingfunctions
9.WhatisthegeneralstrategyforMarkovAlgorithm?
ThegeneralstrategyinaMarkovAlgorithmistotakeasinputastringxand,throughanumberofstepsinthealgorithm,transformxtoan
outputstringy.thistransformationprocessisgenerallyperformedincomputersfortexteditingorprogramcompilation.
10.Definestringinanalgorithmicnotationandanexampletosupportit?
Inthealgorithmicnotation,astringisexpressedasanysequenceofcharactersenclosedinsinglequotemarks.
11.HowtofindmedianofaBST?
Findtheno.ofelementsontheleftside.
Ifitisn1therootisthemedian.
Ifitismorethann1,thenithasalreadybeenfoundintheleftsubtree.
http://placement.freshersworld.com/algorithmsinterviewquestions/33121998181 1/6
6/18/2017 AlgorithmsInterviewQuestions
Elseitshouldbeintherightsubtree
12.WhatisDiffieHellman?
Itisamethodbywhichakeycanbesecurelysharedbytwouserswithoutanyactualexchange.
13.Whatisthegoaloftheshortestdistancealgorithm?
Thegoaliscompletelyfillthedistancearraysothatforeachvertexv,thevalueofdistance[v]istheweightoftheshortestpathfromstartto
v.
14.Explainthedepthofrecursion?
Thisisanotherrecursionprocedurewhichisthenumberoftimestheprocedureiscalledrecursivelyintheprocessofenlargingagiven
argumentorarguments.Usuallythisquantityisnotobviousexceptinthecaseofextremelysimplerecursivefunctions,suchasFACTORIAL
(N),forwhichthedepthisN.
15.ExplainaboutthealgorithmORD_WORDS?
ThisalgorithmconstructsthevectorsTITLE,KEYWORDandT_INDEX.
16.Whicharethesortingalgorithmscategories?
Sortingalgorithmscanbedividedintofivecategories:
a)insertionsorts
b)exchangesorts
c)selectionsorts
d)mergesorts
e)distributionsorts
17.Defineabruteforcealgorithm.Giveashortexample.
Abruteforcealgorithmisatypeofalgorithmthatproceedsinasimpleandobviousway,butrequiresahugenumberofstepstocomplete.As
feedback
anexample,ifyouwanttofindoutthefactorsofagivennumberN,usingthissortofalgorithmwillrequiretogetonebyoneallthepossible
numbercombinations.
18.Whatisagreedyalgorithm?Giveexamplesofproblemssolvedusinggreedyalgorithms.
Agreedyalgorithmisanyalgorithmthatmakesthelocaloptimalchoiceateachstagewiththehopeoffindingtheglobaloptimum.Aclassical
problemwhichcanbesolvedusingagreedystrategyisthetravelingsalesmanproblem.Anotherproblemsthatcanbesolvedusinggreedy
algorithmsarethegraphcoloringproblemandalltheNPcompleteproblems.
19.Whatisabacktrackingalgorithm?Provideseveralexamples.
Itisanalgorithmthatconsiderssystematicallyallpossibleoutcomesforeachdecision.Examplesofbacktrackingalgorithmsaretheeight
queensproblemorgeneratingpermutationsofagivensequence.
20.Whatisthedifferencebetweenabacktrackingalgorithmandabruteforceone?
Duetothefactthatabacktrackingalgorithmtakesallthepossibleoutcomesforadecision,itissimilarfromthispointofviewwiththebrute
forcealgorithm.Thedifferenceconsistsinthefactthatsometimesabacktrackingalgorithmcandetectthatanexhaustivesearchis
unnecessaryand,therefore,itcanperformmuchbetter.
21.Describedivideandconquerparadigm.
Whenaproblemissolvedusingadivideandconqueralgorithm,itissubdividedintooneormoresubproblemswhichareallsimilartothe
originalprobleminsuchawaythateachofthesubproblemscanbesolvedindependently.Intheend,thesolutionstothesubproblemsare
combinedinordertoobtainthesolutiontotheoriginalproblem.
22.Describeonshortaninsertionsortingalgorithm.
Analgorithmthatsortsbyinsertiontakestheinitial,unsortedsequenceandcomputesaseriesofsortedsequencesusingthefollowingrules:
a)thefirstsequenceintheseriesistheemptysequence
b)givenasequenceS(i)intheseries,for0<=i
23.Whicharetheadvantagesprovidedbyinsertionsort?
http://placement.freshersworld.com/algorithmsinterviewquestions/33121998181 2/6
6/18/2017 AlgorithmsInterviewQuestions
Insertionsortprovidesseveraladvantages:
a)simpleimplementation
b)efficientforsmalldatasets
c)adaptiveefficientfordatasetsthatarealreadysubstantiallysorted:thetimecomplexityisO(n+d),wheredisthenumberofinversions
d)moreefficientinpracticethanmostothersimplequadratic,i.e.O(n2)algorithmssuchasselectionsortorbubblesortthebestcase(nearly
sortedinput)isO(n)
e)stabledoesnotchangetherelativeorderofelementswithequalkeys
f)inplaceonlyrequiresaconstantamountO(1)ofadditionalmemoryspace
g)onlinecansortalistasitreceivesit
24.Shortlydescribethequicksortalgorithm.
Inquicksort,thestepsperformedarethefollowing:
a)pickanelement,calledapivot,fromthelist
b)reorderthelistsothatallelementswithvalueslessthanthepivotcomebeforethepivot,whileallelementswithvaluesgreaterthanthe
pivotcomeafterit(equalvaluescangoeitherway)
c)recursivelysortthesublistoflesserelementsandthesublistofgreaterelements
25.Whatisthedifferencebetweenselectionandinsertionsorting?
Ininsertionsortingelementsareaddedtothesortedsequenceinanarbitraryorder.Inselectionsorting,theelementsareaddedtothesorted
sequenceinordersotheyarealwaysaddedatoneend.
26.Whatismergesorting?
Mergingisthesortingalgorithmwhichcombinestwoormoresortedsequencesintoasinglesortedsequence.Itisadivideandconquer
algorithm,anO(nlogn)comparisonbasedsortingalgorithm.Mostimplementationsproduceastablesort,meaningthattheimplementation
preservestheinputorderofequalelementsinthesortedoutput.
27.Whicharethemainstepsofamergesortingalgorithm?
Sortingbymergingisarecursive,divideandconquerstrategy.Thebasicstepstoperformarethefollowing:
a)dividethesequenceintotwosequencesoflength
b)recursivelysorteachofthetwosubsequences
c)mergethesortedsubsequencestoobtainthefinalresult
feedback
28.Provideashortdescriptionofbinarysearchalgorithm.
Binarysearchalgorithmalwayschoosesthemiddleoftheremainingsearchspace,discardingonehalfortheother,againdependingonthe
comparisonbetweenthekeyvaluefoundattheestimatedpositionandthekeyvaluesought.Theremainingsearchspaceisreducedtothepart
beforeoraftertheestimatedposition.
29.Whatisthelinearsearchalgorithm?
Linearsearchisamethodforfindingaparticularvalueinalistwhichconsistsofcheckingeveryoneofitselements,oneatatimeandin
sequence,untilthedesiredoneisfound.Itisthesimplestsearchalgorithm,aspecialcaseofbruteforcesearch.Itsworstcasecostis
proportionaltothenumberofelementsinthelistandsoisitsexpectedcost,ifalllistelementsareequallylikelytobesearchedfor.
Therefore,ifthelisthasmorethanafewelements,othermethods(suchasbinarysearchorhashing)maybemuchmoreefficient.
30.Whatisbestfirstsearchalgorithm?
Itisasearchalgorithmthatconsiderstheestimatedbestpartialsolutionnext.Thisistypicallyimplementedwithpriorityqueues.
31.WhatisHuffmancoding?
Incomputerscienceandinformationtheory,Huffmancodingisanentropyencodingalgorithmusedforlosslessdatacompression.Theterm
referstotheuseofavariablelengthcodetableforencodingasourcesymbol(suchasacharacterinafile)wherethevariablelengthcode
tablehasbeenderivedinaparticularwaybasedontheestimatedprobabilityofoccurrenceforeachpossiblevalueofthesourcesymbol.
GetinTouchwithus
(https://www.facebook.com/freshersworld)
(http://twitter.com/freshersworld)
(http://www.linkedin.com/company/freshersworld
(https://plus.google.com/+freshersworld)
(https://www.youtube.com/user/freshersworld)
com)
AdvertiseWithUs(http://www.freshersworld.com/advertise) RecruitmentSolutions(http://corp.freshersworld.com/employers)
ContactUs(http://www.freshersworld.com/contactus)
20062017Freshersworld.com
http://placement.freshersworld.com/algorithmsinterviewquestions/33121998181 3/6
6/18/2017 AlgorithmsInterviewQuestions
http://placement.freshersworld.com/algorithmsinterviewquestions/33121998181 4/6
6/18/2017 AlgorithmsInterviewQuestions
http://placement.freshersworld.com/algorithmsinterviewquestions/33121998181 5/6
6/18/2017 AlgorithmsInterviewQuestions
http://placement.freshersworld.com/algorithmsinterviewquestions/33121998181 6/6