5. A range function similar to the range function in Python. For example, range (2,12,3) returns the list [2,5,8,11], and range(20, 2, -3) yields [20, 17, 14, 11, 8, 5] 6. A slice function, with functionality similar to the Python list slice operator. For example, slice ([11,22,3,14,5,6], 1, 4) returns the list [22,3,14]. Assume that the indices specified are valid for the list. Hint: Write a helper function nthElement that returns the element at a specified (0-based) index in a list. For example, nthElement([10, 2, 34, 20], 2) returns 34, the element at index 2. 7. A binarySearch function that recursively implements the binary search algorithm to search a sorted integer list for a specified integer and returns true if it is found, false otherwise. For example, binarySearch ([100,200, 300, 400, 500], 200) returns true, whereas binary Search ([100,200, 300, 400, 500], 299) returns false. Hint: Write a helper function mid that returns a tuple (index, value) representing the middle value in a list. For example, mid [10, 2, 40, 8, 22] returns (2,40) because the value 40 at index 2 is the middle value in the list. Similarly, mid [10, 20] would return (1, 20). Use mid in conjunction with slice to implement binarySearch.
5. A range function similar to the range function in Python. For example, range (2,12,3) returns the list [2,5,8,11], and range(20, 2, -3) yields [20, 17, 14, 11, 8, 5] 6. A slice function, with functionality similar to the Python list slice operator. For example, slice ([11,22,3,14,5,6], 1, 4) returns the list [22,3,14]. Assume that the indices specified are valid for the list. Hint: Write a helper function nthElement that returns the element at a specified (0-based) index in a list. For example, nthElement([10, 2, 34, 20], 2) returns 34, the element at index 2. 7. A binarySearch function that recursively implements the binary search algorithm to search a sorted integer list for a specified integer and returns true if it is found, false otherwise. For example, binarySearch ([100,200, 300, 400, 500], 200) returns true, whereas binary Search ([100,200, 300, 400, 500], 299) returns false. Hint: Write a helper function mid that returns a tuple (index, value) representing the middle value in a list. For example, mid [10, 2, 40, 8, 22] returns (2,40) because the value 40 at index 2 is the middle value in the list. Similarly, mid [10, 20] would return (1, 20). Use mid in conjunction with slice to implement binarySearch.
C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter7: Arrays
Section7.5: Case Studies
Problem 3E
Related questions
Question
Code in sml language using pattern matching
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 1 steps
Recommended textbooks for you
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning