SlideShare a Scribd company logo
DEPARTMENT OF INFORMATION SCIENCE
Fibonacci series using pthreads
Presented By-
ROHAN H RAJ 1BI20IS071
RAKSHITHA S 1BI20IS070
RUDRA MRIGNAK 1BI20IS072
SAGAR GHOSH 1BI20IS073
Faculty In charge:
Dr. Hema Jagadish
Associate Professor
Dept of ISE, BIT, Bangalore
BANGALORE INSTITUTE OF TECHNOLOGY
Fibonacci program in c pthread
 In a Fibonacci series, every number (except the first two numbers) is the sum of
the previous two numbers.The mathematical formula for a Fibonacci series is:
 F(n) = F(n - 1) + F(n - 2)F(n)=F(n−1)+F(n−2)
 Here, F(n) represents the n^{th}nth Fibonacci number.
 In Java, we can use different techniques like recursion and memoization to
create a Fibonacci series. Let us take a look at a few examples to understand
how can we create the Fibonacci series.
 Example 1
Fibonacci series using recursion in Java To calculate the Fibonacci series using
we need to create a function so that we can perform recursion. This function
input. The function checks whether the input number is 0, 1, or 2, and it
respectively, if the input is any one of the three numbers. If the input is greater
function calls itself recursively for the previous values until the value of the input
becomes less than or equal to 2. So if the function receives an integer n as input,
the n^th^ Fibonacci number. To print the Fibonacci series we will call this
each Fibonacci number.
public class FibonacciCalc
{
public static int fibRecursion(int count)
{
if (count == 0)
{
return 0;
}
if (count == 1 || count == 2)
{
return 1;
}return fibRecursion(count - 1) + fibRecursion(count - 2);
}
public static void main(String args[])
{
int fib_len = 9;
System.out.print("Fibonacci Series of " + fib_len + " numbers is:
n");
for (int i = 0; i < fib_len; i++)
{
System.out.print(fibRecursion(i) + " ");
}
}
}
Output of the program:
Fibonacci Series of 9 numbers is: 0 1 1 2 3 5 8 13 21
In the above example, we defined a recursive function fib Recursion to get nth Fibonacci
number and call it repeatedly (for i=0 to i=8) in order to create a Fibonacci series of length
9.
Implementation in C
#include <pthread.h>
#include <stdio.h>
int fib;/* this data is shared by the thread(s) */
void *runner(void *param); /* the thread */
int main(int argc, char *argv[])
{ pthread_t tid; /* the thread identifier */
pthread_attr_t attr; /* set of attributes for the thread */
if (argc != 2)
{
fprintf(stderr,"usage: a.out <integer value>n");
return -1;
}
if (atoi(argv[1]) < 0)
{
fprintf(stderr,"Argument %d must be non-negativen",atoi(argv[1]));
return -1;
}
/* get the default attributes */
pthread_attr_init(&attr);
/* create the thread */
pthread_create(&tid,&attr,runner,argv[1]);
/* now wait for the thread to exit */
pthread_join(tid,NULL);
printf("Fibonacci = %dn",fib);
}
if (atoi(argv[1]) < 0)
{
fprintf(stderr,"Argument %d must be non-negativen",atoi(argv[1]));
return -1;
}
/* get the default attributes */
pthread_attr_init(&attr);
/* create the thread */
pthread_create(&tid,&attr,runner,argv[1]);
/* now wait for the thread to exit */
pthread_join(tid,NULL);
printf("Fibonacci = %dn",fib);
}
void *runner(void *param)
{
int i, upper = atoi(param);
fib= 1;
if (upper > 0)
{
int pre1 = 0;
int pre2 = 1;
int current ;
if (fib == 1)
{
printf("The Fibonacci sequence for the number you entered is n");
printf("%dn",pre1);
exit(0);
}
else if (fib == 2)
{
printf("The Fibonacci sequence for the number you entered is n");
printf("%d , %dn",pre1 ,pre2 );
exit(0);
}
else { int j=3;
printf(" nThe Fibonacci sequence for the number you entered is n %d , %d ,",pre1,pre2 );
for(j = 3; j <= fib; j++)
{
current = pre2 + pre1;
pre1 = pre2;
pre2 = current;
printf(" %d ,",current)
}
}
}
pthread_exit(0);
}
*/ ("Foon");
Output
Time And Space Complexity
The time complexity of the recursive approach to solving the
is O(2^n)O(2n) i.e. exponential time. The space complexity of the
method is O(n), if we consider the recursive stack.
Exponential time complexity is extremely inefficient. It would take
calculate the Fibonacci series of a huge length using the recursive
solve this problem, we can use the memorization technique to
Fibonacci series. This technique is much faster than the recursive
CONCLUSIO
Here, we have seen how to build the concurrent application for
Fibonacci series.
THANKYOU

More Related Content

Similar to Presentation 6 (1).pptx

python lab programs.pdf
python lab programs.pdfpython lab programs.pdf
python lab programs.pdf
CBJWorld
 
