UNIT V
UNIT V
1. Define bitfield.
A bitfield stores multiple values in a single integer, each occupying specific bits.
5. Define union.
6. Define searching.
Selection sort finds the smallest element and places it in the correct position.
UNIT V
10. List the components of Space Complexity.
Components include input space, auxiliary space, and recursion stack space.
LONG
Answer:
Declaration of Structure
sstruct StructureName {
data_type member1;
data_type member2;
...
};
Example:
#include <stdio.h>
struct Student {
int roll_no;
char name[50];
float marks;
};
UNIT V
int main( ) {
return 0;
12. What do you understand by Union? How to access its members, and what
are its applications?
Answer:
A union in C is a user-defined data type where all members share the same
memory location. It is used to save memory by storing only one member's value at
a time.
union UnionName {
data_type member1;
data_type member2;
...
};
Accessing Members:
Use the dot operator (.) for accessing union members.
Example:
#include <stdio.h>
union Data {
int i;
float f;
};
UNIT V
int main( ) {
union Data d;
d.i = 10;
d.f = 20.5;
return 0;
Applications:
Answer:
Declaration:
Example:
#include <stdio.h>
struct Student {
int roll_no;
char name[50];
float marks;
};
UNIT V
int main( ) {
return 0;
Answer:
Declaration:
Example:
#include <stdio.h>
(or)
enum Months{Jan,Feb,Mar,Aprl,May,Jun,July,Aug,Sep,Oct,Nov,Dec};
(or)
enum RainbowColors{Red,Green.White,Yellow,Blue,Black,Pink};
int main( ) {
return 0;
} Output: 2
UNIT V
15. What is searching? Explain in detail about linear search algorithm with an
example.
Example Program:
#include <stdio.h>
if (arr[i] == target) {
} }
int main( ) {
if (result != -1)
else
Answer:
Step 1: start
15: stop
UNIT V
17. Discuss briefly the asymptotic notations and study the complexity of
algorithms.
Answer:
Definition:
Types:
Answer:
Example Program:
#include <stdio.h>
arr[j + 1] = temp;
} } } }
int main( ) {
bubbleSort(arr, n);
return 0;
UNIT V
}
Example Program:
#include <stdio.h>
int minIndex = i;
minIndex = j;
arr[i] = arr[minIndex];
arr[minIndex] = temp;
int main( ) {
return 0;
20. Describe space complexity and time complexity and analyze these for a
simple program.
Answer:
Time Complexity:
Space Complexity:
#include <stdio.h>
if (arr[i] == target)
int main( ) {
if (result != -1)
else
return 0;