This C program reads file inputs from a text file named student.txt and stores them in an array. There are records of students' first and last names, student ID, and total grade. The records of the students are sorted using the Quick Sort algorithm to sort the student records and align them in ascending order according to their grades. If students have equal grades, they are sorted by their first name in alphabetical order. The new sorted records of students are written to a new file called sorted_students.txt, but it uses the same format as the student.txt file.
This C program makes sure to read all student records, applies the ascending order sorting using the grades, and the secondary sorting using their first name letter, in alphabetical order, which is applied to records with equal grades. The output file, where the new sorted records are written, preserves the required format of the initial file that was read.
(n) is the number of records,
Best case: O(n log n) Average case: O(n log n) Worst case: O(n ^ 2)
The insertion sort has a time complexity of O(n ^ 2), and that makes it inefficient for large datasets. Quick sort is better because its average time complexity is O(n log n), which performs better and is more scalable for a file-based student data system.
This C program imitates a bus route using a doubly linked list, and each node represents a bus stop, which contains a name and a number. The list is created from the user input, and a menu allows the user to move forward or backward throughout the bus route. A 3-second delay is applied after a bus stop is printed, and traversal stops right after the first or last stop. You can also dynamically add a new bus stop at the end of the route.
This program makes a doubly linked list with forward and backward links. Traversing works with a 3-second delay between stops. New bus stops can be added dynamically at the end of the list. All memory was allocated using malloc and released using free, ensuring no memory leaks.
When inserting a new bus stop at the end of the doubly linked list, it has a time complexity of O(1) when a tail pointer is used, since we don’t need to use traversal.
This C program builds a Binary Search Tree from 68 distinctive integers. Each node has a value and a pointer to the parent. The program identifies the root, leaf nodes and allows a user to search a specific node to print its parent, siblings, and grandchildren.
The Binary Search Tree is correctly built from the array. The leaf and root nodes are identified correctly. Users can input a specific node, and its parent, siblings, and grandchildren are printed correctly. Invalid nodes are well handled. Memory is allocated dynamically using malloc and freed using free to prevent memory leaks.
When inserting a node in a BST with n nodes:
Best case: O(log n) Worst case: O(n)
This C program reads student records from the file students.txt and stores them in a BST using the last name as the key. Duplicates are handled by storing multiple students with the same last name in a linked list at a BST node. Users can search for students by last name and view all matching records.
BST correctly maintains ordering using the last name. Duplicate names are handled correctly. File input is parsed and validated. Search by users retrieves all matching students and handles entries. Memory is dynamically allocated and freed.
Best case: O(log n) Worst case: O(n)
BST allows faster search than a linear file scan, linear search is O(n), while a BST is O(log n). This makes it better for large datasets.
Download all C files and compile them using gcc filename.c -o filename. Execute the files using ./filename.
Credo Desparvis Gutabarwa