SlideShare une entreprise Scribd logo
1  sur  2
Fill in the blanks to write a recurrence relation called RecSearch find a specific value x in a list
of size n. You may assume that the list in held in an array called A. Efficiency is not a concern.
You must use recursion. The function should return an index (position) of the desired item. Do
not make any assumptions about the nature of the list.
RecSearch(A,n,x) = ______________ if ________________= ________________ //
_________________ >= 1 (can also index from zero)
RecSearch(A,n,x) = ______________ // otherwise
Solution
The given recurrence relation can be shown in the form of algorithm as follows:
int RecSearch(int A[], int n, int x)
{
if(n <= 0)
{
return - 1;
}
else if(A[n-1] == x)
{
return (n - 1);
}
return RecSearch(A, n - 1, x);
}
The recurrence relation RecSearch(A, n, x) will return -1 if the value of n is less than or equal to
0. The recurrence relation RecSearch(A, n, x) will return the index of the element if the condition
if(A[n – 1] == x) is satisfied.
The RecSearch(A, n, x) will return the index returned by the multiple calls to the RecSearch(A, n
- 1, x).
The blanks given in the problem can be filled as follows:
RecSearch(A, n, x) = -1 if n < = 0 // if n >= 1 (can also index from zero) RecSearch(A, n, x) =
RecSearch(A, n – 1, x) // otherwise.

Contenu connexe

Similaire à Fill in the blanks to write a recurrence relation called RecSearch fin.docx

Domain-Range-Intercepts-Zeros-and-Asymptotes-of-Rational-Function.pptx
Domain-Range-Intercepts-Zeros-and-Asymptotes-of-Rational-Function.pptxDomain-Range-Intercepts-Zeros-and-Asymptotes-of-Rational-Function.pptx
Domain-Range-Intercepts-Zeros-and-Asymptotes-of-Rational-Function.pptx
NeomyAngelaLeono1
 
3 2 linear equations and lines
3 2 linear equations and lines3 2 linear equations and lines
3 2 linear equations and lines
math123a
 
Mathematics power point presenttation on the topic
Mathematics power point presenttation on the topicMathematics power point presenttation on the topic
Mathematics power point presenttation on the topic
Meghansh Gautam
 
Pc8 6 parametric equations notes
Pc8 6 parametric equations notesPc8 6 parametric equations notes
Pc8 6 parametric equations notes
vhiggins1
 

Similaire à Fill in the blanks to write a recurrence relation called RecSearch fin.docx (20)

Edsc 304 lesson 1
Edsc 304 lesson 1Edsc 304 lesson 1
Edsc 304 lesson 1
 
Function and their graphs ppt
Function and their graphs pptFunction and their graphs ppt
Function and their graphs ppt
 
Lesson 1
Lesson 1Lesson 1
Lesson 1
 
Lesson 1
Lesson 1Lesson 1
Lesson 1
 
Introduction to R
Introduction to RIntroduction to R
Introduction to R
 
Lambda Calculus
Lambda CalculusLambda Calculus
Lambda Calculus
 
Semi-Supervised Regression using Cluster Ensemble
Semi-Supervised Regression using Cluster EnsembleSemi-Supervised Regression using Cluster Ensemble
Semi-Supervised Regression using Cluster Ensemble
 
Domain-Range-Intercepts-Zeros-and-Asymptotes-of-Rational-Function.pptx
Domain-Range-Intercepts-Zeros-and-Asymptotes-of-Rational-Function.pptxDomain-Range-Intercepts-Zeros-and-Asymptotes-of-Rational-Function.pptx
Domain-Range-Intercepts-Zeros-and-Asymptotes-of-Rational-Function.pptx
 
Statistics lab 1
Statistics lab 1Statistics lab 1
Statistics lab 1
 
5.6 Rational Functions
5.6 Rational Functions5.6 Rational Functions
5.6 Rational Functions
 
Machine learning
Machine learningMachine learning
Machine learning
 
3 2 linear equations and lines
3 2 linear equations and lines3 2 linear equations and lines
3 2 linear equations and lines
 
Mathematics power point presenttation on the topic
Mathematics power point presenttation on the topicMathematics power point presenttation on the topic
Mathematics power point presenttation on the topic
 
57 graphing lines from linear equations
57 graphing lines from linear equations57 graphing lines from linear equations
57 graphing lines from linear equations
 
R command cheatsheet.pdf
R command cheatsheet.pdfR command cheatsheet.pdf
R command cheatsheet.pdf
 
@ R reference
@ R reference@ R reference
@ R reference
 
