3
I’m trying to solve the following problem:
Create a graphical representation by illustrating ALL steps (where the start, middle and end) of the search for the value element 57 of the following list:
12,13,15,19,24,28,39,57,59,63,67,69,74
I’m doing it, but I don’t know how to continue!
So far, I’ve done the following step-by-step tracking:
- In the initial interval, I have
início
the 12, in themeio
the 39 and in thefim
the 74. The calculation to locate the central element was this:(início + fim) / 2
, where:início = 0
fim = 12
- Therefore,
meio = (0 + 12) / 2= 12 / 2 = 6
, then 6 is the position of the vector’s central element.
- I divided the list again from the posterior element to the one in the middle, because the sought is larger than the one in the middle, and now item 57 is
início
.
How to continue? Where will the next medium be?
@Anderson: Are you trying to implement a binary search? Look at this: Binary search - wikipeda... has several examples
– Miguel Angelo
@Anderson, welcome to [en.so]! I feel your difficulty in trying to ask questions, with someone who started here today in the OS community. I apologize if anything has ever offended you, but I also ask you to understand that so far it has been difficult to understand exactly what you are in need of. For example, in this question, you had not made it clear which algorithm was being used. I might imply that you want to represent step-by-step a binary search, but see that it took a lot.
– utluiz
I took the liberty of editing your question so that it becomes clearer. I hope this helps you understand how to do the same. I hope you keep asking questions and enjoy the help of the community, but always try to be as clear as possible, format well what you write using paragraphs, topics and a more formal language. Hug!
– utluiz