Finding word in a two dimensional array

  • Thread starter rambo3131
  • Start date
  • Tags
    Array
In summary, a two dimensional array is a data structure that stores values in a grid-like fashion, with rows and columns. To search for a specific word in a two dimensional array, you can loop through each element and compare it to the target word. The time complexity of finding a word in a two dimensional array is O(n^2) and any programming language that supports two dimensional arrays can be used for this task. However, more efficient algorithms such as binary search or hash tables can also be used.
  • #1
rambo3131
18
0
Hi, I have a question about C.In a two dimensional array ,I will search a word (not a letter).Do i have to use pointers?
 
Technology news on Phys.org
  • #2
rambo3131 said:
Hi, I have a question about C.In a two dimensional array ,I will search a word (not a letter).Do i have to use pointers?
No, you can use array indexes in two nested for loops. Note that you will need to use a string comparison function (strcmp) rather than a condition like this one:
if(str == "abc")
 

What is a two dimensional array?

A two dimensional array is a data structure that stores values in a grid-like fashion, with rows and columns. It can be thought of as a table or matrix, where each element is identified by its row and column index.

How can I search for a specific word in a two dimensional array?

To find a specific word in a two dimensional array, you can loop through each element and compare it to the target word. If a match is found, you can return the index of the element or the entire element itself.

What is the time complexity of finding a word in a two dimensional array?

The time complexity of finding a word in a two dimensional array is O(n^2) in the worst case scenario, where n is the length of the array. This is because you would need to iterate through each element in the array to search for the word.

Can I use any programming language to find a word in a two dimensional array?

Yes, you can use any programming language that supports two dimensional arrays to find a word in a two dimensional array. The approach may vary depending on the language, but the basic logic remains the same.

Is there a more efficient way to find a word in a two dimensional array?

Yes, there are more efficient algorithms such as binary search or hash tables that can be used to find a word in a two dimensional array. These algorithms have a lower time complexity, but may require a more complex implementation.

Similar threads

Replies
7
Views
623
  • Programming and Computer Science
Replies
32
Views
2K
  • Programming and Computer Science
Replies
1
Views
414
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
6
Views
788
  • Programming and Computer Science
Replies
4
Views
2K
  • Programming and Computer Science
Replies
4
Views
4K
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
25
Views
1K
  • Programming and Computer Science
Replies
23
Views
1K
Back
Top