Back to 课程

Computer-science_A-level_Cie

0% Complete
0/0 Steps
  1. computers-and-components
    6 主题
  2. logic-gates-and-logic-circuits
    2 主题
  3. central-processing-unit-cpu-architecture
    6 主题
  4. assembly-language-
    4 主题
  5. bit-manipulation
    1 主题
  6. operating-systems
    3 主题
  7. language-translators
    2 主题
  8. data-security
    3 主题
  9. data-integrity
    1 主题
  10. ethics-and-ownership
    3 主题
  11. database-concepts
    3 主题
  12. database-management-systems-dbms-
    1 主题
  13. data-definition-language-ddl-and-data-manipulation-language-dml
    1 主题
  14. computational-thinking-skills
    1 主题
  15. algorithms
    14 主题
  16. data-types-and-records
    2 主题
  17. arrays
    2 主题
  18. files
    1 主题
  19. introduction-to-abstract-data-types-adt
    1 主题
  20. programming-basics
    1 主题
  21. constructs
    2 主题
  22. structured-programming
    1 主题
  23. program-development-life-cycle
    2 主题
  24. program-design-
    2 主题
  25. program-testing-and-maintenance
    3 主题
  26. user-defined-data-types
    1 主题
  27. file-organisation-and-access-
    3 主题
  28. floating-point-numbers-representation-and-manipulation
    3 主题
  29. protocols
    2 主题
  30. circuit-switching-packet-switching
    1 主题
  31. processors-parallel-processing-and-virtual-machines
    5 主题
  32. boolean-algebra-and-logic-circuits
    4 主题
  33. purposes-of-an-operating-system-os
    3 主题
  34. translation-software
    3 主题
  35. encryption-encryption-protocols-and-digital-certificates
    3 主题
  36. artificial-intelligence-ai
    4 主题
  37. recursion
    1 主题
  38. programming-paradigms
    4 主题
  39. object-oriented-programming
    7 主题
  40. file-processing-and-exception-handling
    2 主题
  41. data-representation
    5 主题
  42. multimedia
    3 主题
  43. compression
    2 主题
  44. networks-and-the-internet
    11 主题
课 Progress
0% Complete

What is an abstract data type (ADT)?

  • An abstract data type (ADT) is a collection of data and a set of operations on that data

  • Three common ADT’s are:

    • Stacks

    • Queues

    • Linked lists

Stack operations

What is a stack?

  • A stack is an abstract data type that stores data using the Last In, First Out (LIFO) principle

  • A stack is like a pile of plates, the last item you put on is the first one you take off

    • PUSH: Add an item to the top of the stack

    • POP: Remove the item from the top

  • The first item pushed onto the stack will be the last one popped off

  • A stack uses two pointers:

    • A base pointer – points to the first item in the stack

    • A top pointer – points to the last item in the stack

Main operations

Operation

Description

isEmpty()

This checks is the stack is empty by checking the value of the top pointer

push(value)

This adds a new value to the end of the list, it will need to check the stack is not full before pushing to the stack.

peek()

This returns the top value of the stack. First check the stack is not empty by looking at the value of the top pointer. 

pop()

This removes and returns the top value of the stack. This first checks if the stack is not empty by looking at the value of the top pointer. 

size()

Returns the size of the stack

isFull()

Checks if the stack is full and returns the Boolean value, this compares the stack size to the top pointer. 

  • Stacks use a pointer which points to the top of the stack, where the next piece of data will be added (pushed) or the current piece of data can be removed (popped)

push---visual-example

Pushing data to a stack

  • When pushing (adding) data to a stack, the data is pushed to the position of the pointer

  • Once pushed, the pointer will increment by 1, signifying the top of the stack

  • Since the stack is a static data structure, an attempt to push an item on to a full stack is called a stack overflow

  • This would push ‘Bunny’ onto the empty stack

    push---bunny
  • This would push ‘Dog’ to the top of the stack

    push---dog
  • This would push ‘Ant’ to the top of the stack

    push---ant

