Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Pinterest
Share On Reddit
Share On Stumbleupon
Contact us
Hide Buttons

Check if array is sorted using recursion

Objec­tive:  Given an array of inte­ger write a recur­sive solu­tion to check if array is sorted.


int [] a = {1,2,3,4};
Output: true

int [] a = {1,2,3,4,2};
Output: false

Approach: This prob­lem can eas­ily be solved in sin­gle iter­a­tion by just com­par­ing adja­cent ele­ments. Fun part is to write the recur­sive solu­tion. Code is self explanatory.




You may also like...