COMPUTER SCIENCE CHAPTER 2 - FUNDAMENTALS OF DATA STRUCTURES Flashcards

(99 cards)

1
Q

array

A

-a variable that can contain more than one data item
-items can be changed or replaced

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

contiguous

A

all data is stored together

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

heterogeneous

A

can support more than one data type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

homogenous

A

only support a single data type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

tuples

A

-lists that can’t be changed once created
-fixed size
-immutable so cannot be changed or replaced
-can store more than one data type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

lists

A

-can be changed after created
-not a fixed size but can grow or shrink in size
-mutable as items can be changed or replaced

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

file handling

A

opening, closing, writing to and reading from files by program codes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

binary file

A

-considered to be any file that isn’t a text file
-contains records of many different types of data
-stored as a pure binary number takes up less space
-reading it is language-specific so it requires you to know exact structure of file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

writing data to a file

A

1-open the file
2-write the data to the file
3-close the file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

reading / searching data from a file

A

1-open the file
2-create a boolean variable and set it to false, to indicate the end of file is not reached
3-while the end of file has not been reached , continue reading data from the file
4-compare if data matches the search criteria and if it does output it
5-check if end of file is reached and set boolean variable to true
6-close the file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

reading data from text files

A

1-open the file
2-use a flag to indicate end of file is reached
3-iterate through all the data in the file
4-end of file or output data from file
5-close the file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

writing data from files

A

1-open the file
2-write character data to the file
3-close the file of characters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

text file

A

contains human-readable characters organised into lines and can be read, created or edited by a computer program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

data structure

A

way of organising and storing data in a computer so it can be accessed and modified

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

examples of data structure

A

-stacks
-queues
-graphs
-trees
-hash tables
-dictionaries
-vectors

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

static data structures

A

-organisations or collections of data in memory that are fixed in size
-max size needs to be known in advance
-memory can’t be relocated once program is running

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

dynamic data structures

A

-organisations or collections of data in memory that have the flexibility to grow or shrink in size
-programmer has control over how many memory is used

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

static data advantages

A

-fixed memory allocation so no issues with adding or removing items from data structure
-easier to program as no need to check the size of data structure before accessing it

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

static data disadvantages

A

-can be inefficient as memory for data structure is set aside at start so may not be utilised

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

dynamic data advantages

A

-makes efficient use of memory as data structure only uses as much memory as it needs

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

dynamic data disadvantages

A

-runs risk of overflow if it exceeds limit or underflow it its too empty
-harder to program as code needs to keep track of data structure size and location of items inside

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

stack

A

-data structure that is essential for the operation of a computer
-LIFO (Last In First Out) structure as last item to be pushed onto stack must also be the the first to be popped off
-has a stack pointer that always points to the node at the top

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

stack underflow

A

-attempt to pop an item off a empty stack

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

stacks are used for:

A

