Week 4

Structures (struct) provide a way to unify several variables of different types into a single, new variable type which can be assigned its own type name.

On Singly linked lists

Singly linked list’s node contains two items:

Once a linked list is created, it’s a good idea to always keep track of the first element of the list since it’s in knowing list’s first element, that othe members can be known following the pointers each member’s node contains.

In inserting a new element to a linked list, it is generally better to insert at the start of the list.

When inserting:

NOTE: It is very important to point from new head to old head before making the newly inserted element head of the list to prevent “orphaning” the entire list.

When deleting an entire linked list from memory, start freeing from the end of the list to the head. If done the other way around, the list’s head goes first and there wouldn’t be any way to reference the rest of the list resulting in a memory leak.

Deleting a single element from a singly linked list is kind of tricky. It would involve moving back and forth the chain to “reconnect” the list. Unfortunately, a singly linked list’s node only contains a pointer to the next element, not the previous one. See doubly linked lists.

On Hashtables

Hashtables sort of combines an array with a linked list. It combines the random access ability of an array with the dynamism of a linked list. A couple pointers:

Some Other Data Structures

Comparing Some Data Structures

Arrays:

Linked Lists:

Hash Tables:

Tries:

Other bullets from D. Malan’s lecture