2 data types and operators in r
2 data types and operators in r2 data types and operators in r
2 data types and operators in r
 
Pc8 6 parametric equations notes
Pc8 6 parametric equations notesPc8 6 parametric equations notes
Pc8 6 parametric equations notes
 
2 linear equations in x&amp;y lines x
2 linear equations in x&amp;y lines x2 linear equations in x&amp;y lines x
2 linear equations in x&amp;y lines x
 
Short Reference Card for R users.
Short Reference Card for R users.Short Reference Card for R users.
Short Reference Card for R users.
 

Plus de jkristen1

B- lonic Bonds- Some atoms have such a strong attraction for electrons.docx
B- lonic Bonds- Some atoms have such a strong attraction for electrons.docxB- lonic Bonds- Some atoms have such a strong attraction for electrons.docx
B- lonic Bonds- Some atoms have such a strong attraction for electrons.docx
jkristen1
 
b- Does Rutherford-'s model predict the correct spectrum- Answer- Acco.docx
b- Does Rutherford-'s model predict the correct spectrum- Answer- Acco.docxb- Does Rutherford-'s model predict the correct spectrum- Answer- Acco.docx
b- Does Rutherford-'s model predict the correct spectrum- Answer- Acco.docx
jkristen1
 
Fill out the following table for four different IT systems- Note two.docx
Fill out the following table for four different IT systems-  Note two.docxFill out the following table for four different IT systems-  Note two.docx
Fill out the following table for four different IT systems- Note two.docx
jkristen1
 

Plus de jkristen1 (20)

Based on differences in electronegativity- how would you characterize.docx
Based on differences in electronegativity- how would you characterize.docxBased on differences in electronegativity- how would you characterize.docx
Based on differences in electronegativity- how would you characterize.docx
 
Balance the redox reaction by inserting the appropriate coefficients-.docx
Balance the redox reaction by inserting the appropriate coefficients-.docxBalance the redox reaction by inserting the appropriate coefficients-.docx
Balance the redox reaction by inserting the appropriate coefficients-.docx
 
Auditing and Accounting Cases Investigating Issues of Fraud and Profes (2).docx
Auditing and Accounting Cases Investigating Issues of Fraud and Profes (2).docxAuditing and Accounting Cases Investigating Issues of Fraud and Profes (2).docx
Auditing and Accounting Cases Investigating Issues of Fraud and Profes (2).docx
 
b- Impact testing was used to assess which property of the materials-.docx
b- Impact testing was used to assess which property of the materials-.docxb- Impact testing was used to assess which property of the materials-.docx
b- Impact testing was used to assess which property of the materials-.docx
 
B- lonic Bonds- Some atoms have such a strong attraction for electrons.docx
B- lonic Bonds- Some atoms have such a strong attraction for electrons.docxB- lonic Bonds- Some atoms have such a strong attraction for electrons.docx
B- lonic Bonds- Some atoms have such a strong attraction for electrons.docx
 
b- Does Rutherford-'s model predict the correct spectrum- Answer- Acco.docx
b- Does Rutherford-'s model predict the correct spectrum- Answer- Acco.docxb- Does Rutherford-'s model predict the correct spectrum- Answer- Acco.docx
b- Does Rutherford-'s model predict the correct spectrum- Answer- Acco.docx
 
Auditors should perform audit procedures to identify and assess subseq.docx
Auditors should perform audit procedures to identify and assess subseq.docxAuditors should perform audit procedures to identify and assess subseq.docx
Auditors should perform audit procedures to identify and assess subseq.docx
 
Auditing and Accounting Cases Investigating Issues of Fraud and Profes.docx
Auditing and Accounting Cases Investigating Issues of Fraud and Profes.docxAuditing and Accounting Cases Investigating Issues of Fraud and Profes.docx
Auditing and Accounting Cases Investigating Issues of Fraud and Profes.docx
 
AuditorSolution1) The auditors opinion on internal control is satisfie.docx
AuditorSolution1) The auditors opinion on internal control is satisfie.docxAuditorSolution1) The auditors opinion on internal control is satisfie.docx
AuditorSolution1) The auditors opinion on internal control is satisfie.docx
 
Auditing and Accounting Cases Investigating Issues of Fraud and Profes (5).docx
Auditing and Accounting Cases Investigating Issues of Fraud and Profes (5).docxAuditing and Accounting Cases Investigating Issues of Fraud and Profes (5).docx
Auditing and Accounting Cases Investigating Issues of Fraud and Profes (5).docx
 
