• Home
  • University of the People
  • Data Structures (proctored course) CS 3303
  • Data Structures

Data Structures

1/9/22, 10:55 AM Learning Guide Unit 3 Introduction Chapter four introduces the first of the fundamental data structures that will be covered in this course. We will look at lists, stacks, and queues. Lists, stacks, and queues are all structures that we use to maintain a list of items. There are many examples of lists that we use in everyday life. If we make a shopping list, it typically includes the items that we need to purchase at the market. Sometimes lists have no particular order and other times we might attempt to arrange the items in the list in a particular sequence. In computer science an ordered list is simply one where each item in the list has a position in the list. As explained in our text there are two basic approaches to implementing a list the first is with an array and the other is with a linked list. The array is a structure that is initialized to hold a particular number of items. This has advantages in that it relatively easy to implement, but the array will be unused wasting memory and other resources. On the other hand if you allocated an array with 10 elements and your list needed to grow to 11, you have a problem because there is no longer space in the list to add additional items. An approach to solve this particular problem is to use a linked list. In a linked list, individual elements are allocated and organized into a list by connecting one element to another with the use of a pointer. Where position defines the order in the array, the sequence of pointers defines the order in the linked list. https://my.uopeople.edu/mod/book/tool/print/index.php?id=268727 6/19 1/9/22,10:55 AM Learning Guide Unit 3 Array List Linked List Item 1 Item 1 2 Item 2 Item 5 3 Item 3 Item 2 4 Item 4 5 Item 5 Item 4 Item 3 You can see another issue with an array implementation in the figure above. In the array list, if we need to insert an item between items 2 and 3 then it would be very difficult because all the items below item 2 would have to be shifted down. To add an item into the linked list this same operation would be must easier because a new item would be allocated and the item 2 pointer would point to the new item which would then point to item three effectively inserting a new item into the list as illustrated in the following figure. Linked List Item 1 Item 5 Item2 Item 4 Item 3 Item6 https://my.uopeople.edu/mod/book/tool/print/index.php?id=268727 7/19 1/9/22, 10:55 AM Learning Guide Unit 3 In chapter 4, we will also explore special types of list implementations including stacks, queues and dictionaries. The Queue is a list that can be implemented as either a linked list or array based structure. What differentiates the queue is how items are appended and removed from the list. The queue is called a FIFO first-in first-out list. The