Essentials Flashcards
What is an abstract data type
An abstract data type is defined as a logical description of how data is viewed and the operations that can be performed on it but how this is done is not neccesarily known to the user
How do you insert a node in a singly linked list?
to insert a new element at the beginning of a singly linked list create a new node, point its ‘next’ to the current head and update the head pointer.
Insertion at the end: traverse the list until you find the last node, create a new node and make the last node point to the new node
How to delete a node in singly linked list
Deletion of a specific node: Traverse the list to find the node to be deleted and update the ‘next’ pointers accordingly
Deletion at the beginning: Update the head pointer to the next node
Deletion at the end: Traverse the list to find the second to last node make it point to NULL and free the last node.
How to traverse a node:
To access and process all elements in the list start at the head and traverse the list by following the ‘next’ pointers until NULL is encountered
Briefly describe the bubble sort algorithm
The bubble sort algorithm compares 2 succesive elements repeatedly and swaps if necessary. If the user wants to sort in ascending order then the comparion is made between two elements and the smaller element placed at first place
Briefly describe binary search
A fast way to search a sorted array is to use binary search. The idea is to look at the element in the middle, if the key is greater than that do a binary search on the second half, if the key is less than that do a binary search on the first half and if the key is already equal the search is finished