ECE-PYTHON.docx
ECE-PYTHON.docxECE-PYTHON.docx
ECE-PYTHON.docx
Chaithanya89350
 
L25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxL25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptx
happycocoman
 
Programs.doc
Programs.docPrograms.doc
Programs.doc
ArnabNath30
 
AI-Programs.pdf
AI-Programs.pdfAI-Programs.pdf
AI-Programs.pdf
ArnabNath30
 
New microsoft office word document (2)
New microsoft office word document (2)New microsoft office word document (2)
New microsoft office word document (2)
Syed Umair
 
C++ Course - Lesson 2
C++ Course - Lesson 2C++ Course - Lesson 2
C++ Course - Lesson 2Mohamed Ahmed
 
how to reuse code
how to reuse codehow to reuse code
how to reuse code
jleed1
 
python practicals-solution-2019-20-class-xii.pdf
python practicals-solution-2019-20-class-xii.pdfpython practicals-solution-2019-20-class-xii.pdf
python practicals-solution-2019-20-class-xii.pdf
rajatxyz
 
Anjalisoorej imca133 assignment
Anjalisoorej imca133 assignmentAnjalisoorej imca133 assignment
Anjalisoorej imca133 assignment
AnjaliSoorej
 
Lecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptxLecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptx
jovannyflex
 
Lecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptxLecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptx
jovannyflex
 
EXPT1.pptx
EXPT1.pptxEXPT1.pptx
EXPT1.pptx
swagatkarve
 
Array Cont
Array ContArray Cont
Elegant Solutions for Everyday Python Problems Pycon 2018 - Nina Zakharenko
Elegant Solutions for Everyday Python Problems Pycon 2018 - Nina ZakharenkoElegant Solutions for Everyday Python Problems Pycon 2018 - Nina Zakharenko
Elegant Solutions for Everyday Python Problems Pycon 2018 - Nina Zakharenko
Nina Zakharenko
 
Python program For O level Practical
Python program For O level Practical Python program For O level Practical
Python program For O level Practical
pavitrakumar18
 
python file for easy way practicle programs
python file for easy way practicle programspython file for easy way practicle programs
python file for easy way practicle programs
vineetdhand2004
 

Similar to Presentation 6 (1).pptx (20)

python lab programs.pdf
python lab programs.pdfpython lab programs.pdf
python lab programs.pdf
 
functions
functionsfunctions
functions
 
Algorithms with-java-1.0
Algorithms with-java-1.0Algorithms with-java-1.0
Algorithms with-java-1.0
 
ECE-PYTHON.docx
ECE-PYTHON.docxECE-PYTHON.docx
ECE-PYTHON.docx
 
L25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxL25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptx
 
Programs.doc
Programs.docPrograms.doc
Programs.doc
 
AI-Programs.pdf
AI-Programs.pdfAI-Programs.pdf
AI-Programs.pdf
 
New microsoft office word document (2)
New microsoft office word document (2)New microsoft office word document (2)
New microsoft office word document (2)
 
C++ Course - Lesson 2
C++ Course - Lesson 2C++ Course - Lesson 2
C++ Course - Lesson 2
 
how to reuse code
how to reuse codehow to reuse code
how to reuse code
 
python practicals-solution-2019-20-class-xii.pdf
python practicals-solution-2019-20-class-xii.pdfpython practicals-solution-2019-20-class-xii.pdf
python practicals-solution-2019-20-class-xii.pdf
 
Anjalisoorej imca133 assignment
Anjalisoorej imca133 assignmentAnjalisoorej imca133 assignment
Anjalisoorej imca133 assignment
 
Lecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptxLecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptx
 
Lecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptxLecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptx
 
CSE240 Pointers
CSE240 PointersCSE240 Pointers
CSE240 Pointers
 
EXPT1.pptx
EXPT1.pptxEXPT1.pptx
EXPT1.pptx
 
Array Cont
Array ContArray Cont
Array Cont
 
Elegant Solutions for Everyday Python Problems Pycon 2018 - Nina Zakharenko
Elegant Solutions for Everyday Python Problems Pycon 2018 - Nina ZakharenkoElegant Solutions for Everyday Python Problems Pycon 2018 - Nina Zakharenko
Elegant Solutions for Everyday Python Problems Pycon 2018 - Nina Zakharenko
 
Python program For O level Practical
Python program For O level Practical Python program For O level Practical
Python program For O level Practical
 
python file for easy way practicle programs
python file for easy way practicle programspython file for easy way practicle programs
python file for easy way practicle programs
 

Recently uploaded

CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
karthi keyan
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERSCW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
veerababupersonal22
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
zwunae
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
VENKATESHvenky89705
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
Robbie Edward Sayers
 
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
ssuser7dcef0
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
BrazilAccount1
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
AmarGB2
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
Aditya Rajan Patra
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
Kerry Sado
 
