Glimpse of Data Structures and Algorithms for Freshmen!
Data structures play an essential role in solving problems. An algorithm is a step-by-step method to solve a problem. In Computer Science, we use algorithms and data structures to solve tasks. By using the appropriate data structure, a program can be executed efficiently. This is because data structures provide efficient ways to store, organize, and access data.
There are two different types of data structures, linear and non-linear data structures. Linear data structures are arranged one after the other as they are one-dimensional. Meanwhile, non-linear data structures are arranged hierarchically, which means that they have multiple branches and different layers.
The array is one example of a linear data structure. All the data in an array share the same data type and each data has its own index. Another linear data structure is a stack. A stack has the LIFO, last in first out principle which means that the first data that gets into the stack will come out last. Meanwhile, the data that gets inserted last will come out first. There is also the queue data structure that uses the FIFO principle, first in first out. It is exactly the same as any queue in real life with the first data coming out first and the last data coming out last. Next is a linked list. In a linked list, data are connected by a series of nodes. Each data has a pointer that points to the next node storing the next data. Each node has the data and a pointer.
Examples of nonlinear data structures are graphs and trees. A graph has vertices and edges that will create a connected graph of vertices that links the data to each other. Graphs are more likely to be used to solve complicated problems that search for a path, cycle, etc. Meanwhile, the tree has a hierarchical structure and the topmost node is called the root node. This root node has the first element that will be used as an anchor.
To know which data structure matches a certain problem, first, we have to understand the problem. An example will be a fast food counter. The customer will go up to the counter and order some food and the restaurant has to deliver the right food and information to the right customer. In this case, we can use the queue data structure. Since the order will be in a line and we can assume that people are not cutting the line, it serves one person at a time and operates on a first come first serve basis, just like the FIFO principle. From this example, we can pay attention to the input and output. Then we also have to consider the functions or methods needed in the process. Finally, we can see which data structure matches the most.
Understanding data structures is important to creating an efficient algorithm. By choosing the suitable data structure, memory and time can be reduced, resulting in an efficient piece of algorithm.
References
- https://stackoverflow.com/questions/54466641/examples-of-data-structures-in-real-life
- https://opendsa-server.cs.vt.edu/ODSA/Books/Everything/html/IntroDSA.html
- https://www.programiz.com/dsa/data-structure-types
- https://www.geeksforgeeks.org/what-is-data-structure-types-classifications-and-applications/
- https://www.freecodecamp.org/news/the-top-data-structures-you-should-know-for-your-next-coding-interview-36af0831f5e3/
- Writer: Stephanie Staniswinata