Introduction to Algorithms and Data Structures

Definitions of Algorithms and Data Structures

Algorithms and data structures are closely related concepts in computer science. They are both important concepts in computer science, and understanding their relationship is crucial for developing efficient and effective software.

An algorithm may be loosely defined as a process, procedure, method or recipe. The word algorithm originates from the Arabic word algorism, which is linked to the name of the Arabic mathematician Abu Jafar Mohammed Ibn Musa Al Khwarizmi (825 CE).

In the field of computer science, an algorithm may be better defined as a finite sequence of instructions, each of which has a clear meaning and can be performed with a finite amount of effort in a finite length of time.

Data structures deal with the study of methods, techniques and tools to organize or structure data.

Structure and Properties of Algorithm

This is the structure of an algorithm:

  1. input step;
  2. assignment step;
  3. decision step;
  4. repetitive step;
  5. output step.

The following are the properties of algorithm:

  1. Finiteness: an algorithm must terminate after a finite number of steps.
  2. Definiteness: the steps of the algorithm must be precisely defined or unambiguously specified.
  3. Generality: an algorithm must be generic enough to solve all problems of a particular class.
  4. Effectiveness: the operations of the algorithm must be basic enough to be put down on pencil and paper. They should not be too complex to warrant writing another algorithm for the operation!
  5. Input‒output: the algorithm must have certain initial and precise inputs, and outputs that may be generated both at its intermediate or final steps.

Flowcharts & Programs

An algorithm may be represented using pictorial representations such as flow charts. An algorithm encoded in a programming language for implementation on a computer is called a program.

Development of An Algorithm

In the development of an algorithm, the following 8 steps are involved :

  1. problem statement – a clear statement of the problem is made.
  2. model formulation – model for the solution of the problem is formulated.
  3. algorithm design – design the algorithm based on the solution model formulated. It is here that one sees the role of data structures. The right choice of the data structure needs to be made at the design stage itself since data structures influence the efficiency of the algorithm.
  4. algorithm correctness; check correctness.
  5. implementation; implement algorithm.
  6. algorithm analysis; measure the performance – most important step.
  7. program testing; program is tested.
  8. documentation. – development ends with proper documentation.

For the design of efficient programs for the solution of problems, it is essential that algorithm design goes hand in hand with appropriate data structures.

Definition and Classification of Data Structures

Abstract Data Types

A data type refers to the type of values that variables in a programming language hold. Thus, the integer, real, character and Boolean data types that are inherently provided in programming languages are referred to as primitive data types.

A list of elements is called a data object. For example, we could have a list of integers or a list of alphabetical strings as data objects.

The data objects that comprise the data structure and their fundamental operations are known as abstract data types (ADTs). In other words, an ADT is defined as a set of data objects D defined over a domain L and supporting a list ofoperations O.

Classification of data structures

The data structures are broadly classified as linear data structures and nonlinear data structures. Linear data structures are uni-dimensional in structure and represent linear lists. These are further classified as sequential and linked representations. On the other hand, nonlinear data structures are two-dimensional representations of data lists. The individual data structures listed under each class are shown in the figure below.

algorithms and data structures

Algorithm Design Techniques

Algorithm design concerns strategic methods that strive to find effective solutions or efficient solutions to large classes of problems.

Brute force or exhaustive search

This method of solving a problem: working over all possible combinations of input sequences, one or more of which may lead to the solution of the problem. Brute force methods, therefore, do not explore ways and means to strategically solve the problem by exploiting the problem characteristics or the data structure that describes the problem.

For example, a brute force method to find an element in a list would involve merely sequentially searching for the element, one by one, until the element is found or not found. A strategic method, on the other hand, would try to explore ways and means by which finding the element can be done efficiently without searching the entire list or minimizing the number of comparisons during the search and so on.

Several algorithm design techniques have been identified to solve various classes of problems. The following are some of them:

  1. divide and conquer; (popular)
  2. greedy method; (popular)
  3. dynamic programming (popular)
  4. backtracking;
  5. branch and bound;
  6. local search;
  7. randomized algorithms.

Problem classes that do not yield effective solutions, no matter which algorithm design technique is employed.

NP-complete and NP-hard, where Comprar cialis generico barato en españa NP denotes non-deterministic polynomial. A non-deterministic polynomial simply means that efficient algorithms are not available to solve them.

A class of algorithms known as approximation algorithms have emerged, which aim to solve specific problem instances through heuristics that strive to deliver solutions to the problem instances within a reasonable amount of time. Heuristics involve methods that are intuitive and help to attain near-optimal or acceptable solutions.

Summary of Section 1 of Algorithms and Data Structures

Data structures are classified as linear and nonlinear data structures. Linear data structures are further classified as sequential and linked data structures. While arrays, stacks and queues are examples of sequential data structures, linked lists, linked stacks and queues are examples of linked data structures.

The nonlinear data structures include trees and graphs.

The tree data structure includes variants such as binary search trees, AVL trees, B trees, tries, red–black trees and splay trees.

Algorithm design concerns strategic methods to solve problems efficiently.

Divide and conquer, greedy method and dynamic programming are popular algorithm design strategies.

Analysis of Algorithms

Efficiency of Algorithms

The performance of algorithms can be measured on the scales of time and space.

Time complexity of an algorithm

Here, we are looking for the fastest algorithm for the problem or that which performs its task in the minimum possible time. It is a function of the running time of the algorithm or program.

Space complexity of an algorithm

This means looking for an algorithm that consumes or needs limited memory space for its execution. This performance measure is termed space complexity. The space complexity of an algorithm or a program is a function of the space needed by the algorithm or program to run to completion.

How to compute time complexity

The time complexity of an algorithm can be computed either by an empirical or theoretical approach.

The empirical or posteriori testing approach calls for implementing the complete algorithms and executing them on a computer for various instances of the problem. The time taken by the execution of the programs for various instances of the problem are noted and compared. The algorithm whose implementation yields the least time is considered to be the best among the candidate solutions.

The theoretical or apriori approach calls for mathematically determining the resources such as time and space needed by the algorithm as a function of a parameter related to the instances of the problem considered. A parameter that is often used is the size of the input instances.

For example, for the problem of searching for a name in the telephone directory, an apriori approach could determine the efficiency of the algorithm used in terms of the size of the telephone directory, that is, the number of subscribers listed in the directory.

The disadvantage of posteriori testing is that it is dependent on various other factors, such as the machine on which the program is executed, the programming language with which it is implemented and why, even on the skill of the programmer who writes the program code! On the other hand, the advantage of apriori analysis is that it is entirely machine, language and program independent.

Leave a Comment

Sign up to our newsletter!