Can you answer my Java question plz?
write a method that takes a sorted integer array, sorted, and an integer, k, and returns the index of where the integer is located or -1 if the integer is not in the array.
- brilliant_movesLv 72 months agoFavorite Answer
Hi, Don. With a sorted array, you can perform a sequential search (easy to implement but relatively slow), or if the size of the array is large, a binary search is more efficient. Googling "Java binary search" should come up with the code you're after.
- SnezzyLv 72 months ago
Because the array is sorted an appropriate algorithm is obvious. If it is not obvious to you, read your textbook or your class notes.
If you fell asleep in class the day they covered searching and sorting, then get Volume 3 of Donald Knuth's book, "The Art of Computer Programming." Drop the class and read the book instead. Do ALL the exercises.
- keerokLv 72 months ago
You're not asking a question. You're asking us to do your homework for you. Not cool.