CS342 Data Structures - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

CS342 Data Structures

Description:

CS342 Data Structures End-of-semester Review S2002 – PowerPoint PPT presentation

Number of Views:31
Avg rating:3.0/5.0
Slides: 16
Provided by: Erh95
Category:

less

Transcript and Presenter's Notes

Title: CS342 Data Structures


1
CS342 Data Structures
  • End-of-semester Review
  • S2002

2
Final Examination(open book, notes)
  • 30-40 on low-level implementations of the
    operations of various data structures including
    stacks queues and priority queues lists binary
    trees sets and maps.
  • 60-70 on high-level abstractions (STL) and
    applications of various data structures mentioned
    above.
  • Must know the template well.

3
Low level implementations
  • Given a class interface such of any class or ADT
  • implement member functions.
  • use the ADT to solve a particular problem.

4
The STL
  • Must know and be able to use the frequently used
    member functions of string, vector, list, stack,
    queue, priority queue, and set ADTs to solve some
    simple problems. You may also be asked to
    describe the action of a segment of code and
    analyze its efficiency in terms of Big-O
    notation.

5
Examples
  • Implement the push or pop function of a stack
    using dynamically allocated or static array
    storage.
  • Given nodes and pointers to nodes, implement a
    function or two to insert or delete a node under
    a specified condition.
  • etc.

6
STL examples
  • Vector given the following function
  • templatelttypename Tgt
  • void func(vectorltTgt v)
  • if(v.size( ) gt2)
  • vv.size( ) 2 v.back( )
  • v.pop_back( )
  • What is the output of the following code?
  • string str AA, AB, AC, AD, AE
  • int strSize sizeof(str) / sizeof(string)
  • vectorltstringgt v(str, str strSize)
  • int i
  • func(v)
  • for (i 0 i lt v.size( ) i)
  • cout ltlt vi ltlt \t

7
STL examples
  • list Display the list created by the following
    sequence of statements
  • intList.push_front(0)
  • iter intList.begin( )
  • for (int i 1 i lt 4 i)
  • intList.push_front(i)
  • insert(iter, i)
  • What if the arguments of insert function is
    replaced by (iter, iter) ?

8
STL examples
  • Stack trace the following program and answer
    some questions
  • templatelttypename Tgt
  • void f(stackltTgt s, stackltTgt t, int n)
  • int main()
  • int arr5 2, 1, 7, 4, 3, i
  • stackltintgt s, t
  • for (i 0 i lt 5 i)
  • s.push(arri)
  • f(s, t, 4)
  • outputStack(t) // display content of stack t one
    element at a time
  • return 0

9
STL examples
  • templatelttypename Tgt
  • void f(stackltTgt s, stackltTgt t, const T item)
  • T svalue
  • while (!s.empty( ))
  • svalue s.top( )
  • s.pop( )
  • if (svalue lt item)
  • t.push(svalue)
  • What is displayed by the outputStack( ) function?

10
STL examples
  • Given the definition of postfix expression (not
    given here), draw the sequence of stack
    configuration in the evaluation of the following
    postfix expression
  • 2 3 5 6

11
STL examples
  • Queue what is the contents of the bins and the
    vector after pass 2 of the radix sort for the
    following three digit integer?
  • Integers to be sorted 365 251 67 175 453 380
    905 659 251 49 598 782 967

12
STL examples
  • priority queue use a priority queue object to
    reorder a vector of integers. What is the order
    of the vector v 6, 12, 34, 15, 67, 45, 53, 3,
    5 after the execution of function f( )?
  • void f(vectorltint v)
  • priority_queueltintgt pq
  • int i
  • for (i 0 i lt v.size( ) i)
  • pq.push(vi)
  • i 0
  • while(!pq.empty( ))
  • vi pq.top( )
  • pq.pop( )
  • i

13
STL examples
  • linked list trace the code in function f( )
  • templatelttypename Tgt
  • void f (nodeltTgt front)
  • nodeltTgt p front
  • T value
  • if (front NULL)
  • return
  • while(p-gtnext !NULL)
  • p p-gtnext
  • value p-gtnodevalue
  • p-gtnodeValue front-gtnodeValue
  • front-gtnodeValue value
  • Assuming the list is front-gt 7-gt 2 -gt 9 -gt 5-gt
    NULL, what is the new list?

14
STL examples
  • Binary tree given a binary tree of any node
    type, what is the order in which nodes are
    visited in an LRN, LNR, or NLR scan?
  • A complete tree with 5125 nodes, what is its
    depth?
  • Implement a function countNodes( ) which returns
    the number of nodes in a binary tree as a
    reference argument
  • templatelttypename Tgt
  • void countNodes(tnodeltTgt t, int count) //
    pointer t points to root

15
Other types of problems
  • Big-O
  • Recursive algorithms
  • Dynamic memory allocations
  • Graphs (if any, extra points problem)
Write a Comment
User Comments (0)
About PowerShow.com