Computer Science

# Linear Data Structures: Level 2 Challenges

Give a sorted array of $n$ elements, what is the minimum number of comparisons needed to check whether a certain element occurs more than half of the time?

Details and Assumptions

-No auxiliary data structure is allowed.

Which line of this implementation of a queue should be changed in order to obtain a stack?

## C++

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 #include struct thing { int size; /* size of contents */ int bottom; /* first used location */ int top; /* first unused location */ int *elements; /* array of elements */ }; struct thing *thingCreate(int size) { struct thing *t; t = malloc(sizeof(*t)); t->size = size; t->bottom = t->top = 0; t->elements = malloc(sizeof(int) * size); return t; } void Push(struct thing *t, int value) { t->elements[t->top++] = value; } int Pop(struct thing *t) { return t->elements[t->bottom++]; } 

Find the sum of all the prime numbers less than 1000 that are 1 more than a perfect square.

For example, 2 is a prime that is 1 more than the perfect square 1.

×