Popping data from a stack

  • When popping (removing) data from a stack, the data is popped from the position of the pointer

  • Once popped, the pointer will decrement by 1, to point at the new top of the stack

  • Since the stack is a static data structure, an attempt to pop an item from an empty stack is called a stack underflow

  • This would pop ‘Ant’ from the top of the stack

  • The new top of the stack would become ‘Dog’

pop---visual-example
  • Note that the data that is ‘popped’ isn’t necessarily erased

  • The pointer ‘top’ moves to show that ‘Ant’ is no longer in the stack and depending on the implementation, ‘Ant’ can be deleted or replaced with a null value, or left to be overwritten

Queue operations

What is a queue?

  • A queue is an abstract data type that stores data in the order it arrives, using the First In, First Out (FIFO) principle

  • A queue works like a line of people waiting at a shop, the first one in is the first one served

    • ENQUEUE: Add an item to the back of the queue

    • DEQUEUE: Remove the item from the front

  • The first item added to the queue is the first one removed

Main operations

Operation

Description

enQueue(value)

Adding an element to the back of the queue

deQueue()

Returning an element from the front of the queue

peek()

Return the value of the item from the front of the queue without removing it from the queue

isEmpty()

Check whether the queue is empty

isFull()

Check whether the queue is full (if the size has a constraint)

Linear queues

  • A linear queue is a data structure that consists of an array

  • Items are added to the next available space in the queue starting from the front

  • Items are then removed from the front of the queue

linear-queue
  • Before adding an item to the queue you need to check that the queue is not full

  • If the end of the array has not been reached, the rear index pointer is incremented and the new item is added to the queue

  • In the example below, you can see the queue as the data Adam, Brian and Linda are enqueued.

<img alt=”initialise-queue-example-” class=”ContentBlock_figure__vJw2q” data-nimg=”1″ decoding=”async” height=”284″ loading=”lazy” sizes=”(max-width: 320px) 320w, (max-width: 640px) 640w, (max-width: 960px) 960w, (max-width: 1280px) 1280w, 1920w” src=”https://cdn.savemyexams.com/cdn-cgi/image/f=auto,width=3840/https://cdn.savemyexams.com/uploads/2024/01/initialise-queue-example-.png” srcset=”https://cdn.savemyexams.com/cdn-cgi/image/f=auto,width=16/https://cdn.savemyexams.com/uploads/2024/01/initialise-queue-example-.png 16w, https://cdn.savemyexams.com/cdn-cgi/image/f=auto,width=32/https://cdn.savemyexams.com/uploads/2024/01/initialise-queue-example-.png 32w, https://cdn.savemyexams.com/cdn-cgi/image/f=auto,width=48/https://cdn.savemyexams.com/uploads/2024/01/initialise-queue-example-.png 48w, https://cdn.savemyexams.com/cdn-cgi/image/f=auto,width=64/https://cdn.savemyexams.com/uploads/2024/01/initialise-queue-example-.png 64w, https://cdn.savemyexams.com/cdn-cgi/image/f=auto,width=96/https://cdn.savemyexams.com/uploads/2024/01/initialise-queue-example-.png 96w, https://cdn.savemyexams.com/cdn-cgi/image/f=auto,width=128/https://cdn.savemyexams.com/uploads/2024/01/initialise-queue-example-.png 128w, https://cdn.savemyexams.com/cdn-cgi/image/f=auto,width=256/https://cdn.savemyexams.com/uploads/2024/01/initialise-queue-example-.png 256w, https://cdn.savemyexams.com/cdn-cgi/image/f=auto,width=384/https://cdn.savemyexams.com/uploads/2024/01/initialise-queue-example-.png 384w, https://cdn.savemyexams.com/cdn-cgi/image/f=auto,width=640/https://cdn.savemyexams.com/uploads/2024/01/initialise-queue-example-.

Responses

您的邮箱地址不会被公开。 必填项已用 * 标注