Sunday, March 2, 2014

Recursion and Linked Lists

The underlying programming technique that we have been focusing on throughout CSC148 is recursion. It has its hands on pretty much every aspect of the course, from our first assignment to our labs to our second assignment and everything in between. The professor is teaching us how to use recursion to solve simple problems like determining fibonacci numbers and more difficult problems like creating recursive data structures, such as trees and linked lists.

I never understood how powerful recursion is until I began to use it to create data structures My personal favourite use of recursive data structures is the linked list. A linked list allows the user to build an abstract data structure with much more efficiency than a regular list. In lab I was able to use a linked list to recreate a queue similar to one I made earlier in the semester using a a regular list with much more quicker results to enqueue and dequeue a very large amount of items. The linked list allowed me to delete the item at the front of queue without adjusting every other item in the linked list whereas a regular list must move every item. Every item in a linked list has its own memory space that contains a reference to the following item, so to add an item to the front or to append an item at the back, the user only has to create the memory block and change the reference to head of the linked list or add a reference to the final item in the linked list.

Recursion is a very powerful technique that I now know I will be using for the rest of my programming career. I am excited to use this new knowledge and build on it throughout the final half of CSC148.

No comments:

Post a Comment