Rediet8abere / CS-1.3-Core-Data-Structures

MIT License
0 stars 0 forks source link

Submission 3: Linked List, Stacks & Queue #3

Open Sukhrobjon opened 4 years ago

Sukhrobjon commented 4 years ago
  1. Linked List
    • If you use self.items()[index] in get_index_at() function, the run time will always be as self.items() which is O(n). but you can reduce it to O(k) where k is the given index. instead of calling the items function in the get_index_at() function iterate the linked list until given index and return node.data at that position
  2. Stack
    • it passes the tests, but you are not supposed to use self.top = None property in the LinkedStack class.
    • LinkedStack implementation has to use the head of the LinkedList to be considered efficient. because when you try to pop the head node from the stack it is O(1) run time, on the other hand, you are using the tail as the top of the stack so you pop() function runs O(n). You can change your push() function from using self.list.append(item) to self.list.prepend(item)
    • Also, your peek() function you can use this trick as python allows you to use negative indexes, so return self.list[self.length()-1] = return self.list[-1]
  3. Queue
    • Looks good
Rediet8abere commented 4 years ago

issue solved