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

unit 2 (1)(1).docx

The document outlines practical exercises for a course on Basic Data Structures using C++, focusing on operations with dynamic lists, including insertion, deletion, and traversal of elements. It includes specific tasks such as managing student UIDs, recording participant scores, and implementing search algorithms like linear and binary search. Each section provides input and output formats, constraints, and error handling requirements for the programming assignments.

Uploaded by

Pawan Kumar
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)
6 views

unit 2 (1)(1).docx

The document outlines practical exercises for a course on Basic Data Structures using C++, focusing on operations with dynamic lists, including insertion, deletion, and traversal of elements. It includes specific tasks such as managing student UIDs, recording participant scores, and implementing search algorithms like linear and binary search. Each section provides input and output formats, constraints, and error handling requirements for the programming assignments.

Uploaded by

Pawan Kumar
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/ 8

Subject Name: Basic Data Structures using C++

Subject Code : 24CSH-103


Agenda: Integration of Course Content with Competitive Coding Scenario

Sr. Practical Name Question as per Hackerrank Solution


No


4 Write a menu driven a.)A tech startup is developing a system to manage
program that implement dynamic lists of items, such as products, tasks, or user Solution as per Lab Manual
data. As part of the system, they need functionality to
following operations (using update these lists by adding new entries. https://docs.google.com/document/d/1Q52VmJohMROmup
separate functions) on a Your task is to design a solution that supports the
following operations: Z2-cNX1eFvuJrePhgL/edit?usp=sharing&ouid=107503634
linear array:
015695119350&rtpof=true&sd=true
a) Insert a new element at 1.​ Add to the End: Insert a new entry at the end of
the list. ​
end as well as at a given
2.​ Add at a Specific Position: Insert a new entry at
Solution as per Hackerrank
position a specified position within the list.
b) Delete an element https://docs.google.com/document/d/1zgQFqSfC15YDebbX
If the specified position is invalid (e.g., less than 0 or
whose value is given or beyond the current number of entries), the system should qgKucpsQcskjNRrR/edit?usp=sharing&ouid=10750363401
whose position is given display an error message: "Invalid position". 5695119350&rtpof=true&sd=true
c) To Traverse and
The solution should efficiently manage the list and ensure
display the elements of the smooth addition of new entries while maintaining order.
linear array.
Subject Name: Basic Data Structures using C++
Subject Code : 24CSH-103
Agenda: Integration of Course Content with Competitive Coding Scenario

Input Format

 The first line contains an integer n representing the


initial number of entries.
 The second line contains n integers representing the
initial entries.
 The third line contains an integer q, the number of
operations to perform.
 Each of the next q lines contains a query in one of the
following formats:

●​ "1 x": Insert x at the end of the list.


●​ "2 x p": Insert x at position p (0-based indexing).

Constraints

1≤n≤10^5

1≤q≤10^5

−10^9≤x≤10^9

0≤p≤ current number of entries

Output Format

After processing all operations, print the final list of


entries. For any operation with an invalid position, output
the message "Invalid position" for that particular query.

b)
Subject Name: Basic Data Structures using C++
Subject Code : 24CSH-103
Agenda: Integration of Course Content with Competitive Coding Scenario
Chandigarh University is building a database management
system to keep track of a list of students, such as UIDs. As
part of the system, they need functionality that allows
users to

remove UIDs from the list, either by specifying the UID


number or its position in the list. The

system must handle these operations carefully and inform


user if errors occur, such as

attempting to delete a non-existing UIDs or using an


invalid position.

Your task is to design a program that performs the


following operations on an array:

Delete by UID: Remove the specfic UID from the list.

Delete by Position: Remove UID at a specified position


(0-based index) in the list.

If the specified UID or position does not exist, the


program should display an appropriate error

message:

"Value not found" if the UID is not present.

"Invalid position" if the given position is out of bounds.


Subject Name: Basic Data Structures using C++
Subject Code : 24CSH-103
Agenda: Integration of Course Content with Competitive Coding Scenario

Input Format:

The first line contains an integer n, representing the


