Data Structures Flashcards
What is an Array?
- Linear Data Structure
- Elements are stored in contiguous memory locations
- Can access elements using index
- Stores homogeneous elements
What is the applications of Arrays?
Storing Information in a linear fashion. Suitable for applications that require frequent searching.
What is an 1DA?
1 Dimensional Array, can be seen as a row.
- Needs contiguous memory
- Elements in a linear sequence
- Only same type elements (Homogeneous)
- Only one index is used.
How to declare an 1DA?
Datatype varname[size];
How to initialize an 1DA?
Datatype varname[] = {ele1, ele2, ele3, ele4}
What is a 2DA?
2 Dimensional Array, can be seen as a table.
- Store elements in sequence.
- It is an Array containing 1DAs, therefore gaining one more dimention.
- Two indices are used, one for row and one for column.
How to declare a 2DA?
Datatype varname[rows][cols];
Advantages of arrays?
- Random access elements
- Easy sorting and iteration.
- Replacement of multiple variables.
Disadvantages of arrays?
- Fixed size, surplus will be “wasted”
- Difficult to insert and delete
- Need contiguous memory
Define a Linked List?
- A linear data structure
- Elements can be stored by memory availability (not contiguous)
- Only same type elements (homogeneous)
- Dynamic size
- Easy insertion and deletion
- 1st element is called Root/Head, if lost, all the Linked list will be lost, as it points to the next elements.
What are the applications of a Linked List?
- When Memory is Limited
- When requires frequent insertion and deletion
What are the types of Linked List?
- Single Linked List
- Double Linked List
- Circular Linked List
What is a Single linked List?
The simple Linked List.
- There will be a Head/root Pointer that will link to the first node.
- Each node contains data and a link to the next one.
- The last node will point to null.
What is a Double Linked List?
A linked list in wich each node points to both neighbours (previous and next), so we can move forwards and backwards.
- There will be a head/root pointer to the first node.
- The first node will point to the next (second node), and to the previous address (null).
- All middle nodes have two pointers and data.
- The last node will point to null.
What is a Circular Linked List?
A linked list in wich the last node points to the first one.
- There will be a head/root pointer to the first node.
- Each node points forwards
- The last node will point to the first node.