Athens- Inc-- has 9-000 shares of common stock outstanding and the fol.docx
Athens- Inc-- has 9-000 shares of common stock outstanding and the fol.docxAthens- Inc-- has 9-000 shares of common stock outstanding and the fol.docx
Athens- Inc-- has 9-000 shares of common stock outstanding and the fol.docx
 
At time 110 four processes (P1 P4) are waiting for a timeout signal-.docx
At time 110 four processes (P1  P4) are waiting for a timeout signal-.docxAt time 110 four processes (P1  P4) are waiting for a timeout signal-.docx
At time 110 four processes (P1 P4) are waiting for a timeout signal-.docx
 
At January 1- 2012- Lance Link Corporation had 100-000 shares of $1 pa.docx
At January 1- 2012- Lance Link Corporation had 100-000 shares of $1 pa.docxAt January 1- 2012- Lance Link Corporation had 100-000 shares of $1 pa.docx
At January 1- 2012- Lance Link Corporation had 100-000 shares of $1 pa.docx
 
At December 31- 2013- Hansen Corporation had 42-000 shares of common s.docx
At December 31- 2013- Hansen Corporation had 42-000 shares of common s.docxAt December 31- 2013- Hansen Corporation had 42-000 shares of common s.docx
At December 31- 2013- Hansen Corporation had 42-000 shares of common s.docx
 
File- LineScrabbleDriver-java -U 4- in-Desktop-Guess this is the death.docx
File- LineScrabbleDriver-java -U 4- in-Desktop-Guess this is the death.docxFile- LineScrabbleDriver-java -U 4- in-Desktop-Guess this is the death.docx
File- LineScrabbleDriver-java -U 4- in-Desktop-Guess this is the death.docx
 
Fill out the following table for four different IT systems- Note two.docx
Fill out the following table for four different IT systems-  Note two.docxFill out the following table for four different IT systems-  Note two.docx
Fill out the following table for four different IT systems- Note two.docx
 
Figure 9-3 shows an energy diagram for the dissolving of an ionic comp.docx
Figure 9-3 shows an energy diagram for the dissolving of an ionic comp.docxFigure 9-3 shows an energy diagram for the dissolving of an ionic comp.docx
Figure 9-3 shows an energy diagram for the dissolving of an ionic comp.docx
 
FakeArrayList first - new FakeArrayl_ist(3)- first-set(2- 7-1)- first-.docx
FakeArrayList first - new FakeArrayl_ist(3)- first-set(2- 7-1)- first-.docxFakeArrayList first - new FakeArrayl_ist(3)- first-set(2- 7-1)- first-.docx
FakeArrayList first - new FakeArrayl_ist(3)- first-set(2- 7-1)- first-.docx
 
Explain why workplace spirituality seems to be an important concern-So.docx
Explain why workplace spirituality seems to be an important concern-So.docxExplain why workplace spirituality seems to be an important concern-So.docx
Explain why workplace spirituality seems to be an important concern-So.docx
 
Explanation of the similarities and differences between the Income Sta.docx
Explanation of the similarities and differences between the Income Sta.docxExplanation of the similarities and differences between the Income Sta.docx
Explanation of the similarities and differences between the Income Sta.docx
 

Dernier

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Dernier (20)

This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 

Fill in the blanks to write a recurrence relation called RecSearch fin.docx

  • 1. Fill in the blanks to write a recurrence relation called RecSearch find a specific value x in a list of size n. You may assume that the list in held in an array called A. Efficiency is not a concern. You must use recursion. The function should return an index (position) of the desired item. Do not make any assumptions about the nature of the list. RecSearch(A,n,x) = ______________ if ________________= ________________ // _________________ >= 1 (can also index from zero) RecSearch(A,n,x) = ______________ // otherwise Solution The given recurrence relation can be shown in the form of algorithm as follows: int RecSearch(int A[], int n, int x) { if(n <= 0) { return - 1; } else if(A[n-1] == x) { return (n - 1); } return RecSearch(A, n - 1, x); }
  • 2. The recurrence relation RecSearch(A, n, x) will return -1 if the value of n is less than or equal to 0. The recurrence relation RecSearch(A, n, x) will return the index of the element if the condition if(A[n – 1] == x) is satisfied. The RecSearch(A, n, x) will return the index returned by the multiple calls to the RecSearch(A, n - 1, x). The blanks given in the problem can be filled as follows: RecSearch(A, n, x) = -1 if n < = 0 // if n >= 1 (can also index from zero) RecSearch(A, n, x) = RecSearch(A, n – 1, x) // otherwise.