You are first tasked with developing a search algorithm to search for a student by their ID in an array of integers. The read function in main.cpp reads the student IDs from students.txt in an array. Note that the entire array need not be updated. The index up to which the array is updated is returned by the function and stored in a variable called num_students. A research team has decided that a Ternary search algorithm works best. The algorithm is as follows: 1. Let low = 0, high = size-1; let mid1 low + (high-low)/3 and mid2 high - (high-low)/3 2. If A[mid1] is the element, return mid1; If A[mid2] is the element, return mid2 3. If element < A[mid1], perform ternary search from low to mid1 4. If element > A[mid1] and element < A[mid2], perform ternary search from mid1 to mid2 5. If element > A[mid2], perform ternary search from mid2 to high Implement the search algorithm by defining the function ternarySearch declared in main.cpp. Complete the rest of the main function to accept the student's ID as input and search for the student. Output the index of the student if found, else output a message that the student was not found. Task 2: Add one student Implement an insertion algorithm to insert a new student into the sorted array by defining the function addStudent declared in main.cpp.
You are first tasked with developing a search algorithm to search for a student by their ID in an array of integers. The read function in main.cpp reads the student IDs from students.txt in an array. Note that the entire array need not be updated. The index up to which the array is updated is returned by the function and stored in a variable called num_students. A research team has decided that a Ternary search algorithm works best. The algorithm is as follows: 1. Let low = 0, high = size-1; let mid1 low + (high-low)/3 and mid2 high - (high-low)/3 2. If A[mid1] is the element, return mid1; If A[mid2] is the element, return mid2 3. If element < A[mid1], perform ternary search from low to mid1 4. If element > A[mid1] and element < A[mid2], perform ternary search from mid1 to mid2 5. If element > A[mid2], perform ternary search from mid2 to high Implement the search algorithm by defining the function ternarySearch declared in main.cpp. Complete the rest of the main function to accept the student's ID as input and search for the student. Output the index of the student if found, else output a message that the student was not found. Task 2: Add one student Implement an insertion algorithm to insert a new student into the sorted array by defining the function addStudent declared in main.cpp.
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
1300030051
1300308467
1300606334
1200906550
1201809169
1206505724
1301801478
1302109358
1202406962
1202704464
1203005705
1203308145
1302603281
1203903827
1304209961
1304500491
1304702995
1305101942
1306404827
1205705436
1206002391
1206304604
1206603902
1206900153
1207200292
1207502382
1207807421
1208108716
1208409718
1208709895
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 3 steps with 1 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education