Share this link via
Or copy link
Computers are widely being used in every domain nowadays and in each domain, we have some problems. To Solve the problems of the computer we need to require a program.
A Program consists of two basic components,
Computer science is a field of study that deals with solving a variety of problems by using computers. To solve a given problem by using computers, you need to design an algorithm for it.
Multiple algorithms can be designed to solve a particular problem. An algorithm that provides the maximum efficiency should be used for solving the problem. The efficiency of an algorithm can be improved by using an appropriate data structure. Data structures help in creating programs that are simple, reusable, and easy to maintain. This module will enable a learner to select and implement an appropriate data structure and algorithm to solve a given programming problem.
Variable is a location in the memory. It has a name and contains a value.
Size of the data in the memory.
Type of the data in the memory whether it is character or integer, etc.
A Datatype in a programming language is a set of data with the values having predefined characteristics. System/Compiler defined data type is called a primitive data type. Structure in C/C++ and classes in C++/Java are the means to create our own data types known as user-defined data types.
Data Structure is a particular way of storing and organizing data in a computer so that it can be used efficiently. A data structure is defined as a way of organizing the various data elements into the memory with respect to each other.
Data can be organized in many different ways. Therefore, you can create as many data structures as you want. Some data structures that have proved useful over the years are,
Data structures can be classified under the following two categories:
Example – Array
Example – Linked List
There are two types of data structures,
Note: Efficiency is not the property of the Algorithm.
Ex. sum(n) algorithm to add first n natural numbers. Assume s is a variable initialized to 0.
1) if n<=0 return -1.
2) repeat step 3 and 4 while n!=0.
3) s= s+n
4)[decrement n] n--
5) return s.
The goal of analysis of algorithm is to compare algorthim mainly in terms of running time but also in terms of other factors(like memory, efforts etc.)
1- Rate of Growth
The rate at which the running time increases as a function of i/p is called rate of growth.
Types of Analysis
To analyze the given alogrithm we need to know on what inputs the algo is taking less time and on what inputs the algorithm is taking huge time.
Role of Data Structures
Just a minute
An array is a ___________ data structure, and a linked list is a ____________ data structure.
Eg. Binary Search , Binary Search Tree , Quick Short , Merge Short etc.
Eg. Graphs
Que.The ___________ technique involves selecting the best available option at each step.
Answer:Greedy
Designing Algorithms Using Recursion
Identify the problem in the following algorithm that attempts to find the sum of the first n natural numbers:
Answer:
There is no terminating condition in the given recursive algorithm. Therefore, it will call itself infinitely. The correct algorithm would be:?
Determining the Efficiency of an Algorithm
1. Factors that affect the efficiency of a program include:
2. In addition to these factors, the way data of a program is organized, and the algorithm used to solve the problem also has a significant impact on the efficiencyof a program.