number of initial elements.

The second line contains nnn space-separated integers,


representing the initial values.

The third line contains an integer q, the number of


queries.

Each of the next q lines contains:

1 x: Delete the UID x.

2 p: Delete the UID at position p.

Constraints:

1≤n≤10^5

1≤q≤10^5

−10^9≤x≤10^9

0≤p< current number of entries

Output Format:

If a query is invalid, print the corresponding error


message.
Subject Name: Basic Data Structures using C++
Subject Code : 24CSH-103
Agenda: Integration of Course Content with Competitive Coding Scenario
After processing all queries, print the final list.

c) A sports event organizer needs a simple tool to record


and display participants' scores in the order they are
received. Write a C++ program that allows the organizer to
input the total number of participants along with their
respective scores. Once all scores are entered, the program
should display them exactly as they were recorded.

Input Format:
 The first line contains an integer nnn, representing the
number of participants.
The second line contains nnn space-separated integers,
each representing a participant's score. Constraints:

1≤n≤10^5

−10^9≤score≤10^9

Output Format:

Print the participants' scores in the order they were


entered, separated by a space.

5 a)​ Program to a.
A university is developing a student information system
demonstrate the use that allows professors to efficiently search for student roll
of linear search to numbers in the records. The system should enable a
professor to input the total number of students, their
search a given respective roll numbers, and a specific roll number they
element in an array. want to search for.
Subject Name: Basic Data Structures using C++
Subject Code : 24CSH-103
Agenda: Integration of Course Content with Competitive Coding Scenario
b)​ Program to The program should determine whether the given roll
number exists in the records. If found, it should display the
demonstrate the use position of its first occurrence (starting from 0).
of binary search to Otherwise, it should display "Not found."
Input Format:
search a given
 The first line contains an integer nnn, representing the
element in a sorted
number of students.
array in ascending  The second line contains nnn space-separated integers,
each representing a student’s roll number.
order.
 The third line contains an integer xxx, the roll number
to be searched.

Constraints:

1≤n≤10^5

−10^9≤ roll number,x≤10^9

Output Format:
 If the roll number is found, print its first occurrence
position (0-based index).
 If not found, print "Not found".
b. A student is developing a feature for an online
bookstore where customers can search for the position of a
specific book ID in a sorted list of available books. The
system should allow the administrator to input the sorted
list of book IDs and then search for a specific book ID.
The program should efficiently determine whether the
given book ID exists in the list. If found, it should display
its position (starting from index 0). If the book ID is not
found, the program should display "Not found."
InputFormat
Subject Name: Basic Data Structures using C++
Subject Code : 24CSH-103
Agenda: Integration of Course Content with Competitive Coding Scenario
 The first line contains an integer nnn, representing the
number of available books.
 The second line contains nnn space-separated integers,
each representing a book ID (sorted in ascending order).
 The third line contains an integer xxx, the book ID to
search for.

Constraints

1≤n≤10^5

−10^9≤ book ID, x≤10^9

OutputFormat
 If the book ID is found, print its index (0-based).
 Otherwise, print "Not found."

SampleInput0

13579

Sample Output 0

3
Subject Name: Basic Data Structures using C++
Subject Code : 24CSH-103
Agenda: Integration of Course Content with Competitive Coding Scenario
6 Program to sort an array of An online store receives customer orders with timestamps
indicating their arrival times. However, due to processing
integers in ascending order delays, these timestamps may not always be in the correct
using order. To generate an accurate daily report, the store
manager needs the orders arranged by their arrival times in
a. bubble sort chronological order.
Write a program that takes the list of order timestamps and
b. selection sort reorders them in ascending order so that the report reflects
the correct sequence of order arrivals.
c. insertion sort Input Format:
 The first line contains an integer nnn, representing the
number of orders received.
 The second line contains nnn space-separated integers,
each representing an order's timestamp.

Constraints:

1≤n≤10^3

−10^9≤ timestamp ≤10^9

Output Format:

Print the reordered list of timestamps in ascending order,


separated by spaces.

You might also like