0% found this document useful (0 votes)
3 views7 pages

Data Sturcture 3 Sem Practical File

The document is a practical file for a Data Structure course using C++, submitted by Yash Sahu. It includes definitions of various types of arrays, example C programs for counting odd/even numbers, printing elements of arrays, creating a B-Tree, and deleting duplicates from an array. Each section provides clear explanations and code snippets relevant to the topics discussed.

Uploaded by

vaibhavgaming04
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views7 pages

Data Sturcture 3 Sem Practical File

The document is a practical file for a Data Structure course using C++, submitted by Yash Sahu. It includes definitions of various types of arrays, example C programs for counting odd/even numbers, printing elements of arrays, creating a B-Tree, and deleting duplicates from an array. Each section provides clear explanations and code snippets relevant to the topics discussed.

Uploaded by

vaibhavgaming04
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Practical File

DATA STRUCTURE USING C++


BCA 3rd Semester

SUBMITTED TO :- SUBMITTED BY :-
RAJ SIR YASH SAHU
BCA 3RD SEMESTER
Subject-Data Structure Using C

Q.1 Define : Array, multidimensional array , sparse array


tridiagonal array.
ANS :- Definitions:-

 Array: An array is a collection of elements of the same data type,


stored in contiguous memory locations, and accessed using an
index or a subscript. For example, int arr[5] stores five integers.

 Multidimensional Array: A multidimensional array is an array that


has more than one dimension, i.e., an array of arrays. It can
represent matrices or tables. For example, a 2D array is declared
as int arr[3][4], which can be visualized as a matrix with 3 rows
and 4 columns.

 Sparse Array: A sparse array is an array where most of its


elements have default values (such as 0 or null), and only a few
elements contain non-default values. It is usually used to save
memory by storing only non-default values with their indices.

 Tridiagonal Array: A tridiagonal array is a type of matrix where


non-zero elements are only present on the main diagonal, the
diagonal above it, and the diagonal below it. For example, in a 5x5
matrix, only elements (i,i), (i,i-1), and (i,i+1) are non-zero, and all
other elements are zero.
Q.2 An array A contains 25 positive integers. Write a program
in C which will find out the number of odd and even number in
that array.
ANS :- #include <stdio.h>

int main() {

int arr[25], i, oddCount = 0, evenCount = 0;// Input 25 integers

printf("Enter 25 positive integers: ");

for(i = 0; i < 25; i++)


{
scanf("%d", &arr[i]); // Count odd and even numbers

for(i = 0; i < 25; i++)


{

if(arr[i] % 2 == 0)

evenCount++;

else

oddCount++;

printf("Number of even numbers: %d\n", evenCount);

printf("Number of odd numbers: %d\n", oddCount);

return 0;

}
Q.3 Consider two single dimensional array of size 2 and 3
respectively. Write a program in c to print numbers.

ANS:- #include <stdio.h>


int main() {

int arr1[2] = {1, 2}; // Array of size 2

int arr2[3] = {3, 4, 5}; // Array of size 3

int i;

// Printing elements of the first array

printf("Array 1: ");

for(i = 0; i < 2; i++) {

printf("%d ", arr1[i]);

// Printing elements of the second array

printf("\nArray 2: ");

for(i = 0; i < 3; i++) {

printf("%d ", arr2[i]);

return 0;

}
Q.4 Define a B-Tree and its properties. Create a b-tree in the
following sequences

12,5,14,45,20,5,67,8,34,11,16,63,22,77

ANS :- B-Tree Definition:


 B-Tree: A B-tree is a self-balancing search tree in which nodes
can have more than two children. It is designed to handle large
amounts of data efficiently and is typically used in databases and
file systems.

Properties of B-tree:

o It is a balanced tree, meaning all leaf nodes are at the same


level.
o Each node can have more than two children, but the number
of children is bounded.
o The keys in each node are sorted in ascending order.
o Insertion and deletion operations are carried out in such a
way that the tree remains balanced.

Steps for creating a B-Tree for the given sequence: For simplicity, I
won’t write the full code for creating a B-tree. The process is a bit
lengthy, but here's how it works:

 Begin by inserting the elements one by one (12, 5, 14, 45, 20, 5, 67,
8, 34, 11, 16, 63, 22, 77).
 After each insertion, if a node exceeds the maximum allowed
number of keys, it will split into two nodes, and the middle value
is promoted to the parent node.
 Ensure that the B-tree properties are maintained during insertion.
Q.5 Write a program in C to delete duplicate elements from an
array of 20 integers.

ANS :- #include <stdio.h>

int main() {

int arr[20], i, j, k, isDuplicate;

// Input 20 integers

printf("Enter 20 integers: ");

for(i = 0; i < 20; i++) {

scanf("%d", &arr[i]);

// Remove duplicates

for(i = 0; i < 20; i++)


{
isDuplicate = 0;

for(j = 0; j < i; j++) {

if(arr[i] == arr[j]) {

isDuplicate = 1;

break;

if(isDuplicate == 0) {

arr[k++] = arr[i];

}
}

// Print the array after removing duplicates

printf("Array after removing duplicates: ");

for(i = 0; i < k; i++) {

printf("%d ", arr[i]);

return 0;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy