Com Sci mod 1 Flashcards
What is a stack?
A stack is a linear data structure in which it inserts with push and deletes with pop which are allowed only at the end, called the top of the stack.
LIFO-(last in first out)
What does the Push operation do?
it inserts data at the top of the stack
the data entered immediately becomes the top of the stack
What does the Pop operator do?
Deletes the last inserted element from the stack
Always deletes the top element
What does the isEmpty operation do?
Returns TRUE if the stack is empty else it returns FALSE
What does the isFull operation do?
Returns TRUE if the stack is full, else returns FALSE
What is a queue?
A queue is a linear data structure which operates in a FIFO- (First In First Out) manner
What does the enqueue operation do?
Adds data to the rear end of the queue
What does the dequeue operation do?
Removes elements from the head (front) of the queue
What is a linear search?
Linear searches iterates through a collection one element at a time
What is a disadvantage for a linear search?
It is slow for large data sets
What is an advantage of a linear search?
- Fast for searches of small to medium data sets
- Does not need to be sorted
- Useful for data structures that do not have random access (linked lists)
What is binary search?
Binary search is a search algorithm that finds the position of a target value within a sorted array. Half of the array is eliminated during each “step”. if the mean is not the target value and if the mean is smaller than the target value it continues to the right until the target value is found. if the mean is larger than the target value it continues to the left until the target value is found.
What is a selection sort?
search through an array and keep track of the minimum value during each iteration. At the end of each iteration, we swap values.
What is bubble sorting?
pairs of adjacent numbers are compared, and the elements are swapped if they are not in order
How does a bubble sort algorithm look like?
include <stdio.h></stdio.h>
int main(void)
{
int a[] = {7,1,3,9,0,2,4,5,8,6};
int length =10;
for (int i = 0; i< length; i++)
{
for (int j =0; j< (length-1); j++)
// < for ascending order and > for descending order
{
if (a[j] > a[j + 1])
{
int temp= a[j];
a[j] = a[ j + 1];
a[j + 1] = temp;
}
}
}
return 0;
}