0% found this document useful (0 votes)
24 views

DSA Lab Exercise 3

This document discusses analyzing the time complexity of code snippets and exercises involving structures and arrays. Part 1 defines structures for a computer, room, and hotel. Part 2 includes exercises such as finding the minimum and maximum value in an integer array, checking for duplicate values, combining elements from two arrays into a third array, and returning the index of a target element after sorting an array. The time complexity would need to be analyzed for each code snippet, with most taking O(n) time where n is the number of elements, and sorting taking O(n log n) time.

Uploaded by

Firomsa Mt
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

DSA Lab Exercise 3

This document discusses analyzing the time complexity of code snippets and exercises involving structures and arrays. Part 1 defines structures for a computer, room, and hotel. Part 2 includes exercises such as finding the minimum and maximum value in an integer array, checking for duplicate values, combining elements from two arrays into a third array, and returning the index of a target element after sorting an array. The time complexity would need to be analyzed for each code snippet, with most taking O(n) time where n is the number of elements, and sorting taking O(n log n) time.

Uploaded by

Firomsa Mt
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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