Data Structures Flashcards

(50 cards)

1
Q

What are data structures

A

Data structures is a format used to store , organise, modify and access data

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

What are the features of an array

A

An indexed set of related elements
Must be finite and indexed
An array often start from zero
Must only contain elements with the same data type

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

what are Queues
how can they be used

A

FIFO ( First item added is the first to be removed )
Used in keyboard buffers and breadth first search algorithm

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

Liner queues

A

It has two pointers ( front and rear)
IsEmpty , IsFull , Enqueue and Dequeue

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

How can emptiness in a queue be detected

A

By comparing the front and rear pointers

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

Why is a circular queue better than a linear queue

A

It is more memory efficient

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

What is a circular queue

A

A type of queue where the front and rear pointers can move over the two ends of the queue

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

What are priority queues

A

Items are assigned a priority
High priority items are dequeued first before lower priority items

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

What happens when two or more items have the same priority

A

Items are removed in first in first out

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

What are the features of stacks

A

It has a pointer
Push
Pop
Peek
IsFull and IsEmpty

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

What happens when a push command is executed on a full stack

A

A stack overflow is thrown

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

What happens when you use the pop command on an empty stack

A

Stack underflow

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

When can a graph be used

A

Can be used to represent networks such as transport networks, IT networks and the
Internet.

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

What does a graph consist of

A

Consists of nodes (sometimes called vertices) joined by edges (sometimes called
arcs)

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

What is a weighted graph

A

A weighted graph is one in which edges are assigned a value

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

What are the ways a graph can be represented as

A

○ Adjacency matrices
○ Adjacency lists

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

What is a adjacency matrices

A

● A tabular representation of a graph
● Each of the nodes in the graph is assigned both a row and a column

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

What is a adjacency lists

A

● Represent a graph using a list
● For each node, a list of adjacent nodes is created
● Only records existing connections in a graph

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

What is the difference adjacency matrix ad an adjacency list

A

Adjacency matrix

Stores every possible edge between
nodes, even those that don’t exist. Almost half of the matrix is repeated data.
Memory inefficient

Allows a specific edge to be queried very
quickly, as it can be looked up by its row
and column.
Time efficient.

Well suited for dense graphs where there are a large number of edges

Adjacency list

Only stores the edges that exist in the
graph.
Memory efficient.

Slow to query, as each item in a list must
be searched sequentially until the desired
edge is found.
Time inefficient.

Well suited to sparse graphs, where there
are few edges.

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

What are trees

A

They are connected , undirected with no cycles

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

What are rooted trees

A

● The root node is the only node with no parent, all other roots stem from them

22
Q

What is a leaf node

A

child nodes with no children

23
Q

What is a binary node

A

A rooted tree in which each parent node has no more than two child nodes.

24
Q

What are hash tables

A

A hashing algorithm takes an input and returns a hash.A hash table stores key-value pairs

25
What is collision
When different inputs produce the same hash key
26
How could you solve collisios
You could do that by rehashing
27
What are dictionaries
A collection of key-value pairs
28
What is applications of dictionaries
Dictionary based compression
29
What is a static structure
Static data structures are ○ fixed in size ○ most frequently declared in memory as a series of sequential, contiguous memory locations
30
What are dyanmic structures
○ change in size to store their content ○ store each item of data alongside a reference to where the next item is stored in memory ○ require more work on the part of the computer to set up and use
31
Draw the classification of algorithm problem
constant , quadratic , logarithm , cubic
32
Describe the process that should be followed to add an item to a circular queue implemented as a static data structure using an array.
1.Check the queue is not already full; 2.   Compare the value of the (rear) pointer with the maximum size of the array; 3.   If equal then (rear) pointer becomes zero; 4.   Otherwise, add one to the (rear) pointer; 5.   Insert new item in position indicated by (rear) pointer;
33
Describe the steps involved when adding an item to a priority queue, implemented as a static data structure using an array, that were not required when adding an item to a linear queue.
Starting with the item at the rear of the queue move each item back one place in the array; Until you (reach the start of the queue or) find an item with the same or higher priority than the item to add;
34
Describe the steps involved in adding an item to a linear queue that has been implemented as a static data structure using an array. Your answer should include a description of how any pointers are used and changed.
Check that the queue is not already full; (if it isn’t) then add 1 to the value of the rear pointer; then add the new item to the position indicated by the rear pointer;
35
Describe the method that would need to be followed to attempt to remove an item from a circular queue implemented as a static data structure using an array. Your method should deal appropriately with any issues which could arise.
1.   Check the queue is (not already) empty; 2.   Compare the value of the front pointer with the maximum size of the array; 3.   If equal then front pointer becomes one; A. index of the first position in the array instead of one 4.   Otherwise, add one to the front pointer;
36
Explain how a single stack can be used in the implementation of the repeat action and the undo action.
2. Each time an action is completed it is pushed/added onto the top of the stack; 3. unless it is an undo (or repeat) action; 4. When repeat action is used the top item from the stack is used to indicate the action to complete When undo action is used the top item is popped/removed from the stack of actions;
37
What is meant by recursively-defined?
It calls itself
38
Why are queues in computer systems usually implemented as circular queues?
In a circular queue, the locations will be re-used; Thus a circular queue has a more efficient use of memory; In a linear queue data is static, so queue ‘moves’ through storage
39
What is the role of the stack when a recursively-defined procedure is executed?
Store return addresses;
40
Describe one example of the use of a stack.
Stack of plates
41
A hash table can be used to implement a dictionary data structure. Explain why a hash table is a suitable choice.
Allows direct access to the value being looked-up
42
Time complexity is one of the two measures that are used to describe the complexity of an algorithm. What is the other measure?
Memory (complexity)
43
Some problems are intractable. What does it mean for a problem to be described as intractable?
The problem can be solved; But not in polynomial time , takes too long for a computer to solve
44
What is the significance of the Halting problem?
Shows that some problems are non-computable, shows that some problems cannot be solved by a computer algorithms
45
Explain what approach(es) a programmer might take if asked to ‘solve’ an intractable problem
Use of heuristic; An algorithm that makes a guess/estimate based on experience;solve simpler version of problem
46
Describe the Halting problem
Determining if a program will halt; without running the program;
47
Some problems are tractable. What does it mean for a problem to be described as tractable?
The problem can be solved;In polynomial time or better
48
Why is it not possible to create a Turing machine that solves the Halting problem?
The Halting problem is non-computable there is no algorithm that solves the Halting problem;
49
Describe the steps involved in adding a record to a hash table.
Hash algorithm applied; to key value; result is location in table where the record should be stored; if location is not empty; then use next free location;
50
State advantages of Reverse Polish Notation over infix nota
Easier for the computer to evaluate No need to backtrack when evaluating;