This chapter will introduce you to what they are and help you build the base for the future.
In order to do that, as a programmer you will be writing a computer program to get that job done. You will provide the computer with step by step instructions to reach that goal. The computer then executes the instructions in the same manner that you provided it. That basic
technique of getting the job done can be summarized as an algorithm.
In general terms,
An algorithm is a sequence of clearly defined instructions for solving a problem.
Lets understand the term in a more simpler way…
Friends bike algorithm
- Ask your friend to give you a ride
- Get in the bike
- Reach home in about 4 minutes
- Promise to buy him a beer next time
Grab a taxi algorithm
- Get to the taxi stand
- Find a taxi
- Get in the taxi
- Reach home in about 7 minutes
- Pay the taxi guy
The bus algorithm
- Go to the bus stand
- Wait for the bus
- Get in the bus
- Get off near your street in about 14 minutes
- Walk 2 minutes to reach home
Even though there were multiple options to choose from, the best one was to choose your friends bike. If we take a look back to the options you had, we will notice a few things :
- Each had a finite number of steps
- All three had the same goal (to take you home)
- Each had its own cost
- Each had its own travel time
Algorithms in programming world are similar to these 3 options. In case of programming, there might be even more options.
In the programming world, Algorithm would look something like this.
Problem : Design an algorithm to multiply two numbers and display the result.
Step 1 : START Step 2 : Declare three integers a,b & c Step 3 : Define values of a & b Step 4 : Multiple values of a & b Step 5 : Store the output of step 4 to c Step 6 : Print the result c Step 7 : STOP
Some of the most common algorithm categories in terms of data structure are –
- Search – to search for items in a data structure
- Sorting – to sort a list of items in a certain order
- Insertion – to insert an item in a data structure
- Update – to update an existing item in a data structure
- Delete – to delete an existing item from a data structure
Data Structure is a way of storing and organizing data in a specialized format for a specific purpose such that it can later be accessed and worked with.
Some of the common operations performed in a data structure are insertion, deletion, sorting, searching, traversing etc.
Generally, accessing, maintaining and manipulating data stored in a data structure is done my using various algorithms. That is one of the reasons why Algorithm and Data Structures are so closely related.
All programming languages make use of data structures to store data. Some of the most common ones are array, stack, queue, list and dictionary.
Choosing a data structure to store data largely depends on the amount of data that needs to be stored and the frequency of the operation that needs to be performed on it.
You must have a deep understanding of different kinds of algorithms and data structures in use today if you wish to become a good programmer. Because most of the time, you will be dealing with all kinds of data from text files, API`s and databases.
There are tons of resources and tutorials online to teach you all about these two concepts. You don`t need to master them all at once, but at least be familiar with how they work and where they are generally used.
Lets move on to next topic and get familiar with the paradigms and concepts that defines various programming languages.