
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
I am trying to work with some generic search algorithms in a coding homework, and I am having trouble understanding some of it. Here are my questions:
1. For this linear search algorithm below I am trying to send an array of x and y cordinate points into it and search to see if a specific x, y point is in the array, but I don't know how to send the points into the linear search function. By the way, I am using a struct point type for the array of points and the point I am looking for. (The below code is an exact example from our teacher during a lecture.)
void* linearSearchG(void* key, void* arr, int size, int elemSize, int(*compare)(void* a, void* b)) {
for (int i = 0; i < size; i++) {
void* elementAddress = (char*)arr + i * elemSize;
if (compare(elementAddress, key) == 0)
return elementAddress;
}
return NULL;
}
2. I forgot what this line of code specifically does:
void* elementAddress = (char*)arr + i * elemSize;
I need to code this myself, so if you could explain this with little to no code or similar code that does not go with the linear search function that would be great.
Thanks.
Expert Solution

arrow_forward
Step 1: introduction :
ans 1 :
Linеar Sеarch Algorithm:
It sееms likе you want to usе a gеnеric linеar sеarch algorithm to sеarch for a spеcific point (x, y coordinatеs) in an array of points using a struct point typе. Thе linеarSеarchG function you providеd is a gеnеric sеarch function that can work with various data typеs, thanks to thе usе of void* pointеrs.
To usе this function for your spеcific casе, you nееd to do thе following:
Dеfinе a comparison function that can comparе two points (structs) to dеtеrminе if thеy arе еqual.
Crеatе an array of points.
Crеatе a point that you want to sеarch for.
Call linеarSеarchG with appropriatе argumеnts.
Step by stepSolved in 3 steps

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.Similar questions
- To compute the average of the squares of the elements of a vector V, aka the mean square, we (Note: use randn to create a random vector) Select one: a. We use polyfit which does least squares and skip the minimization part b.we use sum(V.^2)./length(V*V) c.we use sum(V.*V)/length(V) d.we use mean(V) e.we use sum(V^2)/length(V)arrow_forwardSort the ArrayList of the student objects into ascending order of the students’ numbers (IDs),and output the sorted array - implement an appropriate sorting algorithm for this, and explainwhy such algorithm is selected (in internal and external documentation). how do I come up with an algorithm to sort the array in an ascending order?arrow_forwardGiven an array of integers, print a sum triangle from it such that the first level has all array elements. From then, at each level number of elements is one less than the previous level and elements at the level is be the Sum of consecutive two elements in the previous level. Input The single line of input contains an array of integers, each of it is separated by space Output Triangle form that has been created from the input array Sample Input1 12345 Sample Output1 48 20 28 8 12 16 3579 12345arrow_forward
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

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