-performing depth first searches on graph data structures
-keeping track of user inputs for undo operations
-backtracking algorithms , e.g maze
-evaluating mathematical expressions without brackets

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
operations performed on a stack:
-push=adding an item to the top of the stack -pop=removing an item from the top of the stack -peek=returning the value from the top of the stack without removing it
26
queue
-linear data structure -items are enqueued at the back of the queue and dequeued from the front of the queue -FIFO structure (First In First Out)
27
priority queue
allows people to jump the queue
28
circular queue
where the front and back pointers can move over the 2 ends of the queue
29
linear queue
has 2 pointers and is used to identify where to place a item in a queue or to identify if there is a place at the front
30
back/tail pointer
always points to the next available space
31
front / head pointer
always points to the first item
32
queue overflow
attempt to enqueue an item in a full queue
33
queue underflow
attempt to dequeue an item in a empty queue
34
queues are used for
-process scheduling -transferring data between processors and printer -performing breadth first searches on graph data structure
35
operations performed on a queue
-enqueue=adding an item to the back of the queue -dequeue=removing an item from the front of the queue -peek=returning the value from the front of the ques without removing it
36
programming a queue
-IsEmpty - returns the true if the queue has no content and it compares the front and back pointers -IsFull - returns true if the queue has no available position after the front pointer
37
programming a stack
--IsEmpty and IsFull - same function as a queue -Stack.Peek()- returns (what it outputs )the value but doesn’t change the stack in any way -Stack.Push(“ “)-moves stack pointer to the top stack pop () - removes the first item and drops the stack pointer to item below - can also be used to assign variables or constants e.g. X ( arrow pointing to X) stack.pop this would sssing the value to X
38
how to add an item to a stack (array)
1-check for stack overflow 2-move up stack pointer 3-insert new item at position where stack pointer is pointing at
39
how to add an item to a stack (object)
1-check for stack overflow 2-create a new node and insert data 3-new node points to previous node 4-stack pointer points at new node
40
how to add an item to a queue (array)
1-check for queue overflow 2-move up the tail pointer 3-insert new item where tail pointer is facing
41
how to add an item to a queue (object)
1-check for queue overflow 2-create a new node and insert data 3-back pointer points at new node 4-if its the 1st node the front pointer points at new node
42
how to remove an item from a stack (array)
1-check for stack underflow 2-copy data item pointed by pointer 3-reduce pointer
43
how to remove an item from a queue (array)
1-check for queue underflow 2-copy data item pointed to by head pointer 3-move up the head pointer
44
how to remove an item from a stack (object)
1-check for stack underflow 2-output node pointed to by stack pointer 3-set stack pointer to previous item
45
how to remove an item from a queue (object)
1-check for queue underflow 2-output mode pointed to by front pointer 3-set front pointer to previous item
46
traverse through a stack or queue
-use peek to look at front or top item
47
graph
data structure consisting of nodes / vertices and pointers / edges
48
the edges in a graph can :
-point in one direction (directed graph) -not specify a direction (undirected graph)
49
edge value
required for some algorithms, can represent distance and time
50
adjacency matrix
store graphs ,, each node in the graph is assigned a row and a column
51
adjacency list
only records existing connections in a graph,, stores a list
52
graphs implemented as a list of dictionaries
-the dictionary key represents the nodes -dictionary values represent the edge weights
53
unweighted graph
-no edge weights so doesn't require a list of dictionaries -adjacency list contains a list of nodes
54
advantages / disadvantages of adjacency matrix
-it’s time efficient as it allows you to query a edge very quickly by looking up its row and column -ADV -its memory inefficient as it stores every possible edge between nodes even though it doesn’t exist -DISADV
55
advantages / disadvantages of adjacency list
-it's memory efficient as it stores edges that exist in a graph -ADV -it's time inefficient as it takes time to search each edge as the whole list needs to be searched-DISADV
56
uses of graphs in computer science
-mapping road networks -storing social network data -resource allocation in operating systems -representing molecular structures and geometry
57
operations performed on a graph (standard operations)
-adjacent=returns whether there is a edge between 2 vertices -neighbours=returns all vertices between 2 vertices -add=adds a new vertex from the graph -remove=removes a vertex from the graph -add edge=adds a new edge connecting one vertex to another -remove edge=removes edge connecting two vertices -get vertex value=returns data stored in a vertex -set vertex value=sets data for a vertex -get edge value=returns value of edge between 2 vertices -set edge value=sets value of edge between 2 vertices
58
operations on a graph (search operations)
-depth first searches=starts at root of vertex then visits each vertex and explores each branch as far as possible before backtracking -breadth first searches=starts at the root node and visits each neighbouring node before making to vertices at next depth
59
operations performed on a graph (traversal operations)
-pre-order traversal -in-order traversal -post-order traversal
60
tree
connected, undirected graph with no cycles (no path in the tree that returns to the start node without going back and forth an edge twice)
61
rooted tree
-one vertex had been designated as the root -root connects to 0,1 or more child nodes
62
leaf nodes
nodes at the very bottom of the tree
63
subtree
set of nodes or edges from a single node down through all its descendant
64
typical uses for rooted trees
-storing and managing file and folder structures -implementations of A* pathfinding algorithms -storing and manipulating any form of hierarchical data that requires a parent node to have 0,1 or more child nodes
65
binary tree
-standard rooted tree data structure consisting of nodes and pointers. -each node can have 0,1,2 pointers
66
binary tree used in computer science
-database applications where efficient searching and sorting is required without moving items -wireless networking and router tables -operating systems scheduling process -huttman coding used for algorithms like Javascript and MP3
67
operations performed on a tree
-add=adds a new node to the tree -remove=removes a node from the tree -binary search=returns data stored in a node -pre-order traversal= type of depth first search -post-order traversal="" -in-order traversal="" breadth-first search=starts at the root node and visits each node at same level before going deeper into the structure
68
hashing algorithm
value ( arrow pointing to value) input hash ( arrow pointing to value) value MOD 3 RETURN Hash
69
hash table
immediately finds a item in a sorted or unsorted list without the need to compare other items in the data set
70
hashing function
used to calculate the position of a item in a hash table
71
collision
hash table needs to be large enough to store all the data items but is larger to minimise the chance of algorithm returning to the same value for more than one item
72
a good hashing function:
-calculated quickly -very few collisions -use as little memory as possible
73
strategies to resolving collisions
-open addressing -linear probing -chaining
74
open addressing
repeatedly check next available space in table with empty position is found
75
linear probing
hashing function delivers start position from which linear search can be applied till item is found
76
chaining
more than one item can be stored at the same position if using a 2 dimensional table
77
disadvantage of linear probing
-prevents other items from being stored at their correct location -results in clustering (several positions being filled around common collision values)
78
rehashing
finding a alternative position for items in a hash table
79
applications of a hash table
-file systems linking a file name to path of file -identifying the keywords in a programming language during competition
80
operations performed on hash table
-add=adds new item to hash table -remove=removes item from hash table =retrieve=retrieves an item from a hash table using its hash value
81
adding a item to a hash table
1-calculate position of item using a hash function 2-if calculated position is empty insert item and stop 3-if calculated position isn't empty check 1st position in overflow table -a-if position is empty insert item and stop -b-increment position to check overflow table -c-repeat from step 3a
82
removing an item from a hash table
1-calculate position of item in hash table using hashing function 2-if calculated position contains item to be deleted , delete and stop 3-if calculated positions doesn't contain items to be deleted a-if position contains item to be deleted just delete and stop b-increment position to check in overflow table c-repeat from step 3a until item to delete is discovered
83
traversing a hash table
1-calculate position of item in hash table using hashing function 2-check if item in position is item to be found 3-if calculated position doesn't contain item to be found , move 1st position to overflow table a-check if item in that position is to be found b-if not increment to next position in overflow table c-repeat from step 3a until item is found
84
dictionary
general purpose, abstract data structure used for storing groups of objects
85
a dictionary has
-a set of keys -each key has a single value associated with it -when key is supplies, associated value is returned
86
operations required to implement a dictionary:
-create a new empty dictionary -add a new key value pair -amend value of a key value pair -return the value of the key -return TRUE or FALSE -return the length of the dictionary
87
use of dictionaries
-storing and retrieving data efficiently -implementing other data structures -counting groups of data -mapping and translating data
88
vectors can be
stored easily in a computer as numbers , they can represent: -position, velocity, acceleration and force
89
vectors
series of numbers that represents information
90
vectors may be represented using notations like:
-list of numbers (R^4 , 4 vector over R) -dictionary (R^4 , 4 vector over R) e.g. 0:2,1:110 -2-d array , e.g. my vector [0] = 42 -function , e.g =. 0 (arrow) 42 ,, arrow symbol=maps too
91
scaling
scalar-vector multiplication
92
translation
vector addition
93
convex combination of vectors
-shaded area between 2 vectors -aU + Bv -u and v are vectors - a + B = 1 - a and B must be greater than or equal to 0
94
dot product or scalar product of 2 vectors is found by:
-multiplying each component of the first vector X bye each matching component of the second vector , then adding all the results together e.g. U [U*1, U*2, U*3...] V [V*1, V*2, V3...] = U*1 x V*1 + U*2 x V*2 + U*3 x V*3]...
95
producing dot product of 2 vectors purpose:
-used to find the angle between two vectors
96
formula for finding angle between 2 vectors:
- cos (0) = A.B / (||A|| . ||B||)
97
"." meaning
to multiply together
98
how to find the angle between 2 vectors:
1-calculate the dot product of A and B 2-calculate the lengths of vectors ||A|| and ||B|| using Pythagoras 3-calculate ||A|| and ||B|| 4-calculate cos(0)
99