CSC 2516-Rubin Timilsinadocx PDF
CSC 2516-Rubin Timilsinadocx PDF
)
Course Code: (CSC 2516)
Course Name: DATA STRUCTURE AND ALGORITHM
Date of Submission: 24th August 2021
A data structure is a specialized format for organizing, processing, retrieving and storing data. There are
several basic and advanced types of data structures, all designed to arrange data to suit a specific
purpose. Data structures make it easy for users to access and work with the data they need in
appropriate ways. Most importantly, data structures frame the organization of information so that
machines and humans can better understand it. In computer science and computer programming, a
data structure may be selected or designed to store data for the purpose of using it with
various algorithms. In some cases, the algorithm's basic operations are tightly coupled to the data
structure's design. Each data structure contains information about the data values, relationships
between the data and -- in some cases -- functions that can be applied to the data.
I Data structures (how to organize data) and Algorithms (how to manipulate data) are the cores of
today’s computer programming.
II DSA lays a foundation for real programming that includes OOP’s, Recursion, Sorting, Recursion
and more
Q.NO.2 Answer>>>>>>>>>>>>>>>>>
Linear Search Linear search, also called sequential search, is a very simple method used for searching an
array for a particular value. It works by comparing the value to be searched with every element of the
array one by one in a sequence until a match is found. Linear search is mostly used to search an
unordered list of elements (array in which data elements are not sorted).
For example, if an array A[] is declared and initialized as, int A[] = {10, 8, 2, 7, 3, 4, 9, 1, 6, 5}; and the
value to be searched is VAL = 7 , then searching means to find whether the value ‘7’ is present in the
array or not. If yes, then it returns the position of its occurrence. Here, POS = 3 (index starting from 0).
Algorithm: linear search
LINEAR_SEARCH(A, N, VAL)
SET POS = I
PRINT POS
Go to Step 6
[END OF IF]
SET I = I + 1
[END OF LOOP]
Step 5: IF POS = –1
ARRAY "
[END OF IF]
Linear search executes in O(n) time where n is the number of elements in the array. Obviously, the best
case of linear search is when VAL is equal to the first element of the array. In this case, only one
comparison will be made. Likewise, the worst case will happen when either VAL is not present in the
array or it is equal to the last element of the array. In both the cases, n comparisons will have to be
made. However, the performance of the linear search algorithm can be improved by using a sorted
array.
Q.No. 3 Answer>>>>>>>>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Global declaration
int count = 0;
// Structure declaration
struct node {
struct node* prev;
int ssn;
long int phno;
float sal;
char name[20], dept[10], desg[20];
struct node* next;
} * h, *temp, *temp1, *temp2, *temp4;
//
int main()
{
// Function Call
employerDetails();
return 0;
}
Output: