data structure homework
DESCRIPTION
homework for data structureTRANSCRIPT
Assignment/Homework #1 COP-3530, Fall 2015
Instructor: Dr. Antonio L. Bajuelos
Rules & Instructions:
This assignment has 3 problems.
Due date: Thursday, September 10th, 2015 at 4 pm (Eastern Time)
The assignment/homework will be submitted by email to [email protected]
Your submission must be a ZIP file (not RAR format). Please name your submission
as 1_xxxxxxx.zip, where xxxxxxx is your seven digit Panther ID number).
Please indicate in the subject of your email message the following information:
COP-3530, SECTION U02, ASSIGNMENT #1
Please include the following header in every Java program:
/*******************************************************
Program Number: A1_<problem # (ranging from 1 to 2) >
Purpose/Description: <a brief description of the program>
Author: <your name>
Due date: <mm/dd/yy>
Certification:
I hereby certify that this work is my own and none of it is the work of
any other person.
< your full name >
*******************************************************/
Submissions turned in after the due date and/or which don’t meet the
established formatting rules will not be accepted.
Problem #1.
The Fibonacci sequence {fib}i≥1 is defined recursively as follows:
fib(1) = fib(2) = 1 and, fib(n) = fib(n-1) + fib(n-2) for n ≥ 3.
The numbers in the Fibonacci sequence are called the Fibonacci numbers, for example:
{1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233…}
Implement a sub-linear time complexity function in Java
int fib(int n)
that returns the nth Fibonacci number.
Problem #2.
(a) Implement a recursive search function in Java
int terSearch(int arr[], int l, int r, int x)
that returns location of x in a given array arr[l…r] if x is present, otherwise -1.
The terSearch search function, unlike the binary search, must consider two dividing points
int d1 = l + (r - l)/3
int d2 = d1 + (r - l)/3
(b) What is the running time complexity of your function? Justify.
Problem #3.
The input is an N by N matrix of nonnegative integers that is already in memory. Each
individual row is increasing from left to right. Each individual column is increasing from top to
bottom. Propose an O(N) wort-case algorithm that decides if a number x is in the matrix.