Data Structure and Algorithm
  • Data Structure and Algorithm

About the Product

Data Structure and Algorithm (Grade A+)

Summary:

This article explains the basics of algorithms and data structures used in computer programming. An algorithm is a set of instructions that solves a specific problem, takes inputs and produces the desired output. Good algorithms should have clear and unambiguous steps, defined inputs and outputs, and should be effective in various ways of solving a problem. There are different types of algorithms, including Brute Force, Recursive, Divide and Conquer, Dynamic Programming, Greedy, Backtracking, Randomized, Sorting, Searching and Hashing. Brute Force is the simplest and most straightforward approach to a problem, while Recursive solves it by breaking it into subproblems of the same type. Divide and Conquer solves a problem in two sections, while Dynamic Programming stores previously calculated results to avoid calculating them again. Greedy builds a solution part by part, and Backtracking solves a problem incrementally. Randomized uses random numbers to decide the expected outcome. Sorting arranges data efficiently while Searching finds a specific key in particular data. Hashing assigns a key to specific data.

Excerpt:

Data Structure and Algorithm

What is an Algorithm?

In computer programming terms, an algorithm is a set of well-defined instructions to solve a particular problem. It takes a set of input(s) and produces the desired output. For example,

An algorithm to add two numbers:

  1. Take two number inputs
  2. Add numbers using the + operator
  3. Display the result

Qualities of a Good Algorithm

  • Input and output should be defined precisely.
  • Each step in the algorithm should be clear and unambiguous.
  • Algorithms should be the most effective among many different ways to solve a problem.
  • An algorithm shouldn’t include computer code. Instead, the algorithm should be written in such a way that it can be used in different programming languages.

Algorithm 1: Add two numbers entered by the user

Step 1. Start

Step 2. Declare variables num1, num2 and sum.

Step 3. Read values num1 and num2.

Step 4. Add num1 and num2 and assign the result to the sum.

Sum <- num1 + num2

Step 5. Display sum.

Step 6. Stop.