Data Structures and Algorithms in C programming language – coding interviews questions/projects. Linked List, Recursion
How to design better algorithms?
This question is one of the fundamental questions that haunt every programmer. Even software designers want the best algorithms.
But how do we say that one algorithm is better than the other?
Is it not sufficient that the work is done, and the problem is solved?
Not always. Suppose I can solve the problem in 5 years, and somebody else comes with a solution in 5 minutes, who will you prefer? It is not a question of fast computers, but fast algorithms.
The fastness of an algorithm is measured in terms of its complexity. An algorithm with logarithmic time complexity is considered better than an algorithm with polynomial time complexity.
Here the point is, for designing better algorithms, robust data structures are needed. They organize the data in optimal ways and allow access to this data in natural ways.
The most commonly used data structures are arrays, stacks, queues, trees, and linked lists.
They appear in various other applications as primary components.
The study of data structures is a very demanding and challenging field.
Another important thing you should remember is that data structures and algorithms can be thought of independent of languages. That is, you can implement a data structure, or an algorithm in C, C++ or java, subject to the restrictions put forward by that language.
Let us see some of the data structures in a bit more detail.
An array is used to store items of the same type. You can access items randomly. But insertion or deletion from the middle is a problem. Also, you have to know the size of the array in advance.
Linked lists offer a much flexible method of storing and retrieving data. You are free to delete or add anywhere. Also, if you can dynamically add items without knowing the number of items you need in advance. The only disadvantage ii that random access is not possible.
Stacks are implemented using either arrays or linked lists. They allow only the addition and removal of items in the LIFO order. Stacks have many applications, including search algorithms, recursion, and many others.
A Queue is a FIFO structure. Queues are also implemented using arrays or linked lists. Queues allow deletion from one end and addition from others. There are various types of queues, such as circular queues. Double-ended queues, restricted input queues.
Trees are used to organize data hierarchically to facilitate secure deletion and addition.
In short, Data structure is the glue between algorithms and data.