Starting from:
$30

$24

Lab 0601 Solution

1. Problem Statement




Create a recursive function that performs a linear search within an array. Eventually, scale up the array to cause a stack overflow.




2. Requirements




2.1 Assumptions




User will only input integers



User will only input into the command line



2.2 Specifications




User will input key to search for



Program will alert when found



Program will alert how many function calls existed



Decomposition Diagram



Program



Input



Take in User Key



Process



Recursively Compare Key to Data



Output



Data Found after X calls



Not Found



Test Strategy



Valid Data



Invalid Data



Test Plan Version 1






Test Strategy
#
Description
Input
Expected Output
Actual Output
Pass/Fail














Valid Data
1
Key within bounds






















Invalid Data
1
Key out of bounds






















Invalid Data
2
Key out of bounds






















Invalid Data
3
Cause Overflow































Initial Algorithm



Create Function



Name: recursiveLinearSearch



Parameters: integer array, integer key, integer size, bool methodStatus



Return: recursiveLinearSearch



Method



Decrement Size for next use



If key larger than size



Return -1



Else If key matches array index @ size



Set methodStatus to true



Return Global SIZE minus current size/function call



Else



Return calling recursiveLinearSearch



Create Main



Declare Global SIZE as 5000



Declare bool methodStatus as false



Declare integer recusiveCalss as 0



Declare integer key as 0



Declare integer Array with size of SIZE



Fill Array with 0 to SIZE - 1



Prompt user for new key



Perform recursiveLinearSearch with key



If methodStatus after call is true



Alert Key found after number of recursiveCalls



Else



Alert Key was not found.



7. Test Plan Version 2







Test Strategy
#
Description
Input
Expected Output
Actual Output
Pass/Fail














Valid Data
1
Key within bounds
1234
Found after 3766












calls


















Invalid Data
1
Key out of bounds
-1
Key not found


















Invalid Data
2
Key out of bounds
5001
Key not found


















Invalid Data
3
Cause Overflow
Array SIZE
Stack Overflow
























9. Updated Algorithm




Create Function



a. Name: recursiveLinearSearch

Parameters: integer array, integer key, integer size, bool methodStatus



Return: recursiveLinearSearch



Method



Decrement Size for next use



If key larger than size



If key is not within bounds



Return -1



Else If key matches array index @ size



Set methodStatus to true



Return Global SIZE minus current size/function call



Else



Return calling recursiveLinearSearch



Create Main



Declare Global SIZE as 5000



Declare bool methodStatus as false



Declare integer recusiveCalss as 0



Declare integer key as 0



Declare integer Array with size of SIZE



Fill Array with 0 to SIZE - 1



Prompt user for new key



Perform recursiveLinearSearch with key



If methodStatus after call is true



Alert Key found after number of recursiveCalls



Else

More products