CompSci - Data Organisation + Structures Flashcards
commit suicie later
Purpose of data structures
MOE
Manipulation
Organisation
Efficiency
Operations on data structures
CSS TRIM
Copy
Search
Sort
Traverse
Remove
Insert
Merge
Array definition
Collection of elements that are identified by unique indicies and stored in consecutive memory locations
Linked list definition
A web of nodes, each with its memory address, its data and a pointer to the next address. Nodes don’t have to be near each other in memory.
Stack definition
FILO or LIFO structure
Queue definition
FIFO or LILO structure
Binary trees definition
Web of nodes connected by branches and two child nodes for each individual node.
Hashing table definition
Memory address of the data is calculated by the output of the hashing algorithm that is applied on the data itself.
OUTPUT ALL linked list
pointer = 1
linked_list = []
while pointer != -1
node = linked_list(pointer)
output node(data)
pointer = node(pointer)
LINEAR SEARCH linked list
flag = False
linked_list = []
input target
address = 1
while address != -1
node = linked_list(address)
if node(data) == target
return “Target is at: “ address
flag = True
address = node(pointer)
if flag == False:
return “Target not found ):”
Adding / Removing nodes from linked lists
To add, change the pointer of the previous node to the address of the new node + change the pointer of the new node to the address of the next node
To remove, change the pointer of the previous node to the address of the next node.
Simple and doubly linked lists
Simple linked lists only have the pointers to the next node’s address and their data
address + data + pointer>
Doubly linked lists have the previous and next nodes’ addresses and their data
<pointer + address + data + pointer>
Stack and queue removing and inserting
For stacks, pushing and popping
For queues, enqueuing and dequeuing
Stack and queue advantages and disadv
Fast processing
Efficient memory
Simple implementation
Inflexible applications
Difficult to manipulate elements
Stack uses
Store actions in a program
Store function return addresses