DSA 1 (Concept of Data Structures)
DSA 1 (Concept of Data Structures)
DSA 1 (Concept of Data Structures)
To develop a program of an algorithm, we should select an appropriate data structure for that
algorithm. Therefore algorithm and its associated data structures form a program.
A static data structure is one whose capacity is fixed at creation. For example, array. A dynamic data
structure is one whose capacity is variable, so it can expand or contract at any time. For example, linked
list, binary tree etc.
The user of data type does not need to know how that data type is implemented, for example, we have
been using Primitive values like int, float, char data types only with the knowledge that these data type
can operate and be performed on without any idea of how they are implemented. So a user only needs
Compiled by: Er. Sandesh S. Poudel
to know what a data type can do, but not how it will be implemented. Think of ADT as a black box
which hides the inner structure and design of the data type.
For example, when writing application code, we don’t care how strings are represented: we just declare
variables of type String, and manipulate them by using string operations.
Once an abstract data type has been designed, the programmer responsible for implementing that type
is concerned only with choosing a suitable data structure and coding up the methods. On the other hand,
application programmers are concerned only with using that type and calling its methods without
worrying much about how the type is implemented.
Primitive Non-
Data structure Primitive
Data structure
Queue
Graphs
Primitive data structure is a fundamental type of data structure that stores the data of only one type whereas the
non-primitive data structure is a type of data structure which is a user-defined that stores the data of different
types in a single entity
Algorithm:
An algorithm is a precise specification of a sequence of instructions to be carried out in order to
solve a given problem. Each instruction tells what task is to be done. There should be a finite
number of instructions in an algorithm and each instruction should be executed in a finite amount
of time.
Properties of Algorithms:
• Input: A number of quantities are provided to an algorithm initially before the algorithm begins. These
quantities are inputs which are processed by the algorithm.
• Definiteness: Each step must be clear and unambiguous.
Compiled by: Er. Sandesh S. Poudel
• Effectiveness: Each step must be carried out in finite time.
Step 3: Compare Y and Z. if Y is greater than Z then print “Y is greatest” and go to step 7 otherwise
go to step 4
Step 4: Print “Z is greatest” and go to step 7
Step 5: Compare X and Z. if X is greater than Z then print “X is greatest” and go to step 7 otherwise
go to step 6
Step 6: Print “Z is greatest” and go to step 7
Step 7: Stop
Lab work
Write a program using an array to perform the following tasks:(use switch case for menu)
a. Insert element into an array at specified position
b. Delete element from an array
c. Traversing
d. Searching a particular element in the array
#include<stdio.h>
#include<conio.h>
void insert(int [100], int*);
void delet(int [100], int*);
void traverse(int [100], int*);
void searching(int [100], int*);
void main()
{
int a[100],nel,pos,i;