From 7668d1c4192d23b305f611df9ce2aed2d5be50c4 Mon Sep 17 00:00:00 2001 From: Christian Bender Date: Tue, 20 Mar 2018 16:39:13 +0100 Subject: [PATCH] Added some header files and changed the min() function --- Searches/fibonacciSearch | Bin 0 -> 8720 bytes Searches/fibonacciSearch.c | 23 ++++++++++++++--------- Searches/fibonacciSearch.o | Bin 0 -> 2152 bytes 3 files changed, 14 insertions(+), 9 deletions(-) create mode 100755 Searches/fibonacciSearch create mode 100644 Searches/fibonacciSearch.o diff --git a/Searches/fibonacciSearch b/Searches/fibonacciSearch new file mode 100755 index 0000000000000000000000000000000000000000..fba247bda442221dd347e87bf38e4d572d900881 GIT binary patch literal 8720 zcmeHMeQZlPl4?Ia$Fo!QSU zpwV>-pcyZ1q)l7?S&Q}|t*ff7)wbr3YJ>)GDpix2=!UdT3J9vCp<7Th6loOiocr$a z$BQGON&90GNAf%O{O&pDo_pW9_uYH_UAd*nY%(z-Gy4)l>0F+~A^pi%+h#5btd6Z> z65GliV+DZZ!%yNh$n_HOCE=QQkQPg?M zDqSSbn4JS?hq2nMTm*iE7l=Dkap?7AhcMce3%hb*M?4_{BToIpzTvM^`0X@HAfYTF zV~zZo=BSI*c1!bOd8v?#z$IQFzE_7CakBdg*kPOxN;aX`F4|jZToy$ChzpVJ9Pszl zR_`3}Rt)$9k>QHry4s4`YDYNesN(%b|ERnFU>9$R#?cNE#=IVWm;+dEiQaf)`W1QR zm0zse{e0zXU;gVv-;-!dKPWyhtpUx_9NL&ix$w`gfY$(Shu<=SetWQ+wM`ZIe|c#?Fcf4>4g4>>>0R7QC?M^ zfm1A4p^V%vQeyd+*4UYHdQ!`u?cm_WqA6~cdL(P!1eN6W-@&tZs{|#K`>}p*CJD6t z*C=Bsa|tg03}p;qZj#GAAoq@;0aE41&Cx4|mFNv+@|H2pNR@)hilyrgNYybl5 zzMTITfJ~q8md@K@0Z~Twu}J>>55X?w><$_v6Wwzszy`}o^yIZ@D*~BkI9MAwq&ezDJI`GP49lE z_~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], int x, int n) { /* Initialize fibonacci numbers */ int fibMMm2 = 0; // (m-2)'th Fibonacci No. int fibMMm1 = 1; // (m-1)'th Fibonacci No. int fibM = fibMMm2 + fibMMm1; // m'th Fibonacci - + /* fibM is going to store the smallest Fibonacci Number greater than or equal to n */ while (fibM < n) @@ -13,18 +16,20 @@ int fibMonaccianSearch(int arr[], int x, int n) fibMMm1 = fibM; fibM = fibMMm2 + fibMMm1; } - + // Marks the eliminated range from front int offset = -1; - + /* while there are elements to be inspected. Note that we compare arr[fibMm2] with x. When fibM becomes 1, fibMm2 becomes 0 */ while (fibM > 1) { // Check if fibMm2 is a valid location - int i = min(offset+fibMMm2, n-1); - + + // sets i to the min. of (offset+fibMMm2) and (n-1) + int i = ((offset+fibMMm2) < (n-1)) ? (offset+fibMMm2) : (n-1); + /* If x is greater than the value at index fibMm2, cut the subarray array from offset to i */ if (arr[i] < x) @@ -34,7 +39,7 @@ int fibMonaccianSearch(int arr[], int x, int n) fibMMm2 = fibM - fibMMm1; offset = i; } - + /* If x is greater than the value at index fibMm2, cut the subarray after i+1 */ else if (arr[i] > x) @@ -43,14 +48,14 @@ int fibMonaccianSearch(int arr[], int x, int n) fibMMm1 = fibMMm1 - fibMMm2; fibMMm2 = fibM - fibMMm1; } - + /* element found. return index */ else return i; } - + /* comparing the last element with x */ if(fibMMm1 && arr[offset+1]==x)return offset+1; - + /*element not found. return -1 */ return -1; } diff --git a/Searches/fibonacciSearch.o b/Searches/fibonacciSearch.o new file mode 100644 index 0000000000000000000000000000000000000000..905137626f2a711ce15b5196cc5486d39d6496f6 GIT binary patch literal 2152 zcmbtUPe>GD6o2DpX<3;?1r;nrWthXR*_IWtC7;eA!;B>fVjFi?Tx@4+odt`w4pJ}- zlE=Dr4ua_9L1@Wn3nKR5!9$0F0%JWG?7@Rz?|t)q_%TeEdh+>u-|zjMH*fY4yWH2H zX&^;|3$SsMEI@nXh92i?9Ja$&NEpsf!znE~#RVr(t*~XXRoDvUa1+ZeYE_5TYx_`h z7~bm+TTu*1oMY7o-z#i&9p%?!ieuI3!F6|F)n&`t$DVgPue@{En#Tr+U8Y2#!I@5^rFhEMZ-`J$B$n|3&Br8ARf!$+`0e{b*EaC>5;XxYW^DZN{d zbjFJO7JV3v>5*=|=eWm*yCTt8Bo^tRQY3pk0PX$|Xp^nlftD>zGq@B7k*7nlkCx=( zj@Bm)z1ug3+B9_Gw)5Ny@P<&@8(xw5uR^Id!SD4Thfv@~1BCD|NJ5w?NJ5}|1d2ll zwkWp^H3Y#8hhX!DlhAe}wkdt`*&ugR@bb=Qf?NllRy=;8-3j7hG&_>F%v36SEn^l^ zV|t310go~*kA$3=wct)6YuTfaOitKlYCM@58&8g!+1p;F=QL=P20YDp)@a{RUI?Dn zTbYcsM4tLgu!q+nGrl^t5T4 zppQ&UfL_RZmsCEN%UEc$@^(h=zmn+W&x;NemKjTq7R+2m*8g7&V*+|)|C^5^NAgL` z!@GIDQYSoshqf|~N0o?J)mwt38B;2`dHV%Vdqli{muIoJ}ih~H7V+H{*tC& z@u2rNBi^5UE_#0yE92$++l8Ee_DDfl#G7YeAk70rV}>ckQoFTu}Wb LLH43u6@UFdsb4+e literal 0 HcmV?d00001