Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fibonacci Search in C++ #2265

Merged
merged 4 commits into from
Mar 8, 2021
Merged

Fibonacci Search in C++ #2265

merged 4 commits into from
Mar 8, 2021

Conversation

maneprajakta
Copy link
Contributor

Have you read the Contributing Guidelines on Pull Requests?

YES

Description

I have added Fibonacci search under the search section in c++.

Checklist

  • I've read the contribution guidelines.
  • I've checked the issue list before deciding what to submit.
  • I've edited the README.md and link to my code.

Related Issues or Pull Requests

#2242

Copy link
Owner

@HarshCasper HarshCasper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good. Stylistic changes requested 👍

Comment on lines 122 to 130
2.
Enter Size Of Arrary:
4
Enter Elements In Array
1 2 3 4
Enter The Element To Be Searched
5
Element Not Found

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this. One sample I/O does the trick

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay

Comment on lines 84 to 107
int n; /* size of array */
cout<<"Enter Size Of Arrary:"<<"\n";
cin>>n;

int arr[n]; /* array declaration */
cout<<"Enter Elements In Array"<<"\n";

for(int i=0;i<n;i++)
{
cin>>arr[i];
}

int element; /* Element that user want's to search */
cout<<"Enter The Element To Be Searched"<<"\n";
cin>>element;

int index = fibonacciSearch(arr,n,element); /* Call fibonacci search function */

if(index==-1)
cout<<"Element Not Found"<<"\n"; /* if element is not present */
else
cout<<"Element Found At Array Index : "<<index; /* if Present print index*/

return 0;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent the Code. In fact, run a formatter on the whole code

/* if found return index */
else return i;
}
/* check for last array element */
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use // ....... for single line comments only

fibM1 = fibM1 - fibM2;
fibM2 = fibM - fibM1;
}
/* if found return index */
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use // ....... for single line comments only


int fibonacciSearch(int arr[],int n,int element)
{
/* Initializing fibonacci no */
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use // ....... for single line comments only

Comment on lines 6 to 7
Time Complexity : O(log(n))
Auxiliary Space : O(1)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep complexities at the end of the code

@maneprajakta
Copy link
Contributor Author

Sure!
Will do all the Changes and Come back to you again.

Copy link
Owner

@HarshCasper HarshCasper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use redundant comments. We don't need to explain what each variable or console statement do

Time Complexity : O(log(n))
Auxiliary Space : O(1)

*/
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a new line at the EOF

if (index == -1)
cout << "Element Not Found" << "\n"; // if element is not present
else
cout << "Element Found At Array Index : " << index; // if Present print index
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use comments above the line of code not beside it.

int index = fibonacciSearch(arr, n, element); // Call fibonacci search function

if (index == -1)
cout << "Element Not Found" << "\n"; // if element is not present
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use comments above the line of code not beside it.

cout << "Enter The Element To Be Searched" << "\n";
cin >> element;

int index = fibonacciSearch(arr, n, element); // Call fibonacci search function
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use comments above the line of code not beside it.

cin >> arr[i];
}

int element; // Element that user want's to search
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use comments above the line of code not beside it.

}

int main() {
int n; // size of array
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use comments above the line of code not beside it.

cout << "Enter Size Of Arrary:" << "\n";
cin >> n;

int arr[n]; // array declaration
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use comments above the line of code not beside it.

Copy link
Contributor

@atarax665 atarax665 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Thank you for your contribution. 👍

@atarax665 atarax665 merged commit 9a5fc1d into HarshCasper:master Mar 8, 2021
@HarshCasper HarshCasper added Level3 25 Points and removed ready-to-merge labels Mar 17, 2021
@ankitaggarwal23 ankitaggarwal23 changed the title 🚀[Feat]: Adding Fibonacci Search in C++ Fibonacci Search in C++ Apr 14, 2021
@HarshCasper HarshCasper added Level2 15 Points Level1 10 Points and removed Level3 25 Points Level2 15 Points labels Apr 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants