Skip to content

jfgrea27/InterviewCodingPractice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 

Repository files navigation

Interview Coding Practice

This project contains coding interview practice taken from various sources, written in Python.

The project is the following topics:

  • Arrays (of integers) under file array.py
  • Strings under string.py
  • Data Structures under structures.py
  • Sorting Algorithms under sorting.py
  • Miscellaneous code under misc.py

Running Project

Each question/algorithm can be run from main.py.

Consideratinos for Reader

Additional comments about time and space complexity were added to each question/algorithm.

Python Library usage was reduced to minimal in order to make solutions as language agnostic as possible.

Data Structures Discussion

In this section, diagrams explaining the idea behind each data structure is presented.

Linked List

Binary Search Tree

Binary (Max) Heap

Sorting Algorithm Discussion

In this section, diagrams explaining the idea behind each sorting algorithm is presented. Additionl comments on the worst time and space complexity are also provided.

Selection Sort

Idea: Select element for current location. Repeat for all n locations.

Time Complexity: O(n^2) for all cases since we need to find the element for each location.

Auxillary Space Complexity: O(1) since no extra array is necessary

Insertion Sort

Idea: Move down (inserting) element into sorted array, swapping on element-wise comparisons.

Time Complexity: Worst - O(n^2) whenever the list is reversed sorted as we need to swap with each element in sorted sub-arrray. Best - O(n) whenever the list is already sorted since no swaps needed.

Auxillary Space Complexity: O(1) since no extra array is necessary

Merge Sort

Idea: Divide array into subarrays, sort them, merge them together

Time Complexity: O(nlog(n))for all cases since we have log(N) division levels, each of which have to merge the array in a sorted way before considering longer sub-arrays.

Auxillary Space Complexity: O(N) since we need to store subarrays, whose total length is N.

Quick Sort

Idea: Create a pivot. Move everything less/more pivot on left/right pivot. Repeat process and combine the results together to form sorted array.

Time Complexity: Best: O(nlog(n)) - when the array is evenly divided - no need to move any elements either side of the pivot at a given layer Worst: O(n^2) - when already sorted as need to move maximum of elements either side of pivot at a given layer.

Auxillary Space Complexity: O(N) since we need to store subarrays, whose total length is N.

About

Coding interview practice taken from https://www.softwaretestinghelp.com/coding-interview-questions/

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages