DSA Lab Exercise 3

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Lab exercise 3: Complexity Analysis

(Determine the time complexity for each of the exercise questions)


Part 1: Revision on C++ concepts
1. Write a block of code that defines a structure called Computer with these data
members: brand, speed, storage.
2. Here is an initialization of a user defined data type. State what happens with each
initialization.
struct Room
{
double length;
double breadth;
double height;
};
a. Room room = {12.4, 31};
b. Room room = {26, 21.3, 2, 94};
c. Room room = {12, 21, 20, 22};
d. Room room = {3.6, 4.0, 2.3};
3. Give the structure definition for a type named Hotel that has two member
variables, one named room_info of the type Room given in Q2 and one named
location of type string.
4. Create an array of structure (size 20) for a structure called Student with these data
members: id, name, year.
Part 2: Complexity Analysis
1. Analyze and find the time complexity of the code snippets below

b. c.
a.
2. Write a C++ program that accepts 10 integers from the user and finally displays the
smallest value and the largest value.
3. Given an integer array nums, display ‘true’ if any value appears at least twice in the
array, and display ‘false’ if every element is distinct.
4. Write a program which takes 2 arrays of 4 integers each, a and b. c is an array with 8
integers. The program should put into c the first 4 integers of c from array a, the latter
4 from b. Then the program should display c.
5. You are given an array with the following elements 5, 12, 25, 31, 15, 6, 31, 8, 21 and a
target element 8. Return the index of the target in the array after sorting it in increasing
order.

You might also like