DSA Portfolio
DSA Portfolio
Email: [email protected]
LinkedIn: https://www.linkedin.com/in/pola-gautam-sai-597641288
GitHub: https://github.com/GautamSai05
Portfolio Website (if any): None
ELab Completion Status
CODE-
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
// Array to store seats; 0 for available, and index+1 of the user if booked
int seats[TOTAL_SEATS] = {0};
struct User users[MAX_USERS];
int num_users = 0; // Counter for registered users
int current_user = -1; // Index of the currently logged-in user (-1 means no one is logged in)
int seat_num;
printf("Enter seat number to book (1-%d): ", TOTAL_SEATS);
scanf("%d", &seat_num);
if (seats[seat_num - 1] == 0) {
seats[seat_num - 1] = current_user + 1; // Store the index+1 of the user
printf("Seat %d booked successfully under the name %s.\n", seat_num, users[current_user].name);
} else {
printf("Seat %d is already booked.\n", seat_num);
}
}
int seat_num;
printf("Enter seat number to cancel (1-%d): ", TOTAL_SEATS);
scanf("%d", &seat_num);
if (seats[seat_num - 1] == current_user + 1) {
seats[seat_num - 1] = 0; // Mark the seat as available
printf("Seat %d booking canceled successfully.\n", seat_num);
} else {
printf("You cannot cancel this seat. It’s either not booked or booked by another user.\n");
}
}
while (1) {
printf("\n--- Ticket Booking System ---\n");
printf("1. Register\n");
printf("2. Login\n");
printf("3. Book Seat\n");
printf("4. Cancel Seat\n");
printf("5. Display Available Seats\n");
printf("6. Logout\n");
printf("7. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
register_user();
break;
case 2:
if (current_user == -1) {
login_user();
} else {
printf("Already logged in as %s.\n", users[current_user].name);
}
break;
case 3:
book_seat();
break;
case 4:
cancel_seat();
break;
case 5:
display_seats();
break;
case 6:
if (current_user != -1) {
printf("Logging out %s.\n", users[current_user].name);
current_user = -1; // Logout the current user
} else {
printf("No user is currently logged in.\n");
}
break;
case 7:
printf("Exiting the system.\n");
return 0;
default:
printf("Invalid choice. Please try again.\n");
}
}
return 0;
}
CERTIFICATIONS (Coursera/edX/etc.)
Include any online courses, workshops, or certifications related to Dat Structures and
algorithms, problem-solving
NPTEL/HOTS QUESTIONS SOLUTION
Problem Statement:
Given a binary tree where each node contains an integer, find the longest path from the root
to any leaf node where the values in the path strictly increase. If there is no such path,
return 0.
Objective:
Implement a function that returns the length of the longest increasing path from the root to
a leaf node in the tree.
Solution Outline:
1. Use Depth-First Search (DFS) starting from the root node.
2. At each node, if the child node value is greater than the current node value,
continue down that path.
3. Track the length of the current path and update the maximum path length if a longer
path is found.
Complexity:
● Time Complexity: 0(N), where N is the number of nodes in the tree, as each node
is visited once.
● Space Complexity: O(H), where Hbis the height of the tree, for the recursive call
stack.
Code-
#include <iostream>
#include <algorithm>
struct TreeNode {
int val;
TreeNode *left, *right;
TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
};
return currentLength;
}
int main() {
TreeNode* root = new TreeNode(10);
root->left = new TreeNode(12);
root->right = new TreeNode(15);
root->left->left = new TreeNode(11);
root->right->right = new TreeNode(18);
Conclusion-
This solution efficiently finds the longest path from the root to a leaf node where values
strictly increase by using Depth-First Search (DFS). By keeping track of each node’s value
and comparing it with the previous value in the path, the algorithm ensures that only paths
with strictly increasing values are considered
CODING COMPETITIONS