CS32_Final_Review

CS32_Final_Review - CS32FinalReview Topics 1. Classes a.

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS32FinalReview Topics 1. Classes a. Public/private/protectedmembers b. Constructors c. Copyconstructors d. Overloadedoperators e. Destructors f. Memberfunctions/variables 2. DynamicMemory a. Newanddelete b. Dynamicallyallocatedarrays c. Classinstances 3. LinkedLists a. Insertion b. Deletion c. Traversal d. Tailpointers e. Doublylinkedlist f. Comparisonwitharrays 4. StacksandQueues a. LIFO/FIFO b. Addinganelement c. Deletinganelement d. Implementationwitharray e. Implementationwithlinkedlist f. Applications 5. InheritanceandPolymorphism a. Baseclass/derivedclass b. Virtualfunctions c. Purevirtualfunctions d. Abstractbaseclass e. Constructorcalls f. Virtualdestructors 6. Recursion a. Stoppingcondition b. Recursivecalls 7. TemplatesandSTL a. Typedefvs.templates b. Functiontemplatesandclasstemplates c. STLlists,stacks,queues,vectors,sets,maps d. STLiterator 8. AlgorithmicComplexity a. BigOh b. Binarysearch c. Searching,sorting,insertion,deletion 9. SortingAlgorithms a. Selectionsort b. Insertionsort c. Bubblesort d. Shellsort e. Quicksort f. Mergesort g. Bestcase/worstcasetimecomplexity h. Prosandconsofquicksortandmergesort 10. Trees a. Binarytreedefinition b. Preorder,inorder,postorder,levelordertraversals c. Binarysearchtrees:search,insert 11. Hashtables a. Searching,insertingtimecomplexity b. Hashfunctions c. Loadfactor d. Collisions e. LinearProbing/Closedhash f. Chaining/Openhash 12. Heaps a. Minheap,maxheap b. Heapsort PracticeProblems 1. Timecomplexity a. TorF:ThetimecomplexityofquicksortisalwaysO(nlogn). b. TorF:Theworstcaseofmergesortisbetterthantheworstcaseofquicksortintermsoftime complexitybutnotinspacecomplexity. c. Whatistheorderoffunctionfifn>M?Whatifn<logM? void g(int arr[M], int n) { for (int i = 0; i < n; i++) { for (int j = 0; j < M-1; j++) { arr[i][j] += arr[i][j+1]; } } } void f(int arr[M], int n) { for (int i = 0; i < n; i++) { mergesort(arr[i], M); g(arr, i); } } 2. Writeafunctionthatprintsoutallpermutationsofastring. Example:Thepermutationsof"abc"are:abc,acb,bac,bca,cab,cba (Hint:dothisrecursively) 3. BinaryTrees a. Writeafunctionthatreturnsthenumberofelementsinabinarytree. int size(Node *node) { b. Write a function that returns the maximum depth of a binary tree (the number of levels betweentherootnodeandthefarthestleafnode). int maxDepth(Node *node) { c. Writeafunctionthatchangesabinarytreetoitsmirrorimage. Forexample: 4 / \ 2 / \ 1 3 5 4 / \ becomes5 2 / \ 3 1 void mirror(Node *node) { 4. Giventhisarrayofnumbers:14,10,32,12,4,19,2 a. ShowthestateofthearrayaftereachpartitionstepinQuicksort(usingthefirstelementasthe pivot) b. Showtheintermediatearraysaftereachsplitandmerge. 5. ImplementaPriorityQueueclass.Thepriorityqueueisacollectionofintegers,wherelarger integersarehigherprioritythansmallerintegers.HereisonewaytodefineaPriorityQueue: class PQueue { public: PQueue(); int size(); bool isEmpty(); void enqueue(int element); int extractMax(); private: // define your private variables/functions here }; Use an array of size MAX to implement this version of the priority queue. Then, implement the constructorandallthememberfunctions. 6. WewanttodesignaPhoneBookclasstomanagephonenumbersforcellphones.Therecanbeat most4phonenumberspername,butthereisnolimitonthenumberofnames.ThePhoneBook needstohavethefollowingoperations: Displayallnames:MustbeabletobedoneinO(N)time,whereNisthenumberofnamesinthe phonebook. Searchanamegivenaphonenumber:Whenthephonenumberforanincomingcallexistsinthe phonebook,thenameisretrievedforthatnumber.ThishastobedoneinO(1)time. Speeddial:AccessingorupdatingaspeeddialentrytakesO(1)time.Onlythenumbers1through 9canbeassignedspeeddialnumbers. WhatprivatedatastructureswouldyouusetodesignthePhoneBookclass?Keepinmindthat memoryonacellphoneislimited.YoudonotneedtoimplementthePhoneBookclass,justexplain howyourdatastructuresmeetthetimerequirementsforeachofthethreeoperations. ...
View Full Document

Ask a homework question - tutors are online