ML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptxML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptx
Vijay Dialani, PhD
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
WENKENLI1
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
manasideore6
 
Unbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptxUnbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptx
ChristineTorrepenida1
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
Divya Somashekar
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 

Recently uploaded (20)

CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERSCW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
 
ML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptxML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptx
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
 
Unbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptxUnbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptx
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 

Presentation 6 (1).pptx

  • 1. DEPARTMENT OF INFORMATION SCIENCE Fibonacci series using pthreads Presented By- ROHAN H RAJ 1BI20IS071 RAKSHITHA S 1BI20IS070 RUDRA MRIGNAK 1BI20IS072 SAGAR GHOSH 1BI20IS073 Faculty In charge: Dr. Hema Jagadish Associate Professor Dept of ISE, BIT, Bangalore BANGALORE INSTITUTE OF TECHNOLOGY
  • 2. Fibonacci program in c pthread  In a Fibonacci series, every number (except the first two numbers) is the sum of the previous two numbers.The mathematical formula for a Fibonacci series is:  F(n) = F(n - 1) + F(n - 2)F(n)=F(n−1)+F(n−2)  Here, F(n) represents the n^{th}nth Fibonacci number.
  • 3.  In Java, we can use different techniques like recursion and memoization to create a Fibonacci series. Let us take a look at a few examples to understand how can we create the Fibonacci series.
  • 4.  Example 1 Fibonacci series using recursion in Java To calculate the Fibonacci series using we need to create a function so that we can perform recursion. This function input. The function checks whether the input number is 0, 1, or 2, and it respectively, if the input is any one of the three numbers. If the input is greater function calls itself recursively for the previous values until the value of the input becomes less than or equal to 2. So if the function receives an integer n as input, the n^th^ Fibonacci number. To print the Fibonacci series we will call this each Fibonacci number.
  • 5. public class FibonacciCalc { public static int fibRecursion(int count) { if (count == 0) { return 0; } if (count == 1 || count == 2) { return 1; }return fibRecursion(count - 1) + fibRecursion(count - 2); } public static void main(String args[]) { int fib_len = 9; System.out.print("Fibonacci Series of " + fib_len + " numbers is: n"); for (int i = 0; i < fib_len; i++) { System.out.print(fibRecursion(i) + " "); } } }
  • 6. Output of the program: Fibonacci Series of 9 numbers is: 0 1 1 2 3 5 8 13 21
  • 7. In the above example, we defined a recursive function fib Recursion to get nth Fibonacci number and call it repeatedly (for i=0 to i=8) in order to create a Fibonacci series of length 9.
  • 8. Implementation in C #include <pthread.h> #include <stdio.h> int fib;/* this data is shared by the thread(s) */ void *runner(void *param); /* the thread */ int main(int argc, char *argv[]) { pthread_t tid; /* the thread identifier */ pthread_attr_t attr; /* set of attributes for the thread */ if (argc != 2) { fprintf(stderr,"usage: a.out <integer value>n"); return -1; } if (atoi(argv[1]) < 0) { fprintf(stderr,"Argument %d must be non-negativen",atoi(argv[1])); return -1; } /* get the default attributes */ pthread_attr_init(&attr); /* create the thread */ pthread_create(&tid,&attr,runner,argv[1]); /* now wait for the thread to exit */ pthread_join(tid,NULL); printf("Fibonacci = %dn",fib); }
  • 9. if (atoi(argv[1]) < 0) { fprintf(stderr,"Argument %d must be non-negativen",atoi(argv[1])); return -1; } /* get the default attributes */ pthread_attr_init(&attr); /* create the thread */ pthread_create(&tid,&attr,runner,argv[1]); /* now wait for the thread to exit */ pthread_join(tid,NULL); printf("Fibonacci = %dn",fib); } void *runner(void *param) { int i, upper = atoi(param); fib= 1; if (upper > 0) { int pre1 = 0; int pre2 = 1; int current ; if (fib == 1)
  • 10. { printf("The Fibonacci sequence for the number you entered is n"); printf("%dn",pre1); exit(0); } else if (fib == 2) { printf("The Fibonacci sequence for the number you entered is n"); printf("%d , %dn",pre1 ,pre2 ); exit(0); } else { int j=3; printf(" nThe Fibonacci sequence for the number you entered is n %d , %d ,",pre1,pre2 ); for(j = 3; j <= fib; j++) { current = pre2 + pre1; pre1 = pre2; pre2 = current; printf(" %d ,",current) } } } pthread_exit(0); } */ ("Foon");
  • 12. Time And Space Complexity The time complexity of the recursive approach to solving the is O(2^n)O(2n) i.e. exponential time. The space complexity of the method is O(n), if we consider the recursive stack. Exponential time complexity is extremely inefficient. It would take calculate the Fibonacci series of a huge length using the recursive solve this problem, we can use the memorization technique to Fibonacci series. This technique is much faster than the recursive
  • 13. CONCLUSIO Here, we have seen how to build the concurrent application for Fibonacci series.