LoginLogin

Array Element Finding?

Root / Programming Questions / [.]

MochaProbablyCreated:
How would i be able to go through an array and only go to a certain specified element? Say i want to find all the 3s in a large array, if i could go straight to each 3 in chronological order in the array would be far faster than looping through the array and checking if its that element. (I’m working with a 2D array)

what is a 2D array?

what is a 2D array?
A one Dimensional array looks like ARRAY[10]. It holds 11 elements, including 0. Each element is kind of like its own variable. Say ARRAY[2] = 5 and ARRAY[3] = 9. And 2 dimensional array is like a combination lock and looks like this ARRAY[10,15]. It holds 10*15 elements. Say ARRAY[4,8] = 10 and ARRAY[5,8] = 4.

remove kebab
A one Dimensional array looks like ARRAY[10]. It holds 11 elements, including 0. Each element is kind of like its own variable. Say ARRAY[2] = 5 and ARRAY[3] = 9. And 2 dimensional array is like a combination lock and looks like this ARRAY[10,15]. It holds 10*15 elements. Say ARRAY[4,8] = 10 and ARRAY[5,8] = 4.
can i make a 3,000,000,000,000,000D array? Edit 1:REMOVE KEBAB edit II:these edit things and changed 3 billion D array to a 3 quadrillionD array

remove kebab
A one Dimensional array looks like ARRAY[10]. It holds 11 elements, including 0. Each element is kind of like its own variable. Say ARRAY[2] = 5 and ARRAY[3] = 9. And 2 dimensional array is like a combination lock and looks like this ARRAY[10,15]. It holds 10*15 elements. Say ARRAY[4,8] = 10 and ARRAY[5,8] = 4.
can i make a 3,000,000,000D array?
No you cannot, in SB it only goes up to 4.

what is a 2D array?
An array with two dimensions. Instead of a list of values, it's now a grid of values. A three dimensional array is a cube of values. A four dimensional array is fear. Also, please search if questions have already been answered before you ask them. now to answer the actual question Unfortunately, I think your best bet is to just iterate through an entire array. There aren't any algorithms or programming tricks to search faster than that.

-snip- A four dimensional array is fear.-snip-
i'm sorry what

what is a 2D array?
An array with two dimensions. Instead of a list of values, it's now a grid of values. A three dimensional array is a cube of values. A four dimensional array is fear. Also, please search if questions have already been answered before you ask them. now to answer the actual question Unfortunately, I think your best bet is to just iterate through an entire array. There aren't any algorithms or programming tricks to search faster than that.
Aww really? That’s a bit disappointing. Hmm well im not going lose hope yet.

Next person who uses remove kebab in a quote gets removed from the site

Next person who uses remove kebab in a quote gets removed from the site
Thank you so much.

Next person who uses remove kebab in a quote gets removed from the site

An option is to create an index to store all the references of a value in the array. You must update the structure after each change over the array. However, If you have a lot of insertions or updates over that array, then it won't be useful since you'll losing time updating that structure. Example: https://en.wikipedia.org/wiki/Self-balancing_binary_search_tree Edit: By the way, what are you storing on that array?

An option is to create an index to store all the references of a value in the array. You must update the structure after each change over the array. However, If you have a lot of insertions or updates over that array, then it won't be useful since you'll losing time updating that structure. Example: https://en.wikipedia.org/wiki/Self-balancing_binary_search_tree Edit: By the way, what are you storing on that array?
BG Tile IDs

stop
why

what is a 2D array?
An array with two dimensions. Instead of a list of values, it's now a grid of values. A three dimensional array is a cube of values. A four dimensional array is fear. Also, please search if questions have already been answered before you ask them. now to answer the actual question Unfortunately, I think your best bet is to just iterate through an entire array. There aren't any algorithms or programming tricks to search faster than that.
Aww really? That’s a bit disappointing. Hmm well im not going lose hope yet.
Actually maybe not? If i had a function that took the position of a specified element in a 2D array and stored those into an Array, i could just input the recorded positions to what i need, but would that work? So maybe i could have a 1 dimsional record array and have it be as big as the number of recorded elements, and each element would hold a X, Y, and ID number stored in a RGB varible and read the RGB varibles colors and jump to that spot in the array?

Maybe, but I don't understand how would you jump to a certain position with an RGB value. Here are other options. a. Use the dictionary library made by 12Me21 and store the positions on a string. Example:
DICTSET arr$,"&HF12","(1,2),(3,4)"
? DICGET(arr$,"&HF12")
http://smilebasicsource.com/page?pid=702 b. Store 3 arrays and use binary search 1. Store the tile as ID and the positon as a value on 3 arrays.
VAR ID[0],X[0],Y[0]
2. Keep them sorted by ID.(You can use SORT ID,X,Y) 3. Use binary seach to find the position of the first element with a certain ID and then iterate the array until you find a different ID or reach the end of the array. (Here is an implementation in Python of binary search. It's small and the syntax is almost the same as smilebasic.) https://www.geeksforgeeks.org/binary-search/

Ah yes, ok.I’ll probably use the Dictionary Library for this.

What is this kebab thing anyways? Also searching two 1d arrays would be slower than searching a 2d one right?

What is this kebab thing anyways? -snip-